Class AntJob
- All Implemented Interfaces:
Serializable,Runnable,ArooaContextAware,ArooaSessionAware,Forceable,PropertyChangeNotifier,Iconic,LogEnabled,Resettable,Stateful,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 allowstaskdefs 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>
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ClassLoaderprotected intexecute()Execute the tasks.Return the ant tasks output.org.apache.tools.ant.ProjectGet the project used for the tasks.getTasks()protected voidineritProperties(org.apache.tools.ant.PropertyHelper propertyHelper) booleanprotected voidonReset()Allow sub classes to do something on reset.protected voidonStop()Allow sub classes to do something on stop.voidsetBaseDir(File baseDir) voidsetClassLoader(ClassLoader classLoader) voidsetClassPath(String classPath) voidsetException(boolean exception) voidsetMessageLevel(String messageLevel) voidsetOutput(OutputStream out) voidsetProject(org.apache.tools.ant.Project project) Set the project to use for the tasks.voidMethods inherited from class org.oddjob.framework.extend.SimpleJob
fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onDestroy, run, sleep, softReset, stateHandler, stopMethods inherited from class org.oddjob.framework.extend.BasePrimary
configure, getName, logger, logger, loggerName, save, setName, toStringMethods inherited from class org.oddjob.framework.extend.BaseComponent
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSessionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
-
Constructor Details
-
AntJob
public AntJob()
-
-
Method Details
-
setOutput
-
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
-
getMessageLevel
-
execute
Execute the tasks. -
onStop
protected void onStop()Description copied from class:SimpleJobAllow sub classes to do something on stop. -
onReset
protected void onReset()Description copied from class:SimpleJobAllow sub classes to do something on reset. -
ineritProperties
protected void ineritProperties(org.apache.tools.ant.PropertyHelper propertyHelper) -
buildAntClassLoader
- Throws:
IOException
-
isException
public boolean isException() -
setException
public void setException(boolean exception) -
getBaseDir
-
setBaseDir
-
getTasks
-
setTasks
-
getClassLoader
-
setClassLoader
-
getVersion
- Returns:
- The ant version or nothing if the job hasn't run yet.
- Reference Property:
- version
Description
The ant version. -
getClassPath
-
setClassPath
-