Browse Source

Bug 35850

<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-ffa450edef68
master
Jan Materne 19 years ago
parent
commit
370ae530e4
6 changed files with 150 additions and 19 deletions
  1. +61
    -13
      docs/manual/CoreTasks/subant.html
  2. +27
    -2
      src/etc/testcases/taskdefs/subant.xml
  3. +9
    -0
      src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml
  4. +6
    -0
      src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml
  5. +26
    -1
      src/main/org/apache/tools/ant/taskdefs/SubAnt.java
  6. +21
    -3
      src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java

+ 61
- 13
docs/manual/CoreTasks/subant.html View File

@@ -391,10 +391,48 @@
</table> </table>
<!-- End Element --> <!-- End Element -->





<!-- manually written -->
<!-- Start Element -->
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td>&nbsp;</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>&lt;target&gt;</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> </blockquote></td></tr>


</table> </table>
<!-- End Elements --> <!-- End Elements -->


<table border="0" cellspacing="0" cellpadding="2" width="100%"> <table border="0" cellspacing="0" cellpadding="2" width="100%">
<tr><td>&nbsp;</td></tr> <tr><td>&nbsp;</td></tr>
@@ -408,14 +446,14 @@
<tr><td><blockquote> <tr><td><blockquote>
<pre> <pre>
&lt;project name="subant" default="subant1"&gt; &lt;project name="subant" default="subant1"&gt;
&lt;property name="build.dir" value="subant.build"/&gt;
&lt;target name="subant1"&gt;
&lt;subant target=""&gt;
&lt;property name="build.dir" value="subant1.build"/&gt;
&lt;property name="not.overloaded" value="not.overloaded"/&gt;
&lt;fileset dir="." includes="*/build.xml"/&gt;
&lt;/subant&gt;
&lt;/target&gt;
&lt;property name="build.dir" value="subant.build"/&gt;
&lt;target name="subant1"&gt;
&lt;subant target=""&gt;
&lt;property name="build.dir" value="subant1.build"/&gt;
&lt;property name="not.overloaded" value="not.overloaded"/&gt;
&lt;fileset dir="." includes="*/build.xml"/&gt;
&lt;/subant&gt;
&lt;/target&gt;
&lt;/project&gt; &lt;/project&gt;
</pre> </pre>
<p> <p>
@@ -425,11 +463,11 @@
</p> </p>
<pre> <pre>
&lt;subant target=""&gt; &lt;subant target=""&gt;
&lt;propertyset&gt;
&lt;propertyset&gt;
&lt;propertyref prefix="toplevel"/&gt; &lt;propertyref prefix="toplevel"/&gt;
&lt;mapper type="glob" from="foo*" to="bar*"/&gt; &lt;mapper type="glob" from="foo*" to="bar*"/&gt;
&lt;/propertyset&gt;
&lt;fileset dir="." includes="*/build.xml"/&gt;
&lt;/propertyset&gt;
&lt;fileset dir="." includes="*/build.xml"/&gt;
&lt;/subant&gt; &lt;/subant&gt;
</pre> </pre>
<p> <p>
@@ -439,7 +477,7 @@
</p> </p>
<pre> <pre>
&lt;subant target="compile" genericantfile="/opt/project/build1.xml"&gt; &lt;subant target="compile" genericantfile="/opt/project/build1.xml"&gt;
&lt;dirset dir="." includes="projects*"/&gt;
&lt;dirset dir="." includes="projects*"/&gt;
&lt;/subant&gt; &lt;/subant&gt;
</pre> </pre>
<p> <p>
@@ -507,6 +545,16 @@
the root buildfile is capable to run the whole build over all the root buildfile is capable to run the whole build over all
modules. modules.
</p> </p>
<pre>
&lt;subant failonerror="false"&gt;
&lt;fileset dir="." includes="**/build.xml" excludes="build.xml"/&gt;
&lt;target name="clean"/&gt;
&lt;target name="build"/&gt;
&lt;/subant&gt;
</pre>
<p>Does a "clean build" for each subproject.</p>


<!-- manually written --> <!-- manually written -->


@@ -537,4 +585,4 @@
</table> </table>


</body> </body>
</html>
</html>

+ 27
- 2
src/etc/testcases/taskdefs/subant.xml View File

@@ -5,20 +5,45 @@
<subant genericantfile="subant/genericsubant.xml"> <subant genericantfile="subant/genericsubant.xml">
<dirset dir="." includes="subant-test*"/> <dirset dir="." includes="subant-test*"/>
</subant> </subant>

</target> </target>

<target name="testgenericantfile"> <target name="testgenericantfile">
<subant genericantfile="subant/genericsubant.xml"> <subant genericantfile="subant/genericsubant.xml">
<dirset dir="subant" includes="subant-test*"/> <dirset dir="subant" includes="subant-test*"/>
</subant> </subant>
</target> </target>

<target name="testantfile"> <target name="testantfile">
<subant antfile="mysubant.xml"> <subant antfile="mysubant.xml">
<dirset dir="." includes="subant/subant-test*"/> <dirset dir="." includes="subant/subant-test*"/>
</subant> </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>

<target name="cleanup"> <target name="cleanup">
<!-- nothing to do --> <!-- nothing to do -->
</target> </target>
</project>
</project>

+ 9
- 0
src/etc/testcases/taskdefs/subant/subant-test1/mysubant.xml View File

@@ -2,4 +2,13 @@
<target name="mysubant"> <target name="mysubant">
<echo message="${basedir}"/> <echo message="${basedir}"/>
</target> </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> </project>

+ 6
- 0
src/etc/testcases/taskdefs/subant/subant-test2/mysubant.xml View File

@@ -2,4 +2,10 @@
<target name="mysubant"> <target name="mysubant">
<echo message="${basedir}"/> <echo message="${basedir}"/>
</target> </target>
<target name="one">
<echo message="test2-one"/>
</target>
<target name="two">
<echo message="test2-two"/>
</target>
</project> </project>

+ 26
- 1
src/main/org/apache/tools/ant/taskdefs/SubAnt.java View File

@@ -34,6 +34,8 @@ import org.apache.tools.ant.types.PropertySet;
import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.ResourceCollection; 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 * 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 references = new Vector();
private Vector propertySets = 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. * Pass output sent to System.out to the new project.
* *
@@ -274,6 +281,11 @@ public class SubAnt
ant = createAntTask(directory); ant = createAntTask(directory);
String antfilename = file.getAbsolutePath(); String antfilename = file.getAbsolutePath();
ant.setAntfile(antfilename); ant.setAntfile(antfilename);
for (int i=0; i<targets.size(); i++) {
TargetElement targetElement = (TargetElement)targets.get(i);
ant.addConfiguredTarget(targetElement);
}
try { try {
ant.execute(); ant.execute();
} catch (BuildException e) { } catch (BuildException e) {
@@ -342,6 +354,19 @@ public class SubAnt
this.subTarget = target; 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. * Enable/ disable verbose log messages showing when each sub-build path is entered/ exited.
* The default value is "false". * The default value is "false".
@@ -580,4 +605,4 @@ public class SubAnt
} }
} }


} // END class SubAnt
} // END class SubAnt

+ 21
- 3
src/testcases/org/apache/tools/ant/taskdefs/SubAntTest.java View File

@@ -25,8 +25,7 @@ import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.BuildFileTest;
import org.apache.tools.ant.BuildListener; import org.apache.tools.ant.BuildListener;


/**
*/

public class SubAntTest extends BuildFileTest { public class SubAntTest extends BuildFileTest {


public SubAntTest(String name) { 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) { protected void testBaseDirs(String target, String[] dirs) {
SubAntTest.BasedirChecker bc = new SubAntTest.BasedirChecker(dirs); SubAntTest.BasedirChecker bc = new SubAntTest.BasedirChecker(dirs);
@@ -126,4 +144,4 @@ public class SubAntTest extends BuildFileTest {
} }




}
}

Loading…
Cancel
Save