[Index]

ant


Run a series of Ant tasks.

Oddjob creates it's own Ant project to use internally this project can be shared between different AntJob jobs using the 'project' attribute. This allows taskdefs and properties to be defined in one place and shared in many jobs.

Oddjob component properties can be referenced inside an 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.

Not all tasks have been tested.

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!).


Property Summary

baseDir The base directory.
classLoader An optional class loader which will be set as Ant's 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.
tasks The ant XML configuration for the tasks.
version The ant version.

Example Summary

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.

Property Detail

baseDir

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

The base directory. Equivalent to setting the basedir attribute of an ant project.

classLoader

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo.

An optional class loader which will be set as Ant's class loader.

exception

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo, defaults to false.

How to handle build failure. If true, then a build failure will in an EXCEPTION state for this job.

messageLevel

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

The message level for output. one of DEBUG, ERROR, INFO, VERBOSE, WARN.

name

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

A name, can be any text.

output

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo. By default the output will only be written to the logger.

Where to write the resultant output from ant.

project

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

A reference to project in another ant job. This allows reference ids to be shared.

tasks

Configured ByELEMENT
AccessREAD_WRITE
RequiredYes.

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.

version

AccessREAD_ONLY

The ant version.


Examples

Example 1

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>

Example 2

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>

Example 3

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'

Example 4

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.

Example 5

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>


(c) Rob Gordon 2005 - 2013