Author: bodewig
Date: Mon Oct 5 04:04:31 2009
New Revision: 821675
URL: http://svn.apache.org/viewvc?rev=821675&view=rev
Log:
Move "don't check conditions if the attribute hasn't been set at all" logic
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java
ant/core/trunk/src/main/org/apache/tools/ant/Target.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java?rev=821675&r1=821674&r2=821675&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/PropertyHelper.java Mon Oct 5
04:04:31 2009
@@ -1141,19 +1141,46 @@
}
/**
- * 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);
+ }
}
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=821675&r1=821674&r2=821675&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 Mon Oct 5
04:04:31 2009
@@ -457,9 +457,6 @@
* @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 @@
* @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);
}
}