AntTF

Run an Apache Ant script.

Task package:org.apache.ant
Java package:org.schmant.task.apache.ant
Category:Execution tasks
Since:0.5
EntityFS-aware?No*
Implements:ActionTaskFactory

Description:

This task runs an Apache Ant script in its own process.

The script to run may be a complete Ant script, the body of an Ant script or a single target. See the source property.

Required properties

Properties

argumentstop

Arguments to the Ant launcher (ant or ant.bat). The arguments will be given to the program in the order that they are added.

Setter method:
addArgument(String arg)
Add one program argument.
parameters:
arg – The program argument, for instance -nice 10.
Setter method:
addArguments(Object o)
Add one program argument or an array or a collection of program arguments.
parameters:
o – A program argument or an array or collection of program arguments (strings).
Setter method:
clearArguments()
Clear the list of program arguments.
emacsLoggingtop

Ant's Emacs logging property.

Setter method:
setEmacsLogging(boolean b)
parameters:
b – Enable Emacs logging?
Default value:
Off
environmentVariablestop

Environment variables for the program. By default, the variables set are added to the environment of the Schmant script. See the inheritEnvironmentVariables property.

Setter method:
addEnvironmentVariable(String name, String value)
parameters:
name – The environment variable name, for instance PATH.
value – The value of the variable.
Setter method:
addEnvironmentVariables(Object o)
Add one or several environment variables.
parameters:
o – A string or an array or collection of strings. Each string must have the format NAME=VALUE.
Setter method:
clearEnvironmentVariables()
Clear the collection of environment variables.
See also:
inheritEnvironmentVariables
failOnErrorstop

If the program exits with an error (an exit code != 0), should the task fail? See also ErrorIgnoringTF.

Setter method:
setFailOnErrors(boolean b)
parameters:
b – Should the task fail on errors?
Default value:
true (fails on errors)
inheritEnvironmentVariablestop

Should the environment variables of the Schmant script be inherited?

Setter method:
setInheritEnvironmentVariables(boolean b)
parameters:
b – Should environment variables be inherited?
Default value:
true (environment variables are inherited)
See also:
environmentVariables
keepGoingtop

Ant's keep going property. (Should Ant keep going if a task fails?)

Setter method:
setKeepGoing(boolean b)
parameters:
b – Keep going?
Default value:
false
libPathDecoratorstop

A list of PathDecorator:s that are used to create paths where Ant will search for Jars and classes to add to its classpath. The path entries derived from this property are added to the library path after the entries from the libPathEntries property.

This corresponds to Ant's -lib option.

Setter method:
addLibPathDecorator(PathDecorator pd)
Add one library path decorator.
parameters:
pd – A path decorator.
Setter method:
addLibPathDecorators(Object o)
Add one or several library path decorators.
parameters:
o – A library path decorator or an array or collection of library path decorators (PathDecorator objects).
Setter method:
clearLibPathDecorators()
Clear the list of library path decorators.
See also:
libPathEntries
libPathEntriestop

A list of paths where Ant will search for Jars and classes to add to its classpath. The path entries added to this property are added to the library path before the entries derived from the libPathDecorators property.

This corresponds to Ant's -lib option.

Setter method:
addLibPathEntries(Object o)
Add one or several library path entries.
parameters:
o – One or several library path entries.
Interpreted by InterpretAsFileStrategy.
Setter method:
addLibPathEntry(Object o)
Add one or several library path entries.
parameters:
o – One or several library path entries.
Interpreted by InterpretAsFileStrategy.
Setter method:
clearLibPathEntries()
Clear the list of library path entries.
See also:
libPathDecorators
logFiletop

A file to log the output from Ant to.

Setter method:
setLogFile(Object f)
parameters:
f – The log file.
Interpreted by InterpretAsFileStrategy.
Default value:
Log to stdout and stderr.
logFootertop

The message that is logged to info level after the task has been successfully run.

Setter method:
setLogFooter(String s)
parameters:
s – The footer message.
Default value:
Empty (no footer message is logged.)
See also:
logHeader
logHeadertop

The message that is logged to info level before the task is run.

Setter method:
setLogHeader(String s)
parameters:
s – The header message.
Default value:
A task class specific message.
See also:
logFooter
logLeveltop

Ant's log level.

Setter method:
setLogLevel(AntLogLevel l)
parameters:
l – The log level.
noUserLibtop

Ant's noUserLib property.

Setter method:
setNoUserLib(boolean b)
parameters:
b – Set noUserLib?
propertiestop

A map of Ant properties for the script.

Setter method:
addProperties(Map<String, String> m)
Add a map of properties.
parameters:
m – The property map.
Setter method:
addProperty(String name, String value)
Add one property.
parameters:
name – The property name.
value – The property value.
Setter method:
clearProperties()
Clear the property map.
propertyFiletop

A property file, used by Ant.

Setter method:
setPropertyFile(Object o)
parameters:
o – The property file.
Interpreted by InterpretAsFileStrategy.
reportLeveltop

This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.

Setter method:
setReportLevel(Level l)
Set the report level
parameters:
l – The new report level.
source (required)top

The Ant script to run. The basedir for the script, if it is not set in the script, will be set to the directory of the Schmant script.

Setter method:
setSource(Object o)
Set a script.
parameters:
o – The script.
Interpreted by InterpretAsFileStrategy.
Setter method:
setSourceBody(String s)
Set the script body, i.e. the contents of the project tag. The project tag sets the default target doit.
parameters:
s – The script body.
Setter method:
setSourceTargetBody(String s)
Set the body of a script target. This is convenient to use when the script should have only one target.
parameters:
s – The script target body.
stderrStrategytop

A ProcessOutputStrategy for handling the program's output to stderr.

Setter method:
setStderrStrategy(ProcessOutputStrategy s)
parameters:
s – The stderr strategy.
Default value:
A LoggingProcessOutputStrategy that logs output to the Level.SEVERE
See also:
stdoutStrategy
stdoutStrategytop

A ProcessOutputStrategy for handling the program's output to stdout.

Setter method:
setStdoutStrategy(ProcessOutputStrategy s)
parameters:
s – The stdout strategy.
Default value:
A LoggingProcessOutputStrategy that logs output to the Level.INFO
See also:
stderrStrategy
targetstop

The targets to run in the Ant script. The targets will be run in the order that they are added.

Setter method:
addTarget(String name)
Add one target.
parameters:
name – A target.
Setter method:
addTargets(Object o)
Add one target or an array or collection of targets.
parameters:
o – A target or an array or collection of targets (strings).
Setter method:
clearTargets()
Clear the list of targets.
Default value:
Not set. (Run the script's default target.)
traceLoggingtop

If trace logging is enabled for a task, it reports its configuration before it is run.

Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).

Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.
parameters:
b – Enable trace logging?
workingDirectorytop

The working directory for the program. (The directory that the program is started in.)

Setter method:
setWorkingDirectory(Object o)
parameters:
o – A directory.
Interpreted by InterpretAsFileDirectoryStrategy.
Default value:
The Schmant process' working directory. The Schmant launcher scripts sets this to the directory where the current script file is.

Examples

Example 1

Run the Ant script in the file f. f may be a Java File or an EntityFS EFile.

// Enable the task package in the script header // enableTaskPackage org.apache.ant import org.schmant.task.apache.ant.AntTF new AntTF(). setSource(f).run()

Example 2

Run an inline script that prints out the contents of the variable s.

enableTaskPackage("org.apache.ant"); new AntTF(). setSource( new CharSequenceReadableFile( "<project name=\"my_project\" default=\"prints\">\n" + "<target name=\"prints\">\n" + " <echo>" + s + "</echo>\n" + "</target>\n" + "</project>")).run();

Example 3

Run an inline script (using setSourceBody) that prints out the contents of the variable s.

enableTaskPackage("org.apache.ant"); new AntTF(). setSourceBody( "<target name=\"doit\">\n" + " <echo>" + s + "</echo>\n" + "</target>").run();

Example 4

Run an inline script (using setSourceTargetBody) that prints out the contents of the variable s.

enableTaskPackage("org.apache.ant"); new AntTF(). setSourceTargetBody("<echo>" + s + "</echo>").run();

Example 5

Run an inline script (using setSourceTargetBody) that prints out the contents of the variable s. The variable s is assigned to the property s in the Ant script.

enableTaskPackage("org.apache.ant"); new AntTF(). setSourceTargetBody("<echo>${s}</echo>"). addProperty("s", s).run();


* That a task is not EntityFS-aware means that it is not aware of DirectoryView filters (it uses them as plain Directory:s) and also that it usually requires that the entities it takes as arguments are in a File-based file file system. (That they are ECFileResolvable.) A non File-resolvable entity can be made so by using the SchmantFileSystems.makeFileResolvable(org.entityfs.EFile) method.