|
- <!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
- <html>
- <head>
- <meta http-equiv="Content-Language" content="en-us">
- <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
- <title>Subant Task</title>
- </head>
-
- <body>
- <h2>Subant Task</h2>
- <h3 id="description">Description</h3>
- <p>
- Calls a given target for all defined sub-builds.
- This is an extension
- of Ant for bulk project execution.
-
- <strong>This task must not be used outside of a
- <code>target</code> if it invokes the same build file it is
- part of.</strong>
- </p>
- <p><em>Since Apache Ant 1.6</em></p>
-
- <p>
- <code>subant</code> uses <code>ant</code> internally so many things
- said in <a href="ant.html"><code>ant</code>'s manual page</a> apply
- here as well.
- </p>
-
- <h3 id="Use with directories">Use with directories</h3>
- <p>
- subant can be used with directory sets to execute a build from different directories.
- 2 different options are offered :
- </p>
- <ul>
- <li>
- to run the same build file <code>/somepath/otherpath/mybuild.xml</code>
- with different base directories, use the genericantfile attribute
- </li>
- <li>if you want to run <code>directory1/mybuild.xml</code>, <code>directory2/mybuild.xml</code>, <code>....</code>,
- use the antfile attribute. The subant task does not set the base directory for you in this case, because you can specify it in each build file.
- </li>
- </ul>
-
- <h3 id="attributes">Parameters</h3>
- <table>
- <tr>
- <td valign="top" align="left">
- <b>Attribute</b>
- </td>
- <td valign="top" align="left">
- <b>Description</b>
- </td>
- <td valign="top" align="left">
- <b>Type</b>
- </td>
- <td valign="top" align="left">
- <b>Requirement</b>
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- antfile
- </td>
- <td valign="top" align="left">
- Build file name, to use in conjunction with directories.<br> Defaults to "build.xml".<br> If <code>genericantfile</code> is set, this attribute is ignored.
- </td>
- <td valign="top" align="left">
- String
- </td>
- <td valign="top" align="left" rowspan="10">
- Optional
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- buildpath
- </td>
- <td valign="top" align="left">
- Set the buildpath to be used to find sub-projects.
- </td>
- <td valign="top" align="left">
- Path
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- buildpathref
- </td>
- <td valign="top" align="left">
- Buildpath to use, by reference.
- </td>
- <td valign="top" align="left">
- Reference
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- failonerror
- </td>
- <td valign="top" align="left">
- Sets whether to fail with a build exception on error, or go on.
- </td>
- <td valign="top" align="left">
- boolean
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- genericantfile
- </td>
- <td valign="top" align="left">
- Build file path, to use in conjunction with directories.<br> Use <code>genericantfile</code>, in order to run the same build file with different basedirs.<br> If this attribute is set, <code>antfile</code> is ignored.
- </td>
- <td valign="top" align="left">
- File
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- inheritall
- </td>
- <td valign="top" align="left">
- Corresponds to
- <code><ant></code>'s
- <code>inheritall</code> attribute but defaults
- to false in this task..
- </td>
- <td valign="top" align="left">
- boolean
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- inheritrefs
- </td>
- <td valign="top" align="left">
- Corresponds to <code><ant></code>'s <code>inheritrefs</code> attribute.
- </td>
- <td valign="top" align="left">
- boolean
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- output
- </td>
- <td valign="top" align="left">
- Corresponds to <code><ant></code>'s <code>output</code> attribute.
- </td>
- <td valign="top" align="left">
- String
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- target
- </td>
- <td valign="top" align="left"> </td>
- <td valign="top" align="left">
- String
- </td>
- </tr>
- <tr>
- <td valign="top" align="left">
- verbose
- </td>
- <td valign="top" align="left">
- Enable/ disable log messages showing when each sub-build path is entered/ exited.
- The default value is false.
- </td>
- <td valign="top" align="left">
- boolean
- </td>
- </tr>
- </table>
- <h3 id="elements">Parameters as nested elements</h3>
- <h4>any filesystem based <a href="../Types/resources.html#collection">resource collection</a></h4>
- This includes <code><fileset></code>,
- <code><dirset></code> and <code><filelist></code>
- which are the nested resource collections supported prior
- to Ant 1.7.
- <h4><strong>dirset</strong> (org.apache.tools.ant.types.DirSet)</h4>
- Adds a directory set to the implicit build path.
- <p>
- <em>Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead!</em>
- </p>
- <h4><strong>filelist</strong> (org.apache.tools.ant.types.FileList)</h4>
- Adds an ordered file list to the implicit build path.
- <p>
- <em>Note that contrary to file and directory sets, file lists can reference non-existent files or directories!</em>
- </p>
- <h4><strong>fileset</strong> (org.apache.tools.ant.types.FileSet)</h4>
- Adds a file set to the implicit build path.
- <p>
- <em>Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead!</em>
- </p>
- <h4><strong>property</strong> (org.apache.tools.ant.taskdefs.Property)</h4>
- Corresponds to <code><ant></code>'s nested <code><property></code> element.
- <p>
- When more than one nested <code><property></code> element
- would set a property of the same name, the one declared last will
- win. This is for backwards compatibility reasons even so it is
- different from the way <code><property></code> tasks in build
- files behave.
- </p>
- <h4><strong>propertyset</strong> (org.apache.tools.ant.types.PropertySet)</h4>
- Corresponds to <code><ant></code>'s nested <code><propertyset></code> element.
- <h4><strong>buildpath</strong> (org.apache.tools.ant.types.Path)</h4>
- Creates a nested build path, and add it to the implicit build path.
- <h4><strong>buildpathelement</strong> (org.apache.tools.ant.types.Path.PathElement)</h4>
- Creates a nested <code><buildpathelement></code>, and add it to the implicit build path.
- <h4><strong>target</strong> (org.apache.tools.ant.taskdefs.Ant.TargetElement)</h4>
- 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.
- <table>
- <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>
- <h3 id="examples">Examples</h3>
- <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>
- </project>
- </pre>
- <p>
- this snippet build file will run ant in each subdirectory of the project directory,
- where a file called build.xml can be found.
- The property build.dir will have the value subant1.build in the ant projects called by subant.
- </p>
- <pre>
- <subant target="">
- <propertyset>
- <propertyref prefix="toplevel"/>
- <mapper type="glob" from="foo*" to="bar*"/>
- </propertyset>
- <fileset dir="." includes="*/build.xml"/>
- </subant>
- </pre>
- <p>
- this snippet build file will run ant in each subdirectory of the project directory,
- where a file called build.xml can be found.
- All properties whose name starts with "foo" are passed, their names are changed to start with "bar" instead
- </p>
- <pre>
- <subant target="compile" genericantfile="/opt/project/build1.xml">
- <dirset dir="." includes="projects*"/>
- </subant>
- </pre>
- <p>
- assuming the subdirs of the project dir are called projects1, projects2, projects3
- this snippet will execute the compile target of /opt/project/build1.xml,
- setting the basedir to projects1, projects2, projects3
- </p>
- <p>
- Now a little more complex - but useful - scenario. Assume that we have
- a directory structure like this:
- </p>
- <pre>
- root
- | common.xml
- | build.xml
- |
- +-- modules
- +-- modA
- | +-- src
- +-- modB
- +-- src
-
- <u><b>common.xml:</b></u><br>
- <project>
- <property name="src.dir" value="src"/>
- <property name="build.dir" value="build"/>
- <property name="classes.dir" value="${build.dir}/classes"/>
-
- <target name="compile">
- <mkdir dir="${classes.dir}"/>
- <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
- </target>
-
- <!-- more targets -->
- </project>
-
- <u><b>build.xml:</b></u><br>
- <project>
- <macrodef name="iterate">
- <attribute name="target"/>
- <sequential>
- <subant target="@{target}">
- <fileset dir="modules" includes="*/build.xml"/>
- </subant>
- </sequential>
- </macrodef>
-
-
- <target name="compile">
- <iterate target="compile"/>
- </target>
-
- <!-- more targets -->
- </project>
-
- <u><b>modules/modA/build.xml:</b></u><br>
- <project name="modA">
- <import file="../../common.xml"/>
- </project>
- </pre>
-
- <p>
- This results in very small buildfiles in the modules, maintainable
- buildfile (common.xml) and a clear project structure. Additionally
- 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>
- <p>
- <b>Hint:</b> because buildfiles are plain xml, you could generate the
- masterbuildfile from the common buildfile by using a XSLT transformation:
- </p>
-
- <pre>
- <xslt in="common.xml"
- out="master.xml"
- style="${ant.home}/etc/common2master.xsl"/>
- </pre>
- </body>
- </html>
|