Class AntJob

All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, ArooaSessionAware, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resettable, Stateful, Stoppable

public class AntJob extends SerializableJob implements Stoppable
Author:
rob
See Also:

Description

Run a series of Ant tasks.

Not all tasks have been tested!

The Ant Project

Oddjob creates its 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 because name space ant libs require the ant lib to be loaded in the same class loader as Ant.

Example

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>
  • Constructor Details

    • AntJob

      public AntJob()
  • Method Details

    • setOutput

      public void setOutput(OutputStream out)
    • getOutput

      public OutputStream getOutput()
      Return the ant tasks output.
      Returns:
      The output as a string.
    • getProject

      public org.apache.tools.ant.Project getProject()
      Get the project used for the tasks.
      Returns:
      The project.
    • setProject

      public void setProject(org.apache.tools.ant.Project project)
      Set the project to use for the tasks. It is assumed the project is already initialised.
      Parameters:
      project - The project.
    • setMessageLevel

      public void setMessageLevel(String messageLevel)
    • getMessageLevel

      public String getMessageLevel()
    • execute

      protected int execute() throws Exception
      Execute the tasks.
      Specified by:
      execute in class SimpleJob
      Returns:
      0 if the job is complete, anything else otherwise.
      Throws:
      Exception - If the unexpected occurs.
    • onStop

      protected void onStop()
      Description copied from class: SimpleJob
      Allow sub classes to do something on stop.
      Overrides:
      onStop in class SimpleJob
    • onReset

      protected void onReset()
      Description copied from class: SimpleJob
      Allow sub classes to do something on reset.
      Overrides:
      onReset in class SimpleJob
    • ineritProperties

      protected void ineritProperties(org.apache.tools.ant.PropertyHelper propertyHelper)
    • buildAntClassLoader

      protected ClassLoader buildAntClassLoader() throws IOException
      Throws:
      IOException
    • isException

      public boolean isException()
    • setException

      public void setException(boolean exception)
    • getBaseDir

      public File getBaseDir()
    • setBaseDir

      public void setBaseDir(File baseDir)
    • getTasks

      public String getTasks()
    • setTasks

      public void setTasks(String xml)
    • getClassLoader

      public ClassLoader getClassLoader()
    • setClassLoader

      public void setClassLoader(ClassLoader classLoader)
    • getVersion

      public String getVersion()
      Returns:
      The ant version or nothing if the job hasn't run yet.
      Reference Property:
      version

      Description

      The ant version.
    • getClassPath

      public String getClassPath()
    • setClassPath

      public void setClassPath(String classPath)