Package org.apache.tools.ant
Class Target
java.lang.Object
org.apache.tools.ant.Target
- All Implemented Interfaces:
TaskContainer
- Direct Known Subclasses:
ExtensionPoint
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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the wrapper for a data type element to this target.void
addDependency
(String dependency) Adds a dependency to this target.void
Adds a task to this target.boolean
Does this target depend on the named target?void
execute()
Executes the target if the "if" and "unless" conditions are satisfied.Returns an enumeration of the dependencies of this target.Returns the description of this target.getIf()
Returns the "if" property condition of this target.Get the location of this target's definition.getName()
Returns the name of this target.Returns the project this target belongs to.Task[]
getTasks()
Returns the current set of tasks to be executed by this target.Returns the "unless" property condition of this target.parseDepends
(String depends, String targetName, String attributeName) final void
Performs the tasks within this target (if the conditions are met), firing target started/target finished messages around a call to execute.void
setDepends
(String depS) Sets the list of targets this target is dependent on.void
setDescription
(String description) Sets the description of this target.void
Sets the "if" condition to test on execution.void
Same assetIf(String)
but requires aCondition
instancevoid
setLocation
(Location location) Sets the location of this target's definition.void
Sets the name of this target.void
setProject
(Project project) Sets the project this target belongs to.void
Sets the "unless" condition to test on execution.void
Same assetUnless(String)
but requires aCondition
instancetoString()
Returns the name of this target.
-
Constructor Details
-
Target
public Target()Default constructor. -
Target
-
-
Method Details
-
setProject
Sets the project this target belongs to.- Parameters:
project
- The project this target belongs to. Must not benull
.
-
getProject
Returns the project this target belongs to.- Returns:
- The project this target belongs to, or
null
if the project has not been set yet.
-
setLocation
Sets the location of this target's definition.- Parameters:
location
-Location
- Since:
- 1.6.2
-
getLocation
Get the location of this target's definition.- Returns:
Location
- Since:
- 1.6.2
-
setDepends
Sets the list of targets this target is dependent on. The targets themselves are not resolved at this time.- Parameters:
depS
- A comma-separated list of targets this target depends on. Must not benull
.
-
parseDepends
-
setName
Sets the name of this target.- Parameters:
name
- The name of this target. Should not benull
.
-
getName
Returns the name of this target.- Returns:
- the name of this target, or
null
if the name has not been set yet.
-
addTask
Adds a task to this target.- Specified by:
addTask
in interfaceTaskContainer
- Parameters:
task
- The task to be added. Must not benull
.
-
addDataType
Adds the wrapper for a data type element to this target.- Parameters:
r
- The wrapper for the data type element to be added. Must not benull
.
-
getTasks
Returns the current set of tasks to be executed by this target.- Returns:
- an array of the tasks currently within this target
-
addDependency
Adds a dependency to this target.- Parameters:
dependency
- The name of a target this target is dependent on. Must not benull
.
-
getDependencies
Returns an enumeration of the dependencies of this target.- Returns:
- an enumeration of the dependencies of this target (enumeration of String)
-
dependsOn
Does this target depend on the named target?- Parameters:
other
- the other named target.- Returns:
- true if the target does depend on the named target
- Since:
- Ant 1.6
-
setIf
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 propertyfoo
has valuebar
, setting the "if" condition to${foo}_x
will mean that the task will only execute if propertybar_x
is set.- Parameters:
property
- The property condition to test on execution. May benull
, in which case no "if" test is performed.
-
getIf
Returns the "if" property condition of this target.- Returns:
- the "if" property condition or
null
if no "if" condition had been defined. - Since:
- 1.6.2
-
setIf
Same assetIf(String)
but requires aCondition
instance- Parameters:
condition
- Condition- Since:
- 1.9
-
setUnless
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 propertyfoo
has valuebar
, setting the "unless" condition to${foo}_x
will mean that the task will only execute if propertybar_x
isn't set.- Parameters:
property
- The property condition to test on execution. May benull
, in which case no "unless" test is performed.
-
getUnless
Returns the "unless" property condition of this target.- Returns:
- the "unless" property condition or
null
if no "unless" condition had been defined. - Since:
- 1.6.2
-
setUnless
Same assetUnless(String)
but requires aCondition
instance- Parameters:
condition
- Condition- Since:
- 1.9
-
setDescription
Sets the description of this target.- Parameters:
description
- The description for this target. May benull
, indicating that no description is available.
-
getDescription
Returns the description of this target.- Returns:
- the description of this target, or
null
if no description is available.
-
toString
-
execute
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.- Throws:
BuildException
- if any of the tasks fail or if a data type configuration fails.- See Also:
-
performTasks
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:
-