Class to implement a target object with required parameters.
| Method from org.apache.tools.ant.Target Detail: |
public void addDataType(RuntimeConfigurable r) {
children.add(r);
}
Adds the wrapper for a data type element to this target. |
public void addDependency(String dependency) {
if (dependencies == null) {
dependencies = new ArrayList(2);
}
dependencies.add(dependency);
}
Adds a dependency to this target. |
public void addTask(Task task) {
children.add(task);
}
Adds a task to this target. |
public boolean dependsOn(String other) {
Project p = getProject();
Hashtable t = (p == null) ? null : p.getTargets();
return (p != null
&& p.topoSort(getName(), t, false).contains(t.get(other)));
}
Does this target depend on the named target? |
public void execute() throws BuildException {
if (testIfCondition() && testUnlessCondition()) {
for (int taskPosition = 0;
taskPosition < children.size();
++taskPosition) {
Object o = children.get(taskPosition);
if (o instanceof Task) {
Task task = (Task) o;
task.perform();
} else {
RuntimeConfigurable r = (RuntimeConfigurable) o;
r.maybeConfigure(project);
}
}
} else if (!testIfCondition()) {
project.log(this, "Skipped because property '"
+ project.replaceProperties(ifCondition)
+ "' not set.", Project.MSG_VERBOSE);
} else {
project.log(this, "Skipped because property '"
+ project.replaceProperties(unlessCondition)
+ "' set.", Project.MSG_VERBOSE);
}
}
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. |
public Enumeration getDependencies() {
return (dependencies != null ? Collections.enumeration(dependencies)
: new CollectionUtils.EmptyEnumeration());
}
Returns an enumeration of the dependencies of this target. |
public String getDescription() {
return description;
}
Returns the description of this target. |
public String getIf() {
return ("".equals(ifCondition) ? null : ifCondition);
}
Returns the "if" property condition of this target. |
public Location getLocation() {
return location;
}
Get the location of this target's definition. |
public String getName() {
return name;
}
Returns the name of this target. |
public Project getProject() {
return project;
}
Returns the project this target belongs to. |
public Task[] getTasks() {
List tasks = new ArrayList(children.size());
Iterator it = children.iterator();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof Task) {
tasks.add(o);
}
}
return (Task[]) tasks.toArray(new Task[tasks.size()]);
}
Returns the current set of tasks to be executed by this target. |
public String getUnless() {
return ("".equals(unlessCondition) ? null : unlessCondition);
}
Returns the "unless" property condition of this target. |
public final void performTasks() {
RuntimeException thrown = null;
project.fireTargetStarted(this);
try {
execute();
} catch (RuntimeException exc) {
thrown = exc;
throw exc;
} finally {
project.fireTargetFinished(this, thrown);
}
}
Performs the tasks within this target (if the conditions are met),
firing target started/target finished messages around a call to
execute. |
void replaceChild(Task el,
RuntimeConfigurable o) {
int index;
while ((index = children.indexOf(el)) >= 0) {
children.set(index, o);
}
}
Replaces all occurrences of the given task in the list
of children with the replacement data type wrapper. |
void replaceChild(Task el,
Task o) {
int index;
while ((index = children.indexOf(el)) >= 0) {
children.set(index, o);
}
}
Replaces all occurrences of the given task in the list
of children with the replacement task. |
public void setDepends(String depS) {
if (depS.length() > 0) {
StringTokenizer tok =
new StringTokenizer(depS, ",", true);
while (tok.hasMoreTokens()) {
String token = tok.nextToken().trim();
// Make sure the dependency is not empty string
if ("".equals(token) || ",".equals(token)) {
throw new BuildException("Syntax Error: depends "
+ "attribute of target \"" + getName()
+ "\" has an empty string as dependency.");
}
addDependency(token);
// Make sure that depends attribute does not
// end in a ,
if (tok.hasMoreTokens()) {
token = tok.nextToken();
if (!tok.hasMoreTokens() || !",".equals(token)) {
throw new BuildException("Syntax Error: Depend "
+ "attribute for target \"" + getName()
+ "\" ends with a , character");
}
}
}
}
}
Sets the list of targets this target is dependent on.
The targets themselves are not resolved at this time. |
public void setDescription(String description) {
this.description = description;
}
Sets the description of this target. |
public void setIf(String property) {
ifCondition = (property == null) ? "" : 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. |
public void setLocation(Location location) {
this.location = location;
}
Sets the location of this target's definition. |
public void setName(String name) {
this.name = name;
}
Sets the name of this target. |
public void setProject(Project project) {
this.project = project;
}
Sets the project this target belongs to. |
public void setUnless(String property) {
unlessCondition = (property == null) ? "" : 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. |
public String toString() {
return name;
}
Returns the name of this target. |