bodewig 2002/07/15 07:41:47
Modified: docs/manual using.html
src/main/org/apache/tools/ant Main.java
src/main/org/apache/tools/ant/helper ProjectHelperImpl.java
src/main/org/apache/tools/ant/taskdefs Ant.java
AntStructure.java
Added: src/etc/testcases/core/topleveltasks notarget.xml
targetlevelant.xml toplevelant.xml
src/testcases/org/apache/tools/ant TopLevelTaskTest.java
Log:
Allow target-less build files by
(1) making project's default attribute optional.
(2) don't run executeTarget(s) if not asked for one
Adapt documentation and <antstructure>.
Revision Changes Path
1.24 +6 -6 jakarta-ant/docs/manual/using.html
Index: using.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/using.html,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- using.html 9 Jul 2002 21:05:50 -0000 1.23
+++ using.html 15 Jul 2002 14:41:46 -0000 1.24
@@ -30,7 +30,7 @@
<tr>
<td valign="top">default</td>
<td valign="top">the default target to use when no target is
supplied.</td>
- <td align="center" valign="top">Yes.</td>
+ <td align="center" valign="top">No. No target will be run if
omitted.</td>
</tr>
<tr>
<td valign="top">basedir</td>
@@ -284,11 +284,11 @@
</project>
</pre>
-Notice that we are declaring properties outside any target. The
-<tt><property></tt>,<tt><typedef></tt> and
<tt><taskdef></tt>
-tasks are special in that they can be declared outside any target. When you
-do this they are evaluated before any targets are executed. No other tasks
-can be declared outside targets.
+<p>Notice that we are declaring properties outside any target. As of
+Ant 1.6 all tasks can be declared outside targets (earlier version
+only allowed <tt><property></tt>,<tt><typedef></tt> and
+<tt><taskdef></tt>). When you do this they are evaluated before
+any targets are executed.</p>
<p>
We have given some targets descriptions; this causes the <tt>projecthelp</tt>
1.1
jakarta-ant/src/etc/testcases/core/topleveltasks/notarget.xml
Index: notarget.xml
===================================================================
<project>
<echo message="Called" />
</project>
1.1
jakarta-ant/src/etc/testcases/core/topleveltasks/targetlevelant.xml
Index: targetlevelant.xml
===================================================================
<project basedir="." default="foo">
<target name="foo">
<ant antfile="notarget.xml" />
</target>
</project>
1.1
jakarta-ant/src/etc/testcases/core/topleveltasks/toplevelant.xml
Index: toplevelant.xml
===================================================================
<project basedir=".">
<ant antfile="notarget.xml" />
</project>
1.70 +1 -1 jakarta-ant/src/main/org/apache/tools/ant/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Main.java,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- Main.java 9 Jul 2002 21:05:57 -0000 1.69
+++ Main.java 15 Jul 2002 14:41:47 -0000 1.70
@@ -604,7 +604,7 @@
}
// make sure that we have a target to execute
- if (targets.size() == 0) {
+ if (targets.size() == 0 && project.getDefaultTarget() !=
null) {
targets.addElement(project.getDefaultTarget());
}
1.10 +1 -5
jakarta-ant/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
Index: ProjectHelperImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ProjectHelperImpl.java 11 Jul 2002 07:46:34 -0000 1.9
+++ ProjectHelperImpl.java 15 Jul 2002 14:41:47 -0000 1.10
@@ -451,11 +451,7 @@
}
}
- if (def == null) {
- throw new SAXParseException("The default attribute of
project "
- + "is required",
- helperImpl.locator);
- } else {
+ if (def != null) {
helperImpl.project.setDefaultTarget(def);
}
1.61 +11 -9
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
Index: Ant.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- Ant.java 9 Jul 2002 21:05:58 -0000 1.60
+++ Ant.java 15 Jul 2002 14:41:47 -0000 1.61
@@ -356,19 +356,21 @@
target = newProject.getDefaultTarget();
}
- addReferences();
-
- // Are we trying to call the target in which we are defined?
+ // Are we trying to call the target in which we are defined (or
+ // the build file if this is a top level task)?
if (newProject.getBaseDir().equals(project.getBaseDir()) &&
-
newProject.getProperty("ant.file").equals(project.getProperty("ant.file")) &&
- getOwningTarget() != null &&
- target.equals(this.getOwningTarget().getName())) {
-
+
newProject.getProperty("ant.file").equals(project.getProperty("ant.file"))
+ && (getOwningTarget() == null ||
+ getOwningTarget().getName().equals(target))) {
throw new BuildException("ant task calling its own parent "
- + "target");
+ + "target");
}
- newProject.executeTarget(target);
+ addReferences();
+
+ if (target != null) {
+ newProject.executeTarget(target);
+ }
} finally {
// help the gc
newProject = null;
1.26 +5 -4
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
Index: AntStructure.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/AntStructure.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- AntStructure.java 16 Apr 2002 07:15:18 -0000 1.25
+++ AntStructure.java 15 Jul 2002 14:41:47 -0000 1.26
@@ -196,13 +196,14 @@
out.println("");
- out.print("<!ELEMENT project (target | property | taskdef");
- out.print(" | typedef | ");
+ out.print("<!ELEMENT project (target | ");
+ out.print(TASKS);
+ out.print(" | ");
out.print(TYPES);
out.println(")*>");
out.println("<!ATTLIST project");
out.println(" name CDATA #IMPLIED");
- out.println(" default CDATA #REQUIRED");
+ out.println(" default CDATA #IMPLIED");
out.println(" basedir CDATA #IMPLIED>");
out.println("");
}
1.1
jakarta-ant/src/testcases/org/apache/tools/ant/TopLevelTaskTest.java
Index: TopLevelTaskTest.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant;
/**
* Tests for builds with tasks at the top level
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
* @since Ant 1.6
*/
public class TopLevelTaskTest extends BuildFileTest {
public TopLevelTaskTest(String name) {
super(name);
}
public void testNoTarget() {
configureProject("src/etc/testcases/core/topleveltasks/notarget.xml");
assertEquals("Called", getLog());
}
public void testCalledFromTopLevelAnt() {
configureProject("src/etc/testcases/core/topleveltasks/toplevelant.xml");
assertEquals("Called", getLog());
}
public void testCalledFromTargetLevelAnt() {
configureProject("src/etc/testcases/core/topleveltasks/targetlevelant.xml");
expectLog("foo", "Called");
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>