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

public Class Ant

extends Task
Class Inheritance
Imports
java.io.File, .IOException, .PrintStream, java.lang.reflect.Method, java.nio.file.Files, java.util.HashMap, .HashSet, .List, .Map, .Objects, .Set, .Vector, org.apache.tools.ant.BuildException, .DefaultLogger, .MagicNames, .Main, .Project, .ProjectComponent, .ProjectHelper, .Target, .Task, org.apache.tools.ant.types.PropertySet, org.apache.tools.ant.util.FileUtils, .VectorSet

Build a sub-project.
 <target name="foo" depends="init">
   <ant antfile="build.xml" target="bar" >
     <property name="property1" value="aaaaa" />
     <property name="foo" value="baz" />
   </ant>
 </target>

 <target name="bar" depends="init">
   <echo message="prop is ${property1} ${foo}" />
 </target>
Since
Ant 1.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
public static class
Ant.Reference

Helper class that implements the nested <reference> element of <ant> and <antcall>.

public static class
Ant.TargetElement

Helper class that implements the nested <target> element of <ant> and <antcall>.

Field Summary

Modifier and TypeField and Description
private String
antFile

the build.xml file (can be absolute) in this case dir will be ignored

private File
dir

the basedir where is executed the build file

private static final FileUtils
private boolean
inheritAll

should we inherit properties from the parent ?

private boolean
inheritRefs

should we inherit references from the parent ?

private Project
newProject

the temporary project created to run the build file

private PrintStream
out

The stream to which output is to be written.

private String
output

the output

private List<Property>
properties

the properties to pass to the new project

private List<PropertySet>
propertySets

the sets of properties to pass to the new project

private List<Ant.Reference>
references

the references to pass to the new project

private boolean
targetAttributeSet

whether the target attribute was specified

private List<String>
targets

the targets to call on the new project

private boolean
useNativeBasedir

Whether the basedir of the new project should be the same one as it would be when running the build file directly - independent of dir and/or inheritAll settings.

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

Constructor Summary

AccessConstructor and Description
public
Ant()

simple constructor

public
Ant(Task
owning task
owner
)

create a task bound to its creator

Method Summary

Modifier and TypeMethod and Description
private void
addAlmostAll(Map<?, ?>
properties Hashtable to copy to the new project.
props
,
Ant.PropertyType
the type of property to set (a plain Ant property, a user property or an inherited property).
type
)

Copies all properties from the given table to the new project - omitting those that have already been set in the new project as well as properties named basedir or ant.file.

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

Add a target to this Ant invocation.

public void
addPropertyset(PropertySet
PropertySet to add.
ps
)

Add a set of properties to pass to the new project.

public void
addReference(Ant.Reference
Reference to add.
ref
)

Add a Reference element identifying a data type to carry over to the new project.

private void
addReferences()

Add the references explicitly defined as nested elements to the new project.

private void
copyReference(String
the reference id in the current project.
oldKey
,
String
the reference id in the new project.
newKey
)

Try to clone and reconfigure the object referenced by oldkey in the parent project and add it to the new project with the key newkey.

public Property

Returns:

the created Property object.
createProperty
()

Property to pass to the new project.

public void
execute()

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

Do the execution.
protected String

Returns:

the name of the default file
getDefaultBuildFile
()

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

protected Project

Returns:

Project
getNewProject
()

Get the (sub)-Project instance currently in use.

public void
handleErrorFlush(String
The string to output.
errorOutputToFlush
)

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

Handle error output.
public void
handleErrorOutput(String
The string to output.
errorOutputToHandle
)

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

Handle error output.
public void
handleFlush(String
The string to output.
toFlush
)

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

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

Handles input.
public void
handleOutput(String
The string output to output.
outputToHandle
)

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

Handles output.
public void
init()

Overrides org.apache.tools.ant.Task.init.

Creates a Project instance for the project to call.
private void
initializeProject()

Attaches the build listeners of the current project to the new project, configures a possible logfile, transfers task and data-type definitions, transfers properties (either all or just the ones specified as user properties to the current project, depending on inheritall), transfers the input handler.

private void
overrideProperties()

Override the properties in the new project with the one explicitly defined as nested elements here.

private void
reinit()

Called in execute or createProperty (via getNewProject()) if newProject is null.

public void
setAntfile(String
the String build file name.
antFile
)

The build file to use.

public void
setDir(File
new directory as File.
dir
)

The directory to use as a base directory for the new Ant project.

public void
setInheritAll(boolean
if true pass all properties to the new Ant project.
value
)

If true, pass all properties to the new Ant project.

public void
setInheritRefs(boolean
if true, pass all references to the new Ant project
value
)

If true, pass all references to the new Ant project.

public void
setOutput(String
the name of the file to which the output should go.
outputFile
)

Set the filename to write the output to.

public void
setTarget(String
the name of the target to invoke.
targetToAdd
)

The target of the new Ant project to execute.

public void
setUseNativeBasedir(boolean
boolean
b
)

Whether the basedir of the new project should be the same one as it would be when running the build file directly - independent of dir and/or inheritAll settings.

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

Field Detail

antFileback to summary
private String antFile

the build.xml file (can be absolute) in this case dir will be ignored

dirback to summary
private File dir

the basedir where is executed the build file

FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
inheritAllback to summary
private boolean inheritAll

should we inherit properties from the parent ?

inheritRefsback to summary
private boolean inheritRefs

should we inherit references from the parent ?

newProjectback to summary
private Project newProject

the temporary project created to run the build file

outback to summary
private PrintStream out

The stream to which output is to be written.

outputback to summary
private String output

the output

propertiesback to summary
private List<Property> properties

the properties to pass to the new project

propertySetsback to summary
private List<PropertySet> propertySets

the sets of properties to pass to the new project

referencesback to summary
private List<Ant.Reference> references

the references to pass to the new project

targetAttributeSetback to summary
private boolean targetAttributeSet

whether the target attribute was specified

targetsback to summary
private List<String> targets

the targets to call on the new project

useNativeBasedirback to summary
private boolean useNativeBasedir

Whether the basedir of the new project should be the same one as it would be when running the build file directly - independent of dir and/or inheritAll settings.

Since
Ant 1.8.0

Constructor Detail

Antback to summary
public Ant()

simple constructor

Antback to summary
public Ant(Task owner)

create a task bound to its creator

Parameters
owner:Task

owning task

Method Detail

addAlmostAllback to summary
private void addAlmostAll(Map<?, ?> props, Ant.PropertyType type)

Copies all properties from the given table to the new project - omitting those that have already been set in the new project as well as properties named basedir or ant.file.

Parameters
props:Map<?, ?>

properties Hashtable to copy to the new project.

type:Ant.PropertyType

the type of property to set (a plain Ant property, a user property or an inherited property).

Since
Ant 1.8.0
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.6.3
addPropertysetback to summary
public void addPropertyset(PropertySet ps)

Add a set of properties to pass to the new project.

Parameters
ps:PropertySet

PropertySet to add.

Since
Ant 1.6
addReferenceback to summary
public void addReference(Ant.Reference ref)

Add a Reference element identifying a data type to carry over to the new project.

Parameters
ref:Ant.Reference

Reference to add.

addReferencesback to summary
private void addReferences() throws BuildException

Add the references explicitly defined as nested elements to the new project. Also copy over all references that don't override existing references in the new project if inheritrefs has been requested.

Exceptions
BuildException:
if a reference does not have a refid.
copyReferenceback to summary
private void copyReference(String oldKey, String newKey)

Try to clone and reconfigure the object referenced by oldkey in the parent project and add it to the new project with the key newkey.

If we cannot clone it, copy the referenced object itself and keep our fingers crossed.

Parameters
oldKey:String

the reference id in the current project.

newKey:String

the reference id in the new project.

createPropertyback to summary
public Property createProperty()

Property to pass to the new project. The property is passed as a 'user property'.

Returns:Property

the created Property object.

executeback to summary
public void execute() throws BuildException

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

Do the execution.

Annotations
@Override
Exceptions
BuildException:
if a target tries to call itself; probably also if a BuildException is thrown by the new project.
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 easily implement their sublauncher.

Returns:String

the name of the default file

Since
Ant 1.8.0
getNewProjectback to summary
protected Project getNewProject()

Get the (sub)-Project instance currently in use.

Returns:Project

Project

Since
Ant 1.7
handleErrorFlushback to summary
public void handleErrorFlush(String errorOutputToFlush)

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

Handle error output. Send it the the new project if is present, otherwise call the super class.

Parameters
errorOutputToFlush:String

The string to output.

Annotations
@Override
Since
Ant 1.5.2
See Also
Task#handleErrorFlush(String)
handleErrorOutputback to summary
public void handleErrorOutput(String errorOutputToHandle)

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

Handle error output. Send it the the new project if is present, otherwise call the super class.

Parameters
errorOutputToHandle:String

The string to output.

Annotations
@Override
Since
Ant 1.5
See Also
Task#handleErrorOutput(String)
handleFlushback to summary
public void handleFlush(String toFlush)

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

Handles output. Send it the the new project if is present, otherwise call the super class.

Parameters
toFlush:String

The string to output.

Annotations
@Override
Since
Ant 1.5.2
See Also
Task#handleFlush(String)
handleInputback to summary
public int handleInput(byte[] buffer, int offset, int length) throws IOException

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

Handles input. Delegate to the created project, if present, otherwise call the super class.

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
See Also
Task#handleInput(byte[], int, int)
handleOutputback to summary
public void handleOutput(String outputToHandle)

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

Handles output. Send it the the new project if is present, otherwise call the super class.

Parameters
outputToHandle:String

The string output to output.

Annotations
@Override
Since
Ant 1.5
See Also
Task#handleOutput(String)
initback to summary
public void init()

Overrides org.apache.tools.ant.Task.init.

Creates a Project instance for the project to call.

Annotations
@Override
initializeProjectback to summary
private void initializeProject()

Attaches the build listeners of the current project to the new project, configures a possible logfile, transfers task and data-type definitions, transfers properties (either all or just the ones specified as user properties to the current project, depending on inheritall), transfers the input handler.

overridePropertiesback to summary
private void overrideProperties() throws BuildException

Override the properties in the new project with the one explicitly defined as nested elements here.

Exceptions
BuildException:
under unknown circumstances.
reinitback to summary
private void reinit()

Called in execute or createProperty (via getNewProject()) if newProject is null.

This can happen if the same instance of this task is run twice as newProject is set to null at the end of execute (to save memory and help the GC).

calls init() again

setAntfileback to summary
public void setAntfile(String antFile)

The build file to use. Defaults to "build.xml". This file is expected to be a filename relative to the dir attribute given.

Parameters
antFile:String

the String build file name.

setDirback to summary
public void setDir(File dir)

The directory to use as a base directory for the new Ant project. Defaults to the current project's basedir, unless inheritall has been set to false, in which case it doesn't have a default value. This will override the basedir setting of the called project.

Parameters
dir:File

new directory as File.

setInheritAllback to summary
public void setInheritAll(boolean value)

If true, pass all properties to the new Ant project. Defaults to true.

Parameters
value:boolean

if true pass all properties to the new Ant project.

setInheritRefsback to summary
public void setInheritRefs(boolean value)

If true, pass all references to the new Ant project. Defaults to false.

Parameters
value:boolean

if true, pass all references to the new Ant project

setOutputback to summary
public void setOutput(String outputFile)

Set the filename to write the output to. This is relative to the value of the dir attribute if it has been set or to the base directory of the current project otherwise.

Parameters
outputFile:String

the name of the file to which the output should go.

setTargetback to summary
public void setTarget(String targetToAdd)

The target of the new Ant project to execute. Defaults to the new project's default target.

Parameters
targetToAdd:String

the name of the target to invoke.

setUseNativeBasedirback to summary
public void setUseNativeBasedir(boolean b)

Whether the basedir of the new project should be the same one as it would be when running the build file directly - independent of dir and/or inheritAll settings.

Parameters
b:boolean

boolean

Since
Ant 1.8.0
org.apache.tools.ant.taskdefs back to summary

private final Enum Ant.PropertyType

extends Enum<Ant.PropertyType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Ant.PropertyType
public static final Ant.PropertyType
public static final Ant.PropertyType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Ant.PropertyType
public static Ant.PropertyType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INHERITEDback to summary
public static final Ant.PropertyType INHERITED
PLAINback to summary
public static final Ant.PropertyType PLAIN
USERback to summary
public static final Ant.PropertyType USER

Constructor Detail

PropertyTypeback to summary
private PropertyType()

Method Detail

valueOfback to summary
public static Ant.PropertyType valueOf(String name)
valuesback to summary
public static Ant.PropertyType[] values()
org.apache.tools.ant.taskdefs back to summary

public Class Ant.Reference

extends Reference
Class Inheritance
Annotations
@SuppressWarnings:deprecation

Helper class that implements the nested <reference> element of <ant> and <antcall>.

Field Summary

Modifier and TypeField and Description
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the id of the reference in the new project.
getToRefid
()

Get the id under which this reference will be stored in the new project.

public void
setToRefid(String
the id under which this reference will be passed to the new project.
targetid
)

Set the id that this reference to be stored under in the new project.

Inherited from org.apache.tools.ant.types.Reference:
getProjectgetReferencedObjectgetReferencedObjectgetRefIdsetProjectsetRefId

Field Detail

targetidback to summary
private String targetid

Constructor Detail

Referenceback to summary
public Reference()

Method Detail

getToRefidback to summary
public String getToRefid()

Get the id under which this reference will be stored in the new project.

Returns:String

the id of the reference in the new project.

setToRefidback to summary
public void setToRefid(String targetid)

Set the id that this reference to be stored under in the new project.

Parameters
targetid:String

the id under which this reference will be passed to the new project.

org.apache.tools.ant.taskdefs back to summary

public Class Ant.TargetElement

extends Object
Class Inheritance

Helper class that implements the nested <target> element of <ant> and <antcall>.
Since
Ant 1.6.3

Field Summary

Modifier and TypeField and Description
private String

Constructor Summary

AccessConstructor and Description
public
TargetElement()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

String.
getName
()

Get the name of this TargetElement.

public void
setName(String
the String target name.
name
)

Set the name of this TargetElement.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
private String name

Constructor Detail

TargetElementback to summary
public TargetElement()

Default constructor.

Method Detail

getNameback to summary
public String getName()

Get the name of this TargetElement.

Returns:String

String.

setNameback to summary
public void setName(String name)

Set the name of this TargetElement.

Parameters
name:String

the String target name.