diff --git a/docs/manual/CoreTasks/subant.html b/docs/manual/CoreTasks/subant.html index 8e5d0ea75..880b7f99d 100644 --- a/docs/manual/CoreTasks/subant.html +++ b/docs/manual/CoreTasks/subant.html @@ -391,10 +391,48 @@ + + + + + + + + + +
 
+ + target (org.apache.tools.ant.taskdefs.Ant.TargetElement) +
+ You can specify multiple targets using nested <target> elements + instead of using the target attribute. These will be executed as if + Ant had been invoked with a single target whose dependencies are the + targets so specified, in the order specified. + + + + + + + + + + + + + +
AttributeDescriptionRequired
nameThe name of the called target.Yes
+

since Ant 1.7.

+
+ + + + + @@ -408,14 +446,14 @@
 
         <project name="subant" default="subant1">
-        <property name="build.dir" value="subant.build"/>
-        <target name="subant1">
-            <subant target="">
-              <property name="build.dir" value="subant1.build"/>
-              <property name="not.overloaded" value="not.overloaded"/>
-              <fileset dir="." includes="*/build.xml"/>
-            </subant>
-        </target>
+            <property name="build.dir" value="subant.build"/>
+            <target name="subant1">
+                <subant target="">
+                    <property name="build.dir" value="subant1.build"/>
+                    <property name="not.overloaded" value="not.overloaded"/>
+                    <fileset dir="." includes="*/build.xml"/>
+                </subant>
+            </target>
         </project>
         

@@ -425,11 +463,11 @@

           <subant target="">
-             <propertyset>
+              <propertyset>
                   <propertyref prefix="toplevel"/>
                   <mapper type="glob" from="foo*" to="bar*"/>
-             </propertyset>
-             <fileset dir="." includes="*/build.xml"/>
+              </propertyset>
+              <fileset dir="." includes="*/build.xml"/>
           </subant>
         

@@ -439,7 +477,7 @@

           <subant target="compile" genericantfile="/opt/project/build1.xml">
-             <dirset dir="." includes="projects*"/>
+              <dirset dir="." includes="projects*"/>
           </subant>
         

@@ -507,6 +545,16 @@ the root buildfile is capable to run the whole build over all modules.

+ +
+        <subant failonerror="false">
+            <fileset dir="." includes="**/build.xml" excludes="build.xml"/>
+            <target name="clean"/>
+            <target name="build"/>
+        </subant>
+        
+ +

Does a "clean build" for each subproject.

@@ -537,4 +585,4 @@
- + \ No newline at end of file diff --git a/src/etc/testcases/taskdefs/subant.xml b/src/etc/testcases/taskdefs/subant.xml index e2c00c01a..dfa56e7c3 100644 --- a/src/etc/testcases/taskdefs/subant.xml +++ b/src/etc/testcases/taskdefs/subant.xml @@ -5,20 +5,45 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + - + \ No newline at end of file diff --git a/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml b/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml index 6c5d17d4d..ab61f1aa6 100644 --- a/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml +++ b/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml @@ -2,4 +2,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml b/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml index 055267426..e27770869 100644 --- a/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml +++ b/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml @@ -2,4 +2,10 @@ + + + + + + \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java index 7e3ccb47c..5cd48516a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java +++ b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java @@ -34,6 +34,8 @@ import org.apache.tools.ant.types.PropertySet; import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.ResourceCollection; +import org.apache.tools.ant.taskdefs.Ant.TargetElement; + /** * Calls a given target for all defined sub-builds. This is an extension @@ -76,6 +78,11 @@ public class SubAnt private Vector references = new Vector(); private Vector propertySets = new Vector(); + /** the targets to call on the new project */ + private Vector/**/ targets = new Vector(); + + + /** * Pass output sent to System.out to the new project. * @@ -274,6 +281,11 @@ public class SubAnt ant = createAntTask(directory); String antfilename = file.getAbsolutePath(); ant.setAntfile(antfilename); + for (int i=0; iTargetElement to add. + * @since Ant 1.7 + */ + public void addConfiguredTarget(TargetElement t) { + String name = t.getName(); + if ("".equals(name)) { + throw new BuildException("target name must not be empty"); + } + targets.add(t); + } + /** * Enable/ disable verbose log messages showing when each sub-build path is entered/ exited. * The default value is "false". @@ -580,4 +605,4 @@ public class SubAnt } } -} // END class SubAnt +} // END class SubAnt \ No newline at end of file diff --git a/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java b/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java index 3ddd089a5..4b12b9f3b 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java @@ -25,8 +25,7 @@ import org.apache.tools.ant.BuildEvent; import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.BuildListener; -/** - */ + public class SubAntTest extends BuildFileTest { public SubAntTest(String name) { @@ -77,6 +76,25 @@ public class SubAntTest extends BuildFileTest { }); } + + public void testMultipleTargets() { + executeTarget("multipleTargets"); + assertLogContaining("test1-one"); + assertLogContaining("test1-two"); + assertLogContaining("test2-one"); + assertLogContaining("test2-two"); + } + + public void testMultipleTargetsOneDoesntExist_FOEfalse() { + executeTarget("multipleTargetsOneDoesntExist_FOEfalse"); + assertLogContaining("Target \"three\" does not exist in the project \"subant\""); + } + + public void testMultipleTargetsOneDoesntExist_FOEtrue() { + expectBuildExceptionContaining("multipleTargetsOneDoesntExist_FOEtrue", + "Calling not existent target", + "Target \"three\" does not exist in the project \"subant\""); + } protected void testBaseDirs(String target, String[] dirs) { SubAntTest.BasedirChecker bc = new SubAntTest.BasedirChecker(dirs); @@ -126,4 +144,4 @@ public class SubAntTest extends BuildFileTest { } -} +} \ No newline at end of file