diff --git a/src/main/org/apache/tools/ant/PropertyHelper.java b/src/main/org/apache/tools/ant/PropertyHelper.java
index c436657e9..67a27ff92 100644
--- a/src/main/org/apache/tools/ant/PropertyHelper.java
+++ b/src/main/org/apache/tools/ant/PropertyHelper.java
@@ -1117,4 +1117,43 @@ public class PropertyHelper implements GetProperty {
return result;
}
+ /**
+ * If the given object can be interpreted as a true/false value,
+ * turn it into a matching Boolean - otherwise return null.
+ * @since Ant 1.8.0
+ */
+ public static Boolean toBoolean(Object value) {
+ if (value instanceof Boolean) {
+ return (Boolean) value;
+ }
+ if (value instanceof String) {
+ String s = (String) value;
+ if (Project.toBoolean(s)) {
+ return Boolean.TRUE;
+ }
+ if ("off".equalsIgnoreCase(s)
+ || "false".equalsIgnoreCase(s)
+ || "no".equalsIgnoreCase(s)) {
+ return Boolean.FALSE;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 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.
+ * @since Ant 1.8.0
+ */
+ public boolean testIfCondition(Object value) {
+ if (value == null) {
+ return false;
+ }
+ Boolean b = toBoolean(value);
+ if (b != null) {
+ return b.booleanValue();
+ }
+ return getProperty(String.valueOf(value)) != null;
+ }
}
diff --git a/src/main/org/apache/tools/ant/Target.java b/src/main/org/apache/tools/ant/Target.java
index f92369e35..66bb5a97a 100644
--- a/src/main/org/apache/tools/ant/Target.java
+++ b/src/main/org/apache/tools/ant/Target.java
@@ -462,10 +462,7 @@ public class Target implements TaskContainer {
}
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;
+ return propertyHelper.testIfCondition(o);
}
/**
@@ -483,9 +480,6 @@ public class Target implements TaskContainer {
}
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;
+ return !propertyHelper.testIfCondition(o);
}
}
diff --git a/src/tests/antunit/core/target-test-helper.xml b/src/tests/antunit/core/target-test-helper.xml
index 924577b66..6ca2452f1 100644
--- a/src/tests/antunit/core/target-test-helper.xml
+++ b/src/tests/antunit/core/target-test-helper.xml
@@ -33,7 +33,25 @@
unless-false called
+
+ if-string-true called
+
+
+
+ unless-string-true called
+
+
+
+ if-string-false called
+
+
+
+ unless-string-false called
+
+
+ depends="if-true,unless-true,if-false,unless-false,
+ if-string-true,unless-string-true,
+ if-string-false,unless-string-false"/>
diff --git a/src/tests/antunit/core/target-test.xml b/src/tests/antunit/core/target-test.xml
index 507a513b6..3e656be75 100644
--- a/src/tests/antunit/core/target-test.xml
+++ b/src/tests/antunit/core/target-test.xml
@@ -46,6 +46,10 @@ public class CreateBoolean extends ProjectComponent {
+
+
+
+
@@ -55,5 +59,24 @@ public class CreateBoolean extends ProjectComponent {
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+