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

public Class Target

extends Object
implements TaskContainer
Class Inheritance
All Implemented Interfaces
org.apache.tools.ant.TaskContainer
Known Direct Subclasses
org.apache.tools.ant.ExtensionPoint
Imports
java.util.ArrayList, .Collections, .Enumeration, .Hashtable, .List, .StringTokenizer, org.apache.tools.ant.property.LocalProperties, org.apache.tools.ant.taskdefs.condition.And, .Condition, .Or

Class to implement a target object with required parameters.

If you are creating Targets programmatically, make sure you set the Location to a useful value. In particular all targets should have different location values.

Field Summary

Modifier and TypeField and Description
private List<Object>
children

Children of this target (tasks and data types).

private List<String>
dependencies

List of targets this target is dependent on.

private String
description

Description of this target, if any.

private Condition
private String
ifString

The "if" condition to test on execution.

private Location
location

Since Ant 1.6.2

private String
name

Name of this target.

private Project
project

Project this target belongs to.

private Condition
private String
unlessString

The "unless" condition to test on execution.

Constructor Summary

AccessConstructor and Description
public
Target()

Default constructor.

public
Target(Target
the Target to clone.
other
)

Cloning constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addDataType(RuntimeConfigurable
The wrapper for the data type element to be added. Must not be null.
r
)

Adds the wrapper for a data type element to this target.

public void
addDependency(String
The name of a target this target is dependent on. Must not be null.
dependency
)

Adds a dependency to this target.

public void
addTask(Task
The task to be added. Must not be null.
task
)

Implements org.apache.tools.ant.TaskContainer.addTask.

Adds a task to this target.
public boolean

Returns:

true if the target does depend on the named target
dependsOn
(String
the other named target.
other
)

Does this target depend on the named target?

public void
execute()

Executes the target if the "if" and "unless" conditions are satisfied.

public Enumeration<String>

Returns:

an enumeration of the dependencies of this target (enumeration of String)
getDependencies
()

Returns an enumeration of the dependencies of this target.

public String

Returns:

the description of this target, or null if no description is available.
getDescription
()

Returns the description of this target.

public String

Returns:

the "if" property condition or null if no "if" condition had been defined.
getIf
()

Returns the "if" property condition of this target.

public Location

Returns:

Location
getLocation
()

Get the location of this target's definition.

public String

Returns:

the name of this target, or null if the name has not been set yet.
getName
()

Returns the name of this target.

public Project

Returns:

The project this target belongs to, or null if the project has not been set yet.
getProject
()

Returns the project this target belongs to.

public Task[]

Returns:

an array of the tasks currently within this target
getTasks
()

Returns the current set of tasks to be executed by this target.

public String

Returns:

the "unless" property condition or null if no "unless" condition had been defined.
getUnless
()

Returns the "unless" property condition of this target.

public static List<String>
parseDepends(String depends, String targetName, String attributeName)

public final void
performTasks()

Performs the tasks within this target (if the conditions are met), firing target started/target finished messages around a call to execute.

pack-priv void
replaceChild(Task
The task to replace. Must not be null.
el
,
RuntimeConfigurable
The data type wrapper to replace el with.
o
)

Replaces all occurrences of the given task in the list of children with the replacement data type wrapper.

pack-priv void
replaceChild(Task
The task to replace. Must not be null.
el
,
Task
The task to replace el with.
o
)

Replaces all occurrences of the given task in the list of children with the replacement task.

public void
setDepends(String
A comma-separated list of targets this target depends on. Must not be null.
depS
)

Sets the list of targets this target is dependent on.

public void
setDescription(String
The description for this target. May be null, indicating that no description is available.
description
)

Sets the description of this target.

public void
setIf(String
The property condition to test on execution. May be null, in which case no "if" test is performed.
property
)

Sets the "if" condition to test on execution.

public void
setIf(Condition
Condition
condition
)

Same as setIf(String) but requires a Condition instance

public void
setLocation(Location
Location
location
)

Sets the location of this target's definition.

public void
setName(String
The name of this target. Should not be null.
name
)

Sets the name of this target.

public void
setProject(Project
The project this target belongs to. Must not be null.
project
)

Sets the project this target belongs to.

public void
setUnless(String
The property condition to test on execution. May be null, in which case no "unless" test is performed.
property
)

Sets the "unless" condition to test on execution.

public void
setUnless(Condition
Condition
condition
)

Same as setUnless(String) but requires a Condition instance

public String

Returns:

the name of this target, or null if the name has not been set yet.
toString
()

Overrides java.lang.Object.toString.

Returns the name of this target.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

childrenback to summary
private List<Object> children

Children of this target (tasks and data types).

dependenciesback to summary
private List<String> dependencies

List of targets this target is dependent on.

descriptionback to summary
private String description

Description of this target, if any.

ifConditionback to summary
private Condition ifCondition
ifStringback to summary
private String ifString

The "if" condition to test on execution.

locationback to summary
private Location location

Since Ant 1.6.2

nameback to summary
private String name

Name of this target.

projectback to summary
private Project project

Project this target belongs to.

unlessConditionback to summary
private Condition unlessCondition
unlessStringback to summary
private String unlessString

The "unless" condition to test on execution.

Constructor Detail

Targetback to summary
public Target()

Default constructor.

Targetback to summary
public Target(Target other)

Cloning constructor.

Parameters
other:Target

the Target to clone.

Method Detail

addDataTypeback to summary
public void addDataType(RuntimeConfigurable r)

Adds the wrapper for a data type element to this target.

Parameters
r:RuntimeConfigurable

The wrapper for the data type element to be added. Must not be null.

addDependencyback to summary
public void addDependency(String dependency)

Adds a dependency to this target.

Parameters
dependency:String

The name of a target this target is dependent on. Must not be null.

addTaskback to summary
public void addTask(Task task)

Implements org.apache.tools.ant.TaskContainer.addTask.

Adds a task to this target.

Parameters
task:Task

The task to be added. Must not be null.

dependsOnback to summary
public boolean dependsOn(String other)

Does this target depend on the named target?

Parameters
other:String

the other named target.

Returns:boolean

true if the target does depend on the named target

Since
Ant 1.6
executeback to summary
public void execute() throws BuildException

Executes the target if the "if" and "unless" conditions are satisfied. Dependency checking should be done before calling this method, as it does no checking of its own. If either the "if" or "unless" test prevents this target from being executed, a verbose message is logged giving the reason. It is recommended that clients of this class call performTasks rather than this method so that appropriate build events are fired.

Exceptions
BuildException:
if any of the tasks fail or if a data type configuration fails.
See Also
performTasks(), setIf(String), setUnless(String)
getDependenciesback to summary
public Enumeration<String> getDependencies()

Returns an enumeration of the dependencies of this target.

Returns:Enumeration<String>

an enumeration of the dependencies of this target (enumeration of String)

getDescriptionback to summary
public String getDescription()

Returns the description of this target.

Returns:String

the description of this target, or null if no description is available.

getIfback to summary
public String getIf()

Returns the "if" property condition of this target.

Returns:String

the "if" property condition or null if no "if" condition had been defined.

Since
1.6.2
getLocationback to summary
public Location getLocation()

Get the location of this target's definition.

Returns:Location

Location

Since
1.6.2
getNameback to summary
public String getName()

Returns the name of this target.

Returns:String

the name of this target, or null if the name has not been set yet.

getProjectback to summary
public Project getProject()

Returns the project this target belongs to.

Returns:Project

The project this target belongs to, or null if the project has not been set yet.

getTasksback to summary
public Task[] getTasks()

Returns the current set of tasks to be executed by this target.

Returns:Task[]

an array of the tasks currently within this target

getUnlessback to summary
public String getUnless()

Returns the "unless" property condition of this target.

Returns:String

the "unless" property condition or null if no "unless" condition had been defined.

Since
1.6.2
parseDependsback to summary
public static List<String> parseDepends(String depends, String targetName, String attributeName)
performTasksback to summary
public final void performTasks()

Performs the tasks within this target (if the conditions are met), firing target started/target finished messages around a call to execute.

See Also
execute()
replaceChildback to summary
pack-priv void replaceChild(Task el, RuntimeConfigurable o)

Replaces all occurrences of the given task in the list of children with the replacement data type wrapper.

Parameters
el:Task

The task to replace. Must not be null.

o:RuntimeConfigurable

The data type wrapper to replace el with.

replaceChildback to summary
pack-priv void replaceChild(Task el, Task o)

Replaces all occurrences of the given task in the list of children with the replacement task.

Parameters
el:Task

The task to replace. Must not be null.

o:Task

The task to replace el with.

setDependsback to summary
public void setDepends(String depS)

Sets the list of targets this target is dependent on. The targets themselves are not resolved at this time.

Parameters
depS:String

A comma-separated list of targets this target depends on. Must not be null.

setDescriptionback to summary
public void setDescription(String description)

Sets the description of this target.

Parameters
description:String

The description for this target. May be null, indicating that no description is available.

setIfback to summary
public void setIf(String property)

Sets the "if" condition to test on execution. This is the name of a property to test for existence - if the property is not set, the task will not execute. The property goes through property substitution once before testing, so if property foo has value bar, setting the "if" condition to ${foo}_x will mean that the task will only execute if property bar_x is set.

Parameters
property:String

The property condition to test on execution. May be null, in which case no "if" test is performed.

setIfback to summary
public void setIf(Condition condition)

Same as setIf(String) but requires a Condition instance

Parameters
condition:Condition

Condition

Since
1.9
setLocationback to summary
public void setLocation(Location location)

Sets the location of this target's definition.

Parameters
location:Location

Location

Since
1.6.2
setNameback to summary
public void setName(String name)

Sets the name of this target.

Parameters
name:String

The name of this target. Should not be null.

setProjectback to summary
public void setProject(Project project)

Sets the project this target belongs to.

Parameters
project:Project

The project this target belongs to. Must not be null.

setUnlessback to summary
public void setUnless(String property)

Sets the "unless" condition to test on execution. This is the name of a property to test for existence - if the property is set, the task will not execute. The property goes through property substitution once before testing, so if property foo has value bar, setting the "unless" condition to ${foo}_x will mean that the task will only execute if property bar_x isn't set.

Parameters
property:String

The property condition to test on execution. May be null, in which case no "unless" test is performed.

setUnlessback to summary
public void setUnless(Condition condition)

Same as setUnless(String) but requires a Condition instance

Parameters
condition:Condition

Condition

Since
1.9
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns the name of this target.

Returns:String

the name of this target, or null if the name has not been set yet.

Annotations
@Override