Author: jhm Date: Mon Jul 10 08:41:28 2006 New Revision: 420569 URL: http://svn.apache.org/viewvc?rev=420569&view=rev Log: Bug 35850 <subant> now supports nested <target> elements as <ant> does.
Modified: ant/core/trunk/docs/manual/CoreTasks/subant.html ant/core/trunk/src/etc/testcases/taskdefs/subant.xml ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java Modified: ant/core/trunk/docs/manual/CoreTasks/subant.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/subant.html?rev=420569&r1=420568&r2=420569&view=diff ============================================================================== --- ant/core/trunk/docs/manual/CoreTasks/subant.html (original) +++ ant/core/trunk/docs/manual/CoreTasks/subant.html Mon Jul 10 08:41:28 2006 @@ -391,10 +391,48 @@ </table> <!-- End Element --> + + + +<!-- manually written --> + <!-- Start Element --> + <table border="0" cellspacing="0" cellpadding="2" width="100%"> + <tr><td> </td></tr> + <tr><td bgcolor="#828DA6"> + <font color="#ffffff" face="arial,helvetica.sanserif" size="-1"> + <strong>target</strong> (org.apache.tools.ant.taskdefs.Ant.TargetElement)</font> + </td></tr> + <tr><td><blockquote> + You can specify multiple targets using nested <code><target></code> 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. + <!-- Ignore --> + <!-- Ignore --> + <table border="1" cellpadding="2" cellspacing="0"> + <tr> + <td valign="top"><b>Attribute</b></td> + <td valign="top"><b>Description</b></td> + <td align="center" valign="top"><b>Required</b></td> + </tr> + <tr> + <td valign="top">name</td> + <td valign="top">The name of the called target.</td> + <td valign="top" align="center">Yes</td> + </tr> + </table> + <p><em>since Ant 1.7</em>.</p> + </blockquote></td></tr> + </table> + <!-- End Element --> +<!-- manually written end --> + </blockquote></td></tr> </table> <!-- End Elements --> + + <table border="0" cellspacing="0" cellpadding="2" width="100%"> <tr><td> </td></tr> @@ -408,14 +446,14 @@ <tr><td><blockquote> <pre> <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> </pre> <p> @@ -425,11 +463,11 @@ </p> <pre> <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> </pre> <p> @@ -439,7 +477,7 @@ </p> <pre> <subant target="compile" genericantfile="/opt/project/build1.xml"> - <dirset dir="." includes="projects*"/> + <dirset dir="." includes="projects*"/> </subant> </pre> <p> @@ -507,6 +545,16 @@ the root buildfile is capable to run the whole build over all modules. </p> + + <pre> + <subant failonerror="false"> + <fileset dir="." includes="**/build.xml" excludes="build.xml"/> + <target name="clean"/> + <target name="build"/> + </subant> + </pre> + + <p>Does a "clean build" for each subproject.</p> <!-- manually written --> @@ -537,4 +585,4 @@ </table> </body> -</html> +</html> \ No newline at end of file Modified: ant/core/trunk/src/etc/testcases/taskdefs/subant.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/subant.xml?rev=420569&r1=420568&r2=420569&view=diff ============================================================================== --- ant/core/trunk/src/etc/testcases/taskdefs/subant.xml (original) +++ ant/core/trunk/src/etc/testcases/taskdefs/subant.xml Mon Jul 10 08:41:28 2006 @@ -5,20 +5,45 @@ <subant genericantfile="subant/genericsubant.xml"> <dirset dir="." includes="subant-test*"/> </subant> - </target> + <target name="testgenericantfile"> <subant genericantfile="subant/genericsubant.xml"> <dirset dir="subant" includes="subant-test*"/> </subant> </target> + <target name="testantfile"> <subant antfile="mysubant.xml"> <dirset dir="." includes="subant/subant-test*"/> </subant> + </target> + + <target name="multipleTargets"> + <subant antfile="mysubant.xml"> + <dirset dir="." includes="subant/subant-test*"/> + <target name="one"/> + <target name="two"/> + </subant> + </target> + + <target name="multipleTargetsOneDoesntExist_FOEfalse"> + <subant antfile="mysubant.xml" failonerror="false"> + <dirset dir="." includes="subant/subant-test*"/> + <target name="one"/> + <target name="three"/> + </subant> + </target> + <target name="multipleTargetsOneDoesntExist_FOEtrue"> + <subant antfile="mysubant.xml" failonerror="true"> + <dirset dir="." includes="subant/subant-test*"/> + <target name="one"/> + <target name="three"/> + </subant> </target> + <target name="cleanup"> <!-- nothing to do --> </target> -</project> +</project> \ No newline at end of file Modified: ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml?rev=420569&r1=420568&r2=420569&view=diff ============================================================================== --- ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml (original) +++ ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml Mon Jul 10 08:41:28 2006 @@ -2,4 +2,13 @@ <target name="mysubant"> <echo message="${basedir}"/> </target> + <target name="one"> + <echo message="test1-one"/> + </target> + <target name="two"> + <echo message="test1-two"/> + </target> + <target name="three"> + <echo message="test1-three"/> + </target> </project> Modified: ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml?rev=420569&r1=420568&r2=420569&view=diff ============================================================================== --- ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml (original) +++ ant/core/trunk/src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml Mon Jul 10 08:41:28 2006 @@ -2,4 +2,10 @@ <target name="mysubant"> <echo message="${basedir}"/> </target> + <target name="one"> + <echo message="test2-one"/> + </target> + <target name="two"> + <echo message="test2-two"/> + </target> </project> Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java?rev=420569&r1=420568&r2=420569&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SubAnt.java Mon Jul 10 08:41:28 2006 @@ -34,6 +34,8 @@ 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 @@ private Vector references = new Vector(); private Vector propertySets = new Vector(); + /** the targets to call on the new project */ + private Vector/*<TargetElement>*/ targets = new Vector(); + + + /** * Pass output sent to System.out to the new project. * @@ -274,6 +281,11 @@ ant = createAntTask(directory); String antfilename = file.getAbsolutePath(); ant.setAntfile(antfilename); + for (int i=0; i<targets.size(); i++) { + TargetElement targetElement = (TargetElement)targets.get(i); + ant.addConfiguredTarget(targetElement); + } + try { ant.execute(); } catch (BuildException e) { @@ -343,6 +355,19 @@ } /** + * Add a target to this Ant invocation. + * @param t the <code>TargetElement</code> 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". * @param on true to enable verbose mode, false otherwise (default). @@ -580,4 +605,4 @@ } } -} // END class SubAnt +} // END class SubAnt \ No newline at end of file Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java?rev=420569&r1=420568&r2=420569&view=diff ============================================================================== --- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java (original) +++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java Mon Jul 10 08:41:28 2006 @@ -25,8 +25,7 @@ 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 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 @@ } -} +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]