Ant Parent Elements


There are many parent tags in Ant, which are described in this section.

Project Tag

All targets are nested within a parent tag that defines the Ant project:

 <project basedir="[working directory]" default="[default task]" name="[project name]">       <!--All tasks will be nested within targets here--> </project> 

Parameters

  • name: Name of the project.

  • default*: The target to use when one is not specified in the Ant command line execution.

  • basedir: The working directory for the project or root path for the project; defaults to the parent directory of the build file.

Target Tag

All of Ants tasks fit into a parent target element:

 <target name="[target name]"/> 

All tasks reside within target tags. The parent target tag defines the order of execution by declaring dependences. All dependent tasks will then execute before the task that defined it. This relationship is the primary way to define execution order within Ant files. Alternatively, the antcall and ant tasks can be used to execute tasks by target name. For more information, refer to these tasks under the section Ants Key Tasks later in this chapter for more detail.

Parameters

  • name * : Name of the target.

  • depends: A comma-separated list of tasks that must execute all of their tasks dependences, listed in their task parameter, before the task will execute:

     <target name="[target name]" depends="[dependent target name]"/> 

    When the target is called, the dependent target will execute will execute first. For example, consider the following usage:

     <target name="A"/> <target name="B" depends="A"/> <target name="C" depends="B"/> <target name="D" depends="C,E"/> <target name="E" depends="C,B,A"/> 

    If we execute the following command, the order of execution will be A, B, C, E, and then D:

     ant d 

    If we execute the following command, the order of execution will be A, B, C, and then E. No dependency is defined for D, so target D will not execute:

     ant e 
  • if: Name of a property that must exist in order for the task to run. It does not evaluate against the value of a property, it only checks to see if the property exists:

     <target name="[target name]" if="[property name]"/> 

    When the target executes, it looks to see if a property with that name exists. If it does, the task will execute.

  • unless: Name of a property that must not be set in order for the task to execute. The unless parameter does not depend on the if parameter. It only evaluates that a property does not exist; it does not evaluate against the value of a property:

     <target name="[target name]" unless="[property name]"/> 

    When the target executes, it will look to see if a property with that name exists. If it does, the task will not execute.

  • description: A short description of the task.. These descriptions do not print to the screen:

     <target name="[target name]" description="[task description]"/> 

    When you use Ants command line option projecthelp, all the tasks and their descriptions will be printed to the screen.

Path Tag

The path element allows for paths to be used by many tasks:

 <path id=[property] path="[path]"/> 

Parameter

  • id*: Property to represent many path and class path references. The property is referred to as a reference id . Many tasks allow the use of a path task via the reference id.

Nested Parameters

  • pathelement: A class used to specify both paths and class paths. It is often used as a child of a project to create a set of reusable paths and class paths:

     <path>     <pathelement path="[path]"/> </path> 
  • path: A comma-separated list of paths:

     <path>     <pathelement path="[path]"/> </path> 
  • location: A comma-separated list of paths relative to the base directory of the project:

     <path>     <pathelement location="classes"/> </path> 
  • fileset: Groups a set of files and directories. The following buildfile snippets groups all jar files in the /cvs/jars directory as follows :

     <path>     <fileset dir="/cvs/jars" >         <include name="**/*.jar"/>     </fileset> </path> 

Filter Tag

Filters can be used for file-copying tasks. All instances of a specified token can be replaced with a specified value.

A token is a value that can be automatically expanded in a set of text files when they are copied . Tokens are encased in the @ character as in @filename@. If a token exists in a file but no token is defined in the buildfile then no action will be taken, i.e., the token defined in the file will not be changed.

You define a token using the filter tag as follows:

 <filter token="filename" value="autoexec.bat"/> 

Later if you copied a text file with that contained the text @filename@ and filtering is on, the text @filename@ is replaced with autoexec.bat. Demonstrated as follows:

 <copy todir="/tmp" filtering="true">     <fileset dir="/src/config"/>   </copy> 

Parameters

  • token*: Value of the string of text to be replaced in the file. An at sign (@) will be placed around this value automatically.

  • value*: Replacement value to be applied to the token in the file.

  • filtersfile: File containing one name/value pair per line. This file creates filters for every entry in the properties file.

  • filtersfile*: A properties file from which to read the filters.

Tstamp Tag

The tstamp task sets several properties to the current date and time. From the system time:

  • DSTAMP: The date formatted as yyyymmdd.

  • TSTAMP : The time formatted as hhmm.

  • TODAY: The current date formatted as month day year.

The tag is as follows:

 <tstamp/> 

Nested Parameters

  • property: A property to set to a particular time/date format.

  • pattern: Time/date pattern to use:

     <tstamp>     <format property="TODAY_UK" pattern="d MMMM yyyy"> </tstamp> 



Professional Java Tools for Extreme Programming
Professional Java Tools for Extreme Programming: Ant, XDoclet, JUnit, Cactus, and Maven (Programmer to Programmer)
ISBN: 0764556177
EAN: 2147483647
Year: 2003
Pages: 228

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net