Author: mbenson
Date: Wed Oct 29 09:27:00 2008
New Revision: 708930
URL: http://svn.apache.org/viewvc?rev=708930&view=rev
Log:
allow custom propertyhelpers to supply a Boolean for Target if/unless as an
alternative to specifying a property NAME
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/Target.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/Target.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Target.java?rev=708930&r1=708929&r2=708930&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Target.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Target.java Wed Oct 29
09:27:00 2008
@@ -347,30 +347,32 @@
* @see #setUnless(String)
*/
public void execute() throws BuildException {
- if (testIfCondition() && testUnlessCondition()) {
- LocalProperties localProperties
- = LocalProperties.get(getProject());
- localProperties.enterScope();
- try {
- 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) o).maybeConfigure(project);
- }
- }
- } finally {
- localProperties.exitScope();
- }
- } else if (!testIfCondition()) {
+ if (!testIfAllows()) {
project.log(this, "Skipped because property '" +
project.replaceProperties(ifCondition)
+ "' not set.", Project.MSG_VERBOSE);
- } else {
+ return;
+ }
+ if (!testUnlessAllows()) {
project.log(this, "Skipped because property '"
+ project.replaceProperties(unlessCondition) + "' set.",
Project.MSG_VERBOSE);
+ return;
+ }
+ LocalProperties localProperties = LocalProperties.get(getProject());
+ localProperties.enterScope();
+ try {
+ // use index-based approach to avoid
ConcurrentModificationExceptions;
+ // also account for growing target children
+ for (int i = 0; i < children.size(); i++) {
+ Object o = children.get(i);
+ if (o instanceof Task) {
+ Task task = (Task) o;
+ task.perform();
+ } else {
+ ((RuntimeConfigurable) o).maybeConfigure(project);
+ }
+ }
+ } finally {
+ localProperties.exitScope();
}
}
@@ -425,7 +427,7 @@
}
/**
- * Tests whether or not the "if" condition is satisfied.
+ * Tests whether or not the "if" condition allows the execution of this
target.
*
* @return whether or not the "if" condition is satisfied. If no
* condition (or an empty condition) has been set,
@@ -433,16 +435,20 @@
*
* @see #setIf(String)
*/
- private boolean testIfCondition() {
+ private boolean testIfAllows() {
if ("".equals(ifCondition)) {
return true;
}
- String test = project.replaceProperties(ifCondition);
- return project.getProperty(test) != null;
+ PropertyHelper propertyHelper =
PropertyHelper.getPropertyHelper(getProject());
+ Object o = propertyHelper.parseProperties(ifCondition);
+ if (o instanceof Boolean) {
+ return ((Boolean) o).booleanValue();
+ }
+ return propertyHelper.getProperty(String.valueOf(o)) != null;
}
/**
- * Tests whether or not the "unless" condition is satisfied.
+ * Tests whether or not the "unless" condition allows the execution of
this target.
*
* @return whether or not the "unless" condition is satisfied. If no
* condition (or an empty condition) has been set,
@@ -450,11 +456,15 @@
*
* @see #setUnless(String)
*/
- private boolean testUnlessCondition() {
+ private boolean testUnlessAllows() {
if ("".equals(unlessCondition)) {
return true;
}
- String test = project.replaceProperties(unlessCondition);
- return project.getProperty(test) == null;
+ PropertyHelper propertyHelper =
PropertyHelper.getPropertyHelper(getProject());
+ Object o = propertyHelper.parseProperties(unlessCondition);
+ if (o instanceof Boolean) {
+ return !((Boolean) o).booleanValue();
+ }
+ return propertyHelper.getProperty(String.valueOf(o)) == null;
}
}