Top Description Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class SubAnt

extends Task
Class Inheritance
Imports
java.io.File, .IOException, java.util.List, .Vector, org.apache.tools.ant.BuildException, .Main, .Project, .Task, org.apache.tools.ant.taskdefs.Ant.TargetElement, org.apache.tools.ant.types.DirSet, .FileList, .FileSet, .Path, .PropertySet, .Reference, .ResourceCollection, org.apache.tools.ant.util.StringUtils

Calls a given target for all defined sub-builds. This is an extension of ant for bulk project execution.

Use with directories

subant can be used with directory sets to execute a build from different directories. 2 different options are offered

Since
Ant1.6

Field Summary

Modifier and TypeField and Description
private Ant
private String
private Path
private boolean
private File
private boolean
private boolean
private String
private List<Property>
private List<PropertySet>
private List<Ant.Reference>
private String
private List<Ant.TargetElement>
targets

the targets to call on the new project

private boolean
Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(ResourceCollection
the resource collection to add.
rc
)

Adds a resource collection to the implicit build path.

public void
addConfiguredTarget(Ant.TargetElement
the TargetElement to add.
t
)

Add a target to this Ant invocation.

public void
addDirset(DirSet
the directory set to add.
set
)

Adds a directory set to the implicit build path.

public void
addFilelist(FileList
the file list to add.
list
)

Adds an ordered file list to the implicit build path.

public void
addFileset(FileSet
the file set to add.
set
)

Adds a file set to the implicit build path.

public void
addProperty(Property
the property to pass on explicitly to the sub-build.
p
)

Corresponds to <ant>'s nested <property> element.

public void
addPropertyset(PropertySet
the propertyset
ps
)

Corresponds to <ant>'s nested <propertyset> element.

public void
addReference(Ant.Reference
the reference to pass on explicitly to the sub-build.
r
)

Corresponds to <ant>'s nested <reference> element.

private static void
copyProperty(Property
the destination property whose content is modified.
to
,
Property
the source property whose content is copied.
from
)

Assigns an Ant property to another.

private Ant

Returns:

the ant task, configured with the explicit properties and references necessary to run the sub-build.
createAntTask
(File
: if not null the directory where the build should run
directory
)

Creates the <ant> task configured to run a specific target.

public Path

Returns:

the newly created nested build path.
createBuildpath
()

Creates a nested build path, and add it to the implicit build path.

public Path.PathElement

Returns:

the newly created nested build path element.
createBuildpathElement
()

Creates a nested <buildpathelement>, and add it to the implicit build path.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Runs the various sub-builds.
private void
execute(File
the build file to execute
file
,
File
the directory of the current iteration
directory
)

Runs the given target on the provided build file.

private Path

Returns:

the implicit build path.
getBuildpath
()

Gets the implicit build path, creating it if null.

protected String

Returns:

the name of the default file
getDefaultBuildFile
()

Get the default build file name to use when launching the task.

public void
handleErrorFlush(String
The error output to log. Should not be null.
output
)

Overrides org.apache.tools.ant.Task.handleErrorFlush.

Pass output sent to System.err to the new project.
public void
handleErrorOutput(String
The error output to log. Should not be null.
output
)

Overrides org.apache.tools.ant.Task.handleErrorOutput.

Pass output sent to System.err to the new project.
public void
handleFlush(String
The output to log. Should not be null.
output
)

Overrides org.apache.tools.ant.Task.handleFlush.

Pass output sent to System.out to the new project.
public int

Returns:

the number of bytes read
handleInput
(byte[]
the buffer into which data is to be read.
buffer
,
int
the offset into the buffer at which data is stored.
offset
,
int
the amount of data to read
length
)

Overrides org.apache.tools.ant.Task.handleInput.

Process input into the ant task
public void
handleOutput(String
a line of output
output
)

Overrides org.apache.tools.ant.Task.handleOutput.

Pass output sent to System.out to the new project.
private boolean
isHardError(Throwable t)

whether we should even try to continue after this error

public void
setAntfile(String
the short build file name. Defaults to "build.xml".
antfile
)

This method builds the file name to use in conjunction with directories.

public void
setBuildpath(Path
an Ant Path object containing the buildpath.
s
)

Set the buildpath to be used to find sub-projects.

public void
setBuildpathRef(Reference
a reference to an Ant Path object containing the buildpath.
r
)

Buildpath to use, by reference.

public void
setFailonerror(boolean
the new value for this boolean flag.
failOnError
)

Sets whether to fail with a build exception on error, or go on.

public void
setGenericAntfile(File
(path of the generic ant file, absolute or relative to project base directory)
afile
)

This method builds a file path to use in conjunction with directories.

public void
setInheritall(boolean
the new value for this boolean flag.
b
)

Corresponds to <ant>'s inheritall attribute.

public void
setInheritrefs(boolean
the new value for this boolean flag.
b
)

Corresponds to <ant>'s inheritrefs attribute.

public void
setOutput(String
the filename to write the output to.
s
)

Corresponds to <ant>'s output attribute.

public void
setTarget(String
the target
target
)

The target to call on the different sub-builds.

public void
setVerbose(boolean
true to enable verbose mode, false otherwise (default).
on
)

Enable/ disable verbose log messages showing when each sub-build path is entered/ exited.

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

antback to summary
private Ant ant
antfileback to summary
private String antfile
buildpathback to summary
private Path buildpath
failOnErrorback to summary
private boolean failOnError
genericantfileback to summary
private File genericantfile
inheritAllback to summary
private boolean inheritAll
inheritRefsback to summary
private boolean inheritRefs
outputback to summary
private String output
propertiesback to summary
private List<Property> properties
propertySetsback to summary
private List<PropertySet> propertySets
referencesback to summary
private List<Ant.Reference> references
subTargetback to summary
private String subTarget
targetsback to summary
private List<Ant.TargetElement> targets

the targets to call on the new project

verboseback to summary
private boolean verbose

Constructor Detail

SubAntback to summary
public SubAnt()

Method Detail

addback to summary
public void add(ResourceCollection rc)

Adds a resource collection to the implicit build path.

Parameters
rc:ResourceCollection

the resource collection to add.

Since
Ant 1.7
addConfiguredTargetback to summary
public void addConfiguredTarget(Ant.TargetElement t)

Add a target to this Ant invocation.

Parameters
t:Ant.TargetElement

the TargetElement to add.

Since
Ant 1.7
addDirsetback to summary
public void addDirset(DirSet set)

Adds a directory set to the implicit build path.

Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead!

Parameters
set:DirSet

the directory set to add.

addFilelistback to summary
public void addFilelist(FileList list)

Adds an ordered file list to the implicit build path.

Note that contrary to file and directory sets, file lists can reference non-existent files or directories!

Parameters
list:FileList

the file list to add.

addFilesetback to summary
public void addFileset(FileSet set)

Adds a file set to the implicit build path.

Note that the directories will be added to the build path in no particular order, so if order is significant, one should use a file list instead!

Parameters
set:FileSet

the file set to add.

addPropertyback to summary
public void addProperty(Property p)

Corresponds to <ant>'s nested <property> element.

Parameters
p:Property

the property to pass on explicitly to the sub-build.

addPropertysetback to summary
public void addPropertyset(PropertySet ps)

Corresponds to <ant>'s nested <propertyset> element.

Parameters
ps:PropertySet

the propertyset

addReferenceback to summary
public void addReference(Ant.Reference r)

Corresponds to <ant>'s nested <reference> element.

Parameters
r:Ant.Reference

the reference to pass on explicitly to the sub-build.

copyPropertyback to summary
private static void copyProperty(Property to, Property from)

Assigns an Ant property to another.

Parameters
to:Property

the destination property whose content is modified.

from:Property

the source property whose content is copied.

createAntTaskback to summary
private Ant createAntTask(File directory)

Creates the <ant> task configured to run a specific target.

Parameters
directory:File

: if not null the directory where the build should run

Returns:Ant

the ant task, configured with the explicit properties and references necessary to run the sub-build.

createBuildpathback to summary
public Path createBuildpath()

Creates a nested build path, and add it to the implicit build path.

Returns:Path

the newly created nested build path.

createBuildpathElementback to summary
public Path.PathElement createBuildpathElement()

Creates a nested <buildpathelement>, and add it to the implicit build path.

Returns:Path.PathElement

the newly created nested build path element.

executeback to summary
public void execute()

Overrides org.apache.tools.ant.Task.execute.

Runs the various sub-builds.

Annotations
@Override
executeback to summary
private void execute(File file, File directory) throws BuildException

Runs the given target on the provided build file.

Parameters
file:File

the build file to execute

directory:File

the directory of the current iteration

Exceptions
BuildException:
is the file cannot be found, read, is a directory, or the target called failed, but only if failOnError is true. Otherwise, a warning log message is simply output.
getBuildpathback to summary
private Path getBuildpath()

Gets the implicit build path, creating it if null.

Returns:Path

the implicit build path.

getDefaultBuildFileback to summary
protected String getDefaultBuildFile()

Get the default build file name to use when launching the task.

This function may be overridden by providers of custom ProjectHelper so they can implement easily their sub launcher.

Returns:String

the name of the default file

Since
Ant 1.8.0
handleErrorFlushback to summary
public void handleErrorFlush(String output)

Overrides org.apache.tools.ant.Task.handleErrorFlush.

Pass output sent to System.err to the new project.

Parameters
output:String

The error output to log. Should not be null.

Annotations
@Override
Since
Ant 1.6.2
handleErrorOutputback to summary
public void handleErrorOutput(String output)

Overrides org.apache.tools.ant.Task.handleErrorOutput.

Pass output sent to System.err to the new project.

Parameters
output:String

The error output to log. Should not be null.

Annotations
@Override
Since
Ant 1.6.2
handleFlushback to summary
public void handleFlush(String output)

Overrides org.apache.tools.ant.Task.handleFlush.

Pass output sent to System.out to the new project.

Parameters
output:String

The output to log. Should not be null.

Annotations
@Override
Since
Ant 1.6.2
handleInputback to summary
public int handleInput(byte[] buffer, int offset, int length) throws IOException

Overrides org.apache.tools.ant.Task.handleInput.

Process input into the ant task

Parameters
buffer:byte[]

the buffer into which data is to be read.

offset:int

the offset into the buffer at which data is stored.

length:int

the amount of data to read

Returns:int

the number of bytes read

Annotations
@Override
Exceptions
IOException:
if the data cannot be read
Since
Ant 1.6.2
See Also
Task#handleInput(byte[], int, int)
handleOutputback to summary
public void handleOutput(String output)

Overrides org.apache.tools.ant.Task.handleOutput.

Pass output sent to System.out to the new project.

Parameters
output:String

a line of output

Annotations
@Override
Since
Ant 1.6.2
isHardErrorback to summary
private boolean isHardError(Throwable t)

whether we should even try to continue after this error

setAntfileback to summary
public void setAntfile(String antfile)

This method builds the file name to use in conjunction with directories.

Defaults to "build.xml". If genericantfile is set, this attribute is ignored.

Parameters
antfile:String

the short build file name. Defaults to "build.xml".

setBuildpathback to summary
public void setBuildpath(Path s)

Set the buildpath to be used to find sub-projects.

Parameters
s:Path

an Ant Path object containing the buildpath.

setBuildpathRefback to summary
public void setBuildpathRef(Reference r)

Buildpath to use, by reference.

Parameters
r:Reference

a reference to an Ant Path object containing the buildpath.

setFailonerrorback to summary
public void setFailonerror(boolean failOnError)

Sets whether to fail with a build exception on error, or go on.

Parameters
failOnError:boolean

the new value for this boolean flag.

setGenericAntfileback to summary
public void setGenericAntfile(File afile)

This method builds a file path to use in conjunction with directories.

Use genericantfile, in order to run the same build file with different basedirs.

If this attribute is set, antfile is ignored.
Parameters
afile:File

(path of the generic ant file, absolute or relative to project base directory)

setInheritallback to summary
public void setInheritall(boolean b)

Corresponds to <ant>'s inheritall attribute.

Parameters
b:boolean

the new value for this boolean flag.

setInheritrefsback to summary
public void setInheritrefs(boolean b)

Corresponds to <ant>'s inheritrefs attribute.

Parameters
b:boolean

the new value for this boolean flag.

setOutputback to summary
public void setOutput(String s)

Corresponds to <ant>'s output attribute.

Parameters
s:String

the filename to write the output to.

setTargetback to summary
public void setTarget(String target)

The target to call on the different sub-builds. Set to "" to execute the default target.

Parameters
target:String

the target

setVerboseback to summary
public void setVerbose(boolean on)

Enable/ disable verbose log messages showing when each sub-build path is entered/ exited. The default value is "false".

Parameters
on:boolean

true to enable verbose mode, false otherwise (default).