Return-Path: Delivered-To: apmail-ant-notifications-archive@locus.apache.org Received: (qmail 24599 invoked from network); 29 Oct 2008 16:27:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Oct 2008 16:27:52 -0000 Received: (qmail 59477 invoked by uid 500); 29 Oct 2008 16:27:57 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 59459 invoked by uid 500); 29 Oct 2008 16:27:57 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 59450 invoked by uid 99); 29 Oct 2008 16:27:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2008 09:27:57 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Oct 2008 16:26:51 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 898BA23888EB; Wed, 29 Oct 2008 09:27:01 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r708930 - /ant/core/trunk/src/main/org/apache/tools/ant/Target.java Date: Wed, 29 Oct 2008 16:27:01 -0000 To: notifications@ant.apache.org From: mbenson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081029162701.898BA23888EB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mbenson Date: Wed Oct 29 09:27:00 2008 New Revision: 708930 URL: http://svn.apache.org/viewvc?rev=708930&view=rev Log: allow custom propertyhelpers to supply a Boolean for Target if/unless as an alternative to specifying a property NAME Modified: ant/core/trunk/src/main/org/apache/tools/ant/Target.java 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=708930&r1=708929&r2=708930&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 Wed Oct 29 09:27:00 2008 @@ -347,30 +347,32 @@ * @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 @@ } /** - * 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 @@ * * @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 @@ * * @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; } }