ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r420569 - in /ant/core/trunk: docs/manual/CoreTasks/ src/etc/testcases/taskdefs/ src/etc/testcases/taskdefs/subant/subant-test1/ src/etc/testcases/taskdefs/subant/subant-test2/ src/main/org/apache/tools/ant/taskdefs/ src/testcases/org/apach...
Date Mon, 10 Jul 2006 15:41:29 GMT
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>&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>
 
     </table>
     <!-- End Elements -->
+    
+    
 
     <table border="0" cellspacing="0" cellpadding="2" width="100%">
       <tr><td>&nbsp;</td></tr>
@@ -408,14 +446,14 @@
       <tr><td><blockquote>
         <pre>
         &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;
         </pre>
 <p>
@@ -425,11 +463,11 @@
         </p>
 <pre>
           &lt;subant target=""&gt;
-             &lt;propertyset&gt;
+              &lt;propertyset&gt;
                   &lt;propertyref prefix="toplevel"/&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;
         </pre>
 <p>
@@ -439,7 +477,7 @@
         </p>
 <pre>
           &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;
         </pre>
 <p>
@@ -507,6 +545,16 @@
         the root buildfile is capable to run the whole build over all
         modules.
         </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 -->
 
@@ -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: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message