ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r821847 - in /ant/core/trunk/src: main/org/apache/tools/ant/types/PatternSet.java main/org/apache/tools/ant/types/selectors/SelectSelector.java tests/antunit/types/patternset-test.xml tests/antunit/types/selectors/select-test.xml
Date Mon, 05 Oct 2009 15:29:42 GMT
Author: bodewig
Date: Mon Oct  5 15:29:42 2009
New Revision: 821847

URL: http://svn.apache.org/viewvc?rev=821847&view=rev
Log:
make select selector and include/exclude use the same logic as target for if/unless

Added:
    ant/core/trunk/src/tests/antunit/types/patternset-test.xml   (with props)
    ant/core/trunk/src/tests/antunit/types/selectors/select-test.xml   (with props)
Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/types/PatternSet.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/PatternSet.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/PatternSet.java?rev=821847&r1=821846&r2=821847&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/PatternSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/PatternSet.java Mon Oct  5 15:29:42
2009
@@ -26,6 +26,7 @@
 import java.util.Vector;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
 import org.apache.tools.ant.util.FileUtils;
 
 /**
@@ -44,12 +45,13 @@
     /**
      * inner class to hold a name on list.  "If" and "Unless" attributes
      * may be used to invalidate the entry based on the existence of a
-     * property (typically set thru the use of the Available task).
+     * property (typically set thru the use of the Available task)
+     * or value of an expression.
      */
     public class NameEntry {
         private String name;
-        private String ifCond;
-        private String unlessCond;
+        private Object ifCond;
+        private Object unlessCond;
 
         /**
          * Sets the name pattern.
@@ -62,29 +64,64 @@
 
         /**
          * Sets the if attribute. This attribute and the "unless"
-         * attribute are used to validate the name, based in the
-         * existence of the property.
+         * attribute are used to validate the name, based on the
+         * existence of the property or the value of the evaluated
+         * property expression.
          *
-         * @param cond A property name. If this property is not
-         *             present, the name is invalid.
+         * @param cond A property name or expression.  If the
+         *             expression evaluates to false or no property of
+         *             its value is present, the name is invalid.
+         * @since Ant 1.8.0
          */
-        public void setIf(String cond) {
+        public void setIf(Object cond) {
             ifCond = cond;
         }
 
         /**
+         * Sets the if attribute. This attribute and the "unless"
+         * attribute are used to validate the name, based on the
+         * existence of the property or the value of the evaluated
+         * property expression.
+         *
+         * @param cond A property name or expression.  If the
+         *             expression evaluates to false or no property of
+         *             its value is present, the name is invalid.
+         */
+        public void setIf(String cond) {
+            setIf((Object) cond);
+        }
+
+        /**
          * Sets the unless attribute. This attribute and the "if"
-         * attribute are used to validate the name, based in the
-         * existence of the property.
+         * attribute are used to validate the name, based on the
+         * existence of the property or the value of the evaluated
+         * property expression.
          *
-         * @param cond A property name. If this property is
-         *             present, the name is invalid.
+         * @param cond A property name or expression.  If the
+         *             expression evaluates to true or a property of
+         *             its value is present, the name is invalid.
+         * @param cond A property name or expression.
+         * @since Ant 1.8.0
          */
-        public void setUnless(String cond) {
+        public void setUnless(Object cond) {
             unlessCond = cond;
         }
 
         /**
+         * Sets the unless attribute. This attribute and the "if"
+         * attribute are used to validate the name, based on the
+         * existence of the property or the value of the evaluated
+         * property expression.
+         *
+         * @param cond A property name or expression.  If the
+         *             expression evaluates to true or a property of
+         *             its value is present, the name is invalid.
+         */
+        public void setUnless(String cond) {
+            setUnless((Object) cond);
+        }
+
+        /**
          * @return the name attribute.
          */
         public String getName() {
@@ -105,13 +142,9 @@
         }
 
         private boolean valid(Project p) {
-            if (ifCond != null && p.getProperty(ifCond) == null) {
-                return false;
-            }
-            if (unlessCond != null && p.getProperty(unlessCond) != null) {
-                return false;
-            }
-            return true;
+            PropertyHelper ph = PropertyHelper.getPropertyHelper(p);
+            return ph.testIfCondition(ifCond)
+                && ph.testUnlessCondition(unlessCond);
         }
 
         /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java?rev=821847&r1=821846&r2=821847&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/SelectSelector.java Mon Oct
 5 15:29:42 2009
@@ -22,6 +22,7 @@
 import java.io.File;
 
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
 
 /**
  * This selector just holds one other selector and forwards all
@@ -35,8 +36,8 @@
  */
 public class SelectSelector extends BaseSelectorContainer {
 
-    private String ifProperty;
-    private String unlessProperty;
+    private Object ifCondition;
+    private Object unlessCondition;
 
     /**
      * Default constructor.
@@ -51,13 +52,13 @@
         StringBuffer buf = new StringBuffer();
         if (hasSelectors()) {
             buf.append("{select");
-            if (ifProperty != null) {
+            if (ifCondition != null) {
                 buf.append(" if: ");
-                buf.append(ifProperty);
+                buf.append(ifCondition);
             }
-            if (unlessProperty != null) {
+            if (unlessCondition != null) {
                 buf.append(" unless: ");
-                buf.append(unlessProperty);
+                buf.append(unlessCondition);
             }
             buf.append(" ");
             buf.append(super.toString());
@@ -151,32 +152,51 @@
      * @return true if conditions are passed
      */
     public boolean passesConditions() {
-        if (ifProperty != null
-            && getProject().getProperty(ifProperty) == null) {
-            return false;
-        } else if (unlessProperty != null
-            && getProject().getProperty(unlessProperty) != null) {
-            return false;
-        }
-        return true;
+        PropertyHelper ph = PropertyHelper.getPropertyHelper(getProject());
+        return ph.testIfCondition(ifCondition)
+            && ph.testUnlessCondition(unlessCondition);
     }
 
     /**
-     * Sets the if attribute to a property which must exist for the
+     * Sets the if attribute to an expression which must evaluate to
+     * true or the name of an existing property for the
      * selector to select any files.
-     * @param ifProperty the property to check
+     * @param ifProperty the expression to check
+     * @since Ant 1.8.0
+     */
+    public void setIf(Object ifProperty) {
+        this.ifCondition = ifProperty;
+    }
+
+    /**
+     * Sets the if attribute to an expression which must evaluate to
+     * true or the name of an existing property for the
+     * selector to select any files.
+     * @param ifProperty the expression to check
      */
     public void setIf(String ifProperty) {
-        this.ifProperty = ifProperty;
+        setIf((Object) ifProperty);
+    }
+
+    /**
+     * Sets the unless attribute to an expression which must evaluate to
+     * false or the name of a property which cannot exist for the
+     * selector to select any files.
+     * @param unlessProperty the expression to check
+     * @since Ant 1.8.0
+     */
+    public void setUnless(Object unlessProperty) {
+        this.unlessCondition = unlessProperty;
     }
 
     /**
-     * Sets the unless attribute to a property which cannot exist for the
+     * Sets the unless attribute to an expression which must evaluate to
+     * false or the name of a property which cannot exist for the
      * selector to select any files.
-     * @param unlessProperty the property to check
+     * @param unlessProperty the expression to check
      */
     public void setUnless(String unlessProperty) {
-        this.unlessProperty = unlessProperty;
+        setUnless((Object) unlessProperty);
     }
 
     /**

Added: ant/core/trunk/src/tests/antunit/types/patternset-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/patternset-test.xml?rev=821847&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/patternset-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/patternset-test.xml Mon Oct  5 15:29:42 2009
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
+
+  <import file="../antunit-base.xml" />
+
+  <target name="setUp">
+    <mkdir dir="${input}"/>
+    <touch file="${input}/A"/>
+    <touch file="${input}/B"/>
+    <touch file="${input}/C"/>
+    <touch file="${input}/D"/>
+    <mkdir dir="${output}"/>
+    <macrodef name="cp">
+      <sequential>
+        <copy todir="${output}">
+          <fileset dir="${input}">
+            <include name="A" if="${if}"/>
+            <include name="B" unless="${if}"/>
+            <include name="C" if="if"/>
+            <include name="D" unless="if"/>
+          </fileset>
+        </copy>
+      </sequential>
+    </macrodef>
+  </target>
+
+  <target name="testIfNotSet" depends="setUp">
+    <cp/>
+    <au:assertFileDoesntExist file="${output}/A"/>
+    <au:assertFileExists file="${output}/B"/>
+    <au:assertFileDoesntExist file="${output}/C"/>
+    <au:assertFileExists file="${output}/D"/>
+  </target>
+
+  <target name="testIfSet" depends="setUp">
+    <property name="if" value="whatever"/>
+    <cp/>
+    <au:assertFileDoesntExist file="${output}/A"/>
+    <au:assertFileExists file="${output}/B"/>
+    <au:assertFileExists file="${output}/C"/>
+    <au:assertFileDoesntExist file="${output}/D"/>
+  </target>
+
+  <target name="testIfTrue" depends="setUp">
+    <property name="if" value="true"/>
+    <cp/>
+    <au:assertFileExists file="${output}/A"/>
+    <au:assertFileDoesntExist file="${output}/B"/>
+    <au:assertFileExists file="${output}/C"/>
+    <au:assertFileDoesntExist file="${output}/D"/>
+  </target>
+
+  <target name="testIfFalse" depends="setUp">
+    <property name="if" value="false"/>
+    <cp/>
+    <au:assertFileDoesntExist file="${output}/A"/>
+    <au:assertFileExists file="${output}/B"/>
+    <au:assertFileExists file="${output}/C"/>
+    <au:assertFileDoesntExist file="${output}/D"/>
+  </target>
+
+</project>

Propchange: ant/core/trunk/src/tests/antunit/types/patternset-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/core/trunk/src/tests/antunit/types/selectors/select-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/selectors/select-test.xml?rev=821847&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/selectors/select-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/selectors/select-test.xml Mon Oct  5 15:29:42 2009
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
+
+  <import file="../../antunit-base.xml" />
+
+  <target name="setUp">
+    <mkdir dir="${input}"/>
+    <touch file="${input}/A"/>
+    <touch file="${input}/B"/>
+    <touch file="${input}/C"/>
+    <touch file="${input}/D"/>
+    <mkdir dir="${output}"/>
+    <macrodef name="cp">
+      <sequential>
+        <copy todir="${output}">
+          <fileset dir="${input}">
+            <or>
+              <selector if="${if}">
+                <filename name="A"/>
+              </selector>
+              <selector unless="${if}">
+                <filename name="B"/>
+              </selector>
+              <selector if="if">
+                <filename name="C"/>
+              </selector>
+              <selector unless="if">
+                <filename name="D"/>
+              </selector>
+            </or>
+          </fileset>
+        </copy>
+      </sequential>
+    </macrodef>
+  </target>
+
+  <target name="testIfNotSet" depends="setUp">
+    <cp/>
+    <au:assertFileDoesntExist file="${output}/C"/>
+    <au:assertFileExists file="${output}/D"/>
+    <au:assertFileDoesntExist file="${output}/A"/>
+    <au:assertFileExists file="${output}/B"/>
+  </target>
+
+  <target name="testIfSet" depends="setUp">
+    <property name="if" value="whatever"/>
+    <cp/>
+    <au:assertFileDoesntExist file="${output}/A"/>
+    <au:assertFileExists file="${output}/B"/>
+    <au:assertFileExists file="${output}/C"/>
+    <au:assertFileDoesntExist file="${output}/D"/>
+  </target>
+
+  <target name="testIfTrue" depends="setUp">
+    <property name="if" value="true"/>
+    <cp/>
+    <au:assertFileExists file="${output}/A"/>
+    <au:assertFileDoesntExist file="${output}/B"/>
+    <au:assertFileExists file="${output}/C"/>
+    <au:assertFileDoesntExist file="${output}/D"/>
+  </target>
+
+  <target name="testIfFalse" depends="setUp">
+    <property name="if" value="false"/>
+    <cp/>
+    <au:assertFileDoesntExist file="${output}/A"/>
+    <au:assertFileExists file="${output}/B"/>
+    <au:assertFileExists file="${output}/C"/>
+    <au:assertFileDoesntExist file="${output}/D"/>
+  </target>
+
+</project>

Propchange: ant/core/trunk/src/tests/antunit/types/selectors/select-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message