Browse Source

Move "don't check conditions if the attribute hasn't been set at all" logic

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@821675 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
df102bb3a3
2 changed files with 35 additions and 14 deletions
  1. +34
    -7
      src/main/org/apache/tools/ant/PropertyHelper.java
  2. +1
    -7
      src/main/org/apache/tools/ant/Target.java

+ 34
- 7
src/main/org/apache/tools/ant/PropertyHelper.java View File

@@ -1141,19 +1141,46 @@ public class PropertyHelper implements GetProperty {
}

/**
* Returns true if the value is not-null, can be interpreted as a
* true value or cannot be interpreted as a false value and a
* property of the value's name exists.
* Returns true if the object is null or an empty string.
*
* @since Ant 1.8.0
*/
public boolean testIfCondition(Object value) {
if (value == null) {
return false;
}
private static boolean nullOrEmpty(Object value) {
return value == null || "".equals(value);

}

/**
* Returns true if the value can be interpreted as a true value or
* cannot be interpreted as a false value and a property of the
* value's name exists.
* @since Ant 1.8.0
*/
private boolean evalAsBooleanOrPropertyName(Object value) {
Boolean b = toBoolean(value);
if (b != null) {
return b.booleanValue();
}
return getProperty(String.valueOf(value)) != null;
}

/**
* Returns true if the value is null or an empty string, can be
* interpreted as a true value or cannot be interpreted as a false
* value and a property of the value's name exists.
* @since Ant 1.8.0
*/
public boolean testIfCondition(Object value) {
return nullOrEmpty(value) || evalAsBooleanOrPropertyName(value);
}

/**
* Returns true if the value is null or an empty string, can be
* interpreted as a false value or cannot be interpreted as a true
* value and a property of the value's name doesn't exist.
* @since Ant 1.8.0
*/
public boolean testUnlessCondition(Object value) {
return nullOrEmpty(value) || !evalAsBooleanOrPropertyName(value);
}
}

+ 1
- 7
src/main/org/apache/tools/ant/Target.java View File

@@ -457,9 +457,6 @@ public class Target implements TaskContainer {
* @see #setIf(String)
*/
private boolean testIfAllows() {
if ("".equals(ifCondition)) {
return true;
}
PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
Object o = propertyHelper.parseProperties(ifCondition);
return propertyHelper.testIfCondition(o);
@@ -475,11 +472,8 @@ public class Target implements TaskContainer {
* @see #setUnless(String)
*/
private boolean testUnlessAllows() {
if ("".equals(unlessCondition)) {
return true;
}
PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(getProject());
Object o = propertyHelper.parseProperties(unlessCondition);
return !propertyHelper.testIfCondition(o);
return propertyHelper.testUnlessCondition(o);
}
}

Loading…
Cancel
Save