ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r908513 - in /ant/antlibs/props/trunk: docs/index.html src/main/org/apache/ant/props/ConditionEvaluator.java src/tests/antunit/condition-test.xml
Date Wed, 10 Feb 2010 14:20:40 GMT
Author: bodewig
Date: Wed Feb 10 14:20:39 2010
New Revision: 908513

URL: http://svn.apache.org/viewvc?rev=908513&view=rev
Log:
minimal docs, a bit more tests, tiny optimization and better whitespace handling for the conditions
evaluator

Modified:
    ant/antlibs/props/trunk/docs/index.html
    ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
    ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml

Modified: ant/antlibs/props/trunk/docs/index.html
URL: http://svn.apache.org/viewvc/ant/antlibs/props/trunk/docs/index.html?rev=908513&r1=908512&r2=908513&view=diff
==============================================================================
--- ant/antlibs/props/trunk/docs/index.html (original)
+++ ant/antlibs/props/trunk/docs/index.html Wed Feb 10 14:20:39 2010
@@ -128,6 +128,18 @@
             then <code>(<em>arg</em>)</code>.</td>
       </tr>
       <tr>
+        <a name="conditions" />
+        <td align="center">types</td>
+        <td align="center">PropertyEvaluator</td>
+        <td>Given <code><em>condition</em>([<em>arg1=value1</em>,<em>arg2=value2</em>,...])</code>,
+            attempts to invoke an Ant condition of the given name
+            setting the given attibute values and evaluates to either
+            Boolean.TRUE or Boolean.FALSE.  Usage looks
+            like <em>${os(family=unix)}</em>.  This is probably most
+            useful together with the if/unless attributes of tasks or
+            targets.</td>
+      </tr>
+      <tr>
         <a name="encodeURL" />
         <td align="center">encodeURL</td>
         <td align="center">PropertyEvaluator</td>

Modified: ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
URL: http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java?rev=908513&r1=908512&r2=908513&view=diff
==============================================================================
--- ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java (original)
+++ ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java Wed Feb
10 14:20:39 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.ant.props;
 
+import java.util.regex.Pattern;
 import org.apache.tools.ant.ComponentHelper;
 import org.apache.tools.ant.IntrospectionHelper;
 import org.apache.tools.ant.Project;
@@ -31,6 +32,9 @@
  * for example <code>os(family=unix)</code>.
  */
 public class ConditionEvaluator extends RegexBasedEvaluator {
+    private static final Pattern COMMA = Pattern.compile(",");
+    private static final Pattern EQ = Pattern.compile("=");
+
     public ConditionEvaluator() {
         super("^(.+?)\\(((?:(?:.+?)=(?:.+?))?(?:,(?:.+?)=(?:.+?))*?)\\)$");
     }
@@ -44,10 +48,11 @@
             if (groups[2].length() > 0) {
                 IntrospectionHelper ih =
                     IntrospectionHelper.getHelper(instance.getClass());
-                String[] attributes = groups[2].split(",");
+                String[] attributes = COMMA.split(groups[2]);
                 for (int i = 0; i < attributes.length; i++) {
-                    String[] keyValue = attributes[i].split("=");
-                    ih.setAttribute(p, instance, keyValue[0], keyValue[1]);
+                    String[] keyValue = EQ.split(attributes[i]);
+                    ih.setAttribute(p, instance, keyValue[0].trim(),
+                                    keyValue[1].trim());
                 }
             }
             return Boolean.valueOf(cond.eval());

Modified: ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml?rev=908513&r1=908512&r2=908513&view=diff
==============================================================================
--- ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml (original)
+++ ant/antlibs/props/trunk/src/tests/antunit/condition-test.xml Wed Feb 10 14:20:39 2010
@@ -24,10 +24,41 @@
     </propertyhelper>
   </target>
 
-  <target name="testAvailable">
-    <au:assertEquals expected="true"
-                     actual="${available(classname=org.apache.ant.props.ConditionEvaluator)}"/>
-    <au:assertEquals expected="false"
-                     actual="${available(classname=org.apache.ant.props.ConditionEvaluatorFoo)}"/>
+  <target name="testAvailable"
+          depends="if-available,unless-available">
+    <au:assertLogContains text="true"/>
   </target>
+
+  <target name="if-available"
+          if="${available(classname=org.apache.ant.props.ConditionEvaluator)}">
+    <echo>true</echo>
+  </target>
+
+  <target name="unless-available"
+          unless="${available(classname=org.apache.ant.props.ConditionEvaluator)}">
+    <fail>org.apache.ant.props.ConditionEvaluator must be there</fail>
+  </target>
+
+  <target name="testTrueEquals" depends="set-prop,if-equals,unless-equals">
+    <au:assertLogContains text="equal"/>
+  </target>
+
+  <target name="set-prop">
+    <property name="foo" value="bar"/>
+  </target>
+
+  <target name="if-equals"
+          if="${equals(arg1=bar,arg2=${foo})}">
+    <echo>equal</echo>
+  </target>
+
+  <target name="unless-equals"
+          unless="${equals(arg1=bar,arg2=${foo})}">
+    <echo>not equal</echo>
+  </target>
+
+  <target name="testFalseEquals" depends="if-equals,unless-equals">
+    <au:assertLogContains text="not equal"/>
+  </target>
+
 </project>



Mime
View raw message