[Index]

ant


Run a series of Ant tasks.

Not all tasks have been tested!

The Ant Project

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.

Property Expansion

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

ClassLoaders and Task Definitions

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.


Property Summary

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

classPath

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

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.

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.

stop

AccessREAD_ONLY
RequiredRead Only.

This flag is set by the stop method and should be examined by any Stoppable jobs in their processing loops.

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) R Gordon Ltd 2005 - Present