<subant> now supports nested <target> elements as <ant> does. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@420569 13f79535-47bb-0310-9956-ffa450edef68master
@@ -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> |
@@ -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> |
@@ -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> |
@@ -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> |
@@ -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/*<TargetElement>*/ 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; i<targets.size(); i++) { | |||
TargetElement targetElement = (TargetElement)targets.get(i); | |||
ant.addConfiguredTarget(targetElement); | |||
} | |||
try { | |||
ant.execute(); | |||
} catch (BuildException e) { | |||
@@ -342,6 +354,19 @@ public class SubAnt | |||
this.subTarget = target; | |||
} | |||
/** | |||
* 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". | |||
@@ -580,4 +605,4 @@ public class SubAnt | |||
} | |||
} | |||
} // END class SubAnt | |||
} // END class SubAnt |
@@ -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 { | |||
} | |||
} | |||
} |