Not all tasks have been tested!
Oddjob component properties can be referenced inside Ant tasks using the ${id.property} notation. Ant will look up the Oddjob property before it looks up properties defined with the <property> tag. The oddjob derived properties of an Ant task aren't constant. Oddjob variables can change unlike Ant properties.
Note: Ant looks up properties beginning with 'ant.' - Therefore no component can have an id of 'ant' as the lookup will fail to retrieve the properties from that component (unless of course the 'ant' component implements all the properties that Ant requires!).
A class path or class loader can be supplied and this will be used for task definitions and antlibs. Name space antlibs will only work if the antlib is placed in the oj-ant/lib directory. This is becuase name space ant libs require the ant lib to be loaded in the same class loader as Ant.
baseDir | The base directory. |
classLoader | An optional class loader which will be set as Ant's class loader. |
classPath | A class path to use to create Ants class loader. |
exception | How to handle build failure. |
messageLevel | The message level for output. |
name | A name, can be any text. |
output | Where to write the resultant output from ant. |
project | A reference to project in another ant job. |
stop | This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops. |
tasks | The ant XML configuration for the tasks. |
version | The ant version. |
Example 1 | Running an Ant Echo Task. |
Example 2 | Defining Ant properties in an Ant Job. |
Example 3 | Using Oddjob variables. |
Example 4 | Sharing a project. |
Example 5 | Working with files in Ant. |
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
The base directory. Equivalent to setting the basedir attribute of an ant project.
Configured By | ELEMENT |
Access | READ_WRITE |
Required | No. |
An optional class loader which will be set as Ant's class loader.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
A class path to use to create Ants class loader. This is often more convenient than providing a separate class loader. If a class loader is also provided then it will be used as the parent class loader of the class loader created from this path, otherwise the class loader of this job will be used as the parent.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No, defaults to false. |
How to handle build failure. If true, then a build failure will in an EXCEPTION state for this job.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
The message level for output. one of DEBUG, ERROR, INFO, VERBOSE, WARN.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
A name, can be any text.
Configured By | ELEMENT |
Access | READ_WRITE |
Required | No. By default the output will only be written to the logger. |
Where to write the resultant output from ant.
Configured By | ATTRIBUTE |
Access | READ_WRITE |
Required | No. |
A reference to project in another ant job. This allows reference ids to be shared.
Access | READ_ONLY |
Required | Read Only. |
This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops.
Configured By | ELEMENT |
Access | READ_WRITE |
Required | Yes. |
The ant XML configuration for the tasks. The document element for the task definitions is expected to be <tasks>. Any type of content that is normally contained in an Ant target is allowed as child elements of <tasks> including properties and task definitions.
Access | READ_ONLY |
The ant version.
Running an Ant Echo Task. The resultant output is captured in a buffer.
<oddjob id="this"> <job> <ant id="an-ant"> <output> <identify id="result"> <value> <buffer/> </value> </identify> </output> <tasks> <xml> <tasks> <echo message="${this.args[0]}"/> </tasks> </xml> </tasks> </ant> </job> </oddjob>
Defining Ant properties in an Ant Job.
<ant> <tasks> <xml> <tasks> <property name="test.thing" value="Test"/> <echo message="${test.thing}"/> </tasks> </xml> </tasks> </ant>
Using Oddjob variables. Variables and properties defined in Oddjob are available in the Ant tasks.
<oddjob id="this"> <job> <sequential> <jobs> <variables id="v"> <fruit> <value value="Apples"/> </fruit> </variables> <ant> <tasks> <xml> <tasks> <taskdef name="result" classname="org.oddjob.ant.AntJobTest$ResultTask"/> <property name="our.fruit" value="${v.fruit}"/> <property name="v.fruit" value="Pears"/> <result key="one" result="${our.fruit}"/> <result key="two" result="${v.fruit}"/> </tasks> </xml> </tasks> </ant> </jobs> </sequential> </job> </oddjob>Note that the property defined in Ant does not override that defined in Oddjob (as per the rules of Ant). the result of both one and two is 'Apples'
Sharing a project.
<oddjob> <job> <sequential> <jobs> <variables id="v"> <fruit> <value value="Apples"/> </fruit> </variables> <ant id="defs"> <tasks> <xml> <tasks> <taskdef name="result" classname="org.oddjob.ant.AntJobTest$ResultTask"/> <property name="our.fruit" value="${v.fruit}"/> <property name="v.fruit" value="Pears"/> </tasks> </xml> </tasks> </ant> <ant project="${defs.project}"> <tasks> <xml> <tasks> <property name="our.fruit" value="Pears"/> <result key="three" result="${our.fruit}"/> <result key="four" result="${v.fruit}"/> </tasks> </xml> </tasks> </ant> </jobs> </sequential> </job> </oddjob>The first Ant job declares a task and properties that the second Ant project can access.
Working with files in Ant.
<oddjob> <job> <sequential name="Using Ant to Manipulate Files"> <jobs> <properties> <values> <value key="our.test.file.name" value="test.txt"/> </values> </properties> <ant baseDir="${work.dir}"> <tasks> <xml> <tasks> <patternset id="file.test"> <include name="${our.test.file.name}"/> </patternset> <touch file="${our.test.file.name}"/> <copy todir=".."> <fileset dir="."> <patternset refid="file.test"/> </fileset> </copy> <delete file="../${our.test.file.name}"/> <delete file="${our.test.file.name}"/> <echo message="Done."/> </tasks> </xml> </tasks> </ant> </jobs> </sequential> </job> </oddjob>