From df102bb3a3c66a6497d780fed807527a865cf864 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 5 Oct 2009 04:04:31 +0000 Subject: [PATCH] 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 --- .../org/apache/tools/ant/PropertyHelper.java | 41 +++++++++++++++---- src/main/org/apache/tools/ant/Target.java | 8 +--- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/org/apache/tools/ant/PropertyHelper.java b/src/main/org/apache/tools/ant/PropertyHelper.java index 67a27ff92..cb01f5342 100644 --- a/src/main/org/apache/tools/ant/PropertyHelper.java +++ b/src/main/org/apache/tools/ant/PropertyHelper.java @@ -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); + } } diff --git a/src/main/org/apache/tools/ant/Target.java b/src/main/org/apache/tools/ant/Target.java index 66bb5a97a..28ac04aea 100644 --- a/src/main/org/apache/tools/ant/Target.java +++ b/src/main/org/apache/tools/ant/Target.java @@ -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); } }