Browse Source

fmt/refac

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@556981 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 18 years ago
parent
commit
f18d3adfa8
1 changed files with 22 additions and 29 deletions
  1. +22
    -29
      src/main/org/apache/tools/ant/Target.java

+ 22
- 29
src/main/org/apache/tools/ant/Target.java View File

@@ -15,7 +15,6 @@
* limitations under the License. * limitations under the License.
* *
*/ */

package org.apache.tools.ant; package org.apache.tools.ant;


import java.util.ArrayList; import java.util.ArrayList;
@@ -26,8 +25,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;


import org.apache.tools.ant.util.CollectionUtils;

/** /**
* Class to implement a target object with required parameters. * Class to implement a target object with required parameters.
* *
@@ -36,14 +33,19 @@ public class Target implements TaskContainer {


/** Name of this target. */ /** Name of this target. */
private String name; private String name;

/** The "if" condition to test on execution. */ /** The "if" condition to test on execution. */
private String ifCondition = ""; private String ifCondition = "";

/** The "unless" condition to test on execution. */ /** The "unless" condition to test on execution. */
private String unlessCondition = ""; private String unlessCondition = "";

/** List of targets this target is dependent on. */ /** List of targets this target is dependent on. */
private List dependencies = null; private List dependencies = null;

/** Children of this target (tasks and data types). */ /** Children of this target (tasks and data types). */
private List children = new ArrayList(); private List children = new ArrayList();

/** Since Ant 1.6.2 */ /** Since Ant 1.6.2 */
private Location location = Location.UNKNOWN_LOCATION; private Location location = Location.UNKNOWN_LOCATION;


@@ -130,9 +132,8 @@ public class Target implements TaskContainer {


// Make sure the dependency is not empty string // Make sure the dependency is not empty string
if ("".equals(token) || ",".equals(token)) { if ("".equals(token) || ",".equals(token)) {
throw new BuildException("Syntax Error: depends "
+ "attribute of target \"" + getName()
+ "\" has an empty string as dependency.");
throw new BuildException("Syntax Error: depends " + "attribute of target \""
+ getName() + "\" has an empty string as dependency.");
} }


addDependency(token); addDependency(token);
@@ -143,8 +144,8 @@ public class Target implements TaskContainer {
token = tok.nextToken(); token = tok.nextToken();
if (!tok.hasMoreTokens() || !",".equals(token)) { if (!tok.hasMoreTokens() || !",".equals(token)) {
throw new BuildException("Syntax Error: Depend " throw new BuildException("Syntax Error: Depend "
+ "attribute for target \"" + getName()
+ "\" ends with a , character");
+ "attribute for target \"" + getName()
+ "\" ends with a , character");
} }
} }
} }
@@ -203,7 +204,6 @@ public class Target implements TaskContainer {
tasks.add(o); tasks.add(o);
} }
} }

return (Task[]) tasks.toArray(new Task[tasks.size()]); return (Task[]) tasks.toArray(new Task[tasks.size()]);
} }


@@ -226,8 +226,8 @@ public class Target implements TaskContainer {
* @return an enumeration of the dependencies of this target * @return an enumeration of the dependencies of this target
*/ */
public Enumeration getDependencies() { public Enumeration getDependencies() {
return (dependencies != null ? Collections.enumeration(dependencies)
: new CollectionUtils.EmptyEnumeration());
return Collections
.enumeration(dependencies == null ? Collections.EMPTY_LIST : dependencies);
} }


/** /**
@@ -238,9 +238,8 @@ public class Target implements TaskContainer {
*/ */
public boolean dependsOn(String other) { public boolean dependsOn(String other) {
Project p = getProject(); Project p = getProject();
Hashtable t = (p == null) ? null : p.getTargets();
return (p != null
&& p.topoSort(getName(), t, false).contains(t.get(other)));
Hashtable t = p == null ? null : p.getTargets();
return p != null && p.topoSort(getName(), t, false).contains(t.get(other));
} }


/** /**
@@ -257,7 +256,7 @@ public class Target implements TaskContainer {
* no "if" test is performed. * no "if" test is performed.
*/ */
public void setIf(String property) { public void setIf(String property) {
ifCondition = (property == null) ? "" : property;
ifCondition = property == null ? "" : property;
} }


/** /**
@@ -268,7 +267,7 @@ public class Target implements TaskContainer {
* @since 1.6.2 * @since 1.6.2
*/ */
public String getIf() { public String getIf() {
return ("".equals(ifCondition) ? null : ifCondition);
return "".equals(ifCondition) ? null : ifCondition;
} }


/** /**
@@ -285,7 +284,7 @@ public class Target implements TaskContainer {
* no "unless" test is performed. * no "unless" test is performed.
*/ */
public void setUnless(String property) { public void setUnless(String property) {
unlessCondition = (property == null) ? "" : property;
unlessCondition = property == null ? "" : property;
} }


/** /**
@@ -296,7 +295,7 @@ public class Target implements TaskContainer {
* @since 1.6.2 * @since 1.6.2
*/ */
public String getUnless() { public String getUnless() {
return ("".equals(unlessCondition) ? null : unlessCondition);
return "".equals(unlessCondition) ? null : unlessCondition;
} }


/** /**
@@ -348,26 +347,21 @@ public class Target implements TaskContainer {
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
if (testIfCondition() && testUnlessCondition()) { if (testIfCondition() && testUnlessCondition()) {
for (int taskPosition = 0;
taskPosition < children.size();
++taskPosition) {
for (int taskPosition = 0; taskPosition < children.size(); ++taskPosition) {
Object o = children.get(taskPosition); Object o = children.get(taskPosition);
if (o instanceof Task) { if (o instanceof Task) {
Task task = (Task) o; Task task = (Task) o;
task.perform(); task.perform();
} else { } else {
RuntimeConfigurable r = (RuntimeConfigurable) o;
r.maybeConfigure(project);
((RuntimeConfigurable) o).maybeConfigure(project);
} }
} }
} else if (!testIfCondition()) { } else if (!testIfCondition()) {
project.log(this, "Skipped because property '"
+ project.replaceProperties(ifCondition)
+ "' not set.", Project.MSG_VERBOSE);
project.log(this, "Skipped because property '" + project.replaceProperties(ifCondition)
+ "' not set.", Project.MSG_VERBOSE);
} else { } else {
project.log(this, "Skipped because property '" project.log(this, "Skipped because property '"
+ project.replaceProperties(unlessCondition)
+ "' set.", Project.MSG_VERBOSE);
+ project.replaceProperties(unlessCondition) + "' set.", Project.MSG_VERBOSE);
} }
} }


@@ -434,7 +428,6 @@ public class Target implements TaskContainer {
if ("".equals(ifCondition)) { if ("".equals(ifCondition)) {
return true; return true;
} }

String test = project.replaceProperties(ifCondition); String test = project.replaceProperties(ifCondition);
return project.getProperty(test) != null; return project.getProperty(test) != null;
} }


Loading…
Cancel
Save