From 18681d7fc981b944ed3768a168ddd44898692175 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Wed, 29 Oct 2008 16:27:00 +0000 Subject: [PATCH] allow custom propertyhelpers to supply a Boolean for Target if/unless as an alternative to specifying a property NAME git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@708930 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/Target.java | 66 +++++++++++++---------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/main/org/apache/tools/ant/Target.java b/src/main/org/apache/tools/ant/Target.java index 4cf060560..19fda5767 100644 --- a/src/main/org/apache/tools/ant/Target.java +++ b/src/main/org/apache/tools/ant/Target.java @@ -347,30 +347,32 @@ public class Target implements TaskContainer { * @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 @@ public class Target implements TaskContainer { } /** - * 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 @@ public class Target implements TaskContainer { * * @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 @@ public class Target implements TaskContainer { * * @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; } }