ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r822118 - in /ant/core/trunk/src: main/org/apache/tools/ant/taskdefs/XSLTProcess.java tests/antunit/taskdefs/xslt-test.xml
Date Tue, 06 Oct 2009 04:30:38 GMT
Author: bodewig
Date: Tue Oct  6 04:30:37 2009
New Revision: 822118

URL: http://svn.apache.org/viewvc?rev=822118&view=rev
Log:
use the same logic as target for xslt's param element's if/unless attribute

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
    ant/core/trunk/src/tests/antunit/taskdefs/xslt-test.xml

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java?rev=822118&r1=822117&r2=822118&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java Tue Oct  6 04:30:37
2009
@@ -26,6 +26,7 @@
 import org.apache.tools.ant.DirectoryScanner;
 import org.apache.tools.ant.DynamicConfigurator;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
 import org.apache.tools.ant.types.CommandlineJava;
 import org.apache.tools.ant.types.Environment;
 import org.apache.tools.ant.types.Mapper;
@@ -947,8 +948,8 @@
         /** The parameter's value */
         private String expression = null;
 
-        private String ifProperty;
-        private String unlessProperty;
+        private Object ifCond;
+        private Object unlessCond;
         private Project project;
 
         /**
@@ -1005,22 +1006,45 @@
         }
 
         /**
-         * Set whether this param should be used.  It will be
-         * used if the property has been set, otherwise it won't.
-         * @param ifProperty name of property
+         * Set whether this param should be used.  It will be used if
+         * the expression evalutes to true or the name of a property
+         * which has been set, otherwise it won't.
+         * @param ifCond evaluated expression
+         * @since Ant 1.8.0
+         */
+        public void setIf(Object ifCond) {
+            this.ifCond = ifCond;
+        }
+
+        /**
+         * Set whether this param should be used.  It will be used if
+         * the expression evalutes to true or the name of a property
+         * which has been set, otherwise it won't.
+         * @param ifProperty evaluated expression
          */
         public void setIf(String ifProperty) {
-            this.ifProperty = ifProperty;
+            setIf((Object) ifProperty);
+        }
+
+        /**
+         * Set whether this param should NOT be used. It will not be
+         * used if the expression evaluates to true or the name of a
+         * property which has been set, otherwise it will be used.
+         * @param unlessCond evaluated expression
+         * @since Ant 1.8.0
+         */
+        public void setUnless(Object unlessCond) {
+            this.unlessCond = unlessCond;
         }
 
         /**
-         * Set whether this param should NOT be used. It
-         * will not be used if the property has been set, otherwise it
-         * will be used.
-         * @param unlessProperty name of property
+         * Set whether this param should NOT be used. It will not be
+         * used if the expression evaluates to true or the name of a
+         * property which has been set, otherwise it will be used.
+         * @param unlessProperty evaluated expression
          */
         public void setUnless(String unlessProperty) {
-            this.unlessProperty = unlessProperty;
+            setUnless((Object) unlessProperty);
         }
 
         /**
@@ -1029,13 +1053,9 @@
          * @return true if the task passes the "if" and "unless" parameters
          */
         public boolean shouldUse() {
-            if (ifProperty != null && project.getProperty(ifProperty) == null) {
-                return false;
-            }
-            if (unlessProperty != null && project.getProperty(unlessProperty) !=
null) {
-                return false;
-            }
-            return true;
+            PropertyHelper ph = PropertyHelper.getPropertyHelper(project);
+            return ph.testIfCondition(ifCond)
+                && ph.testUnlessCondition(unlessCond);
         }
     } // Param
 

Modified: ant/core/trunk/src/tests/antunit/taskdefs/xslt-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/xslt-test.xml?rev=822118&r1=822117&r2=822118&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/xslt-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/xslt-test.xml Tue Oct  6 04:30:37 2009
@@ -170,4 +170,52 @@
     <au:assertLogDoesntContain text="Failed to enable tracing"/>
   </target>
 
+  <target name="setUpIfUnlessTests" depends="setUp">
+    <macrodef name="xs">
+      <sequential>
+        <xslt in="${legacy.dir}/data.xml" out="${output}/out.xml"
+              style="${legacy.dir}/printParams.xsl">
+          <param name="set" expression="if-value" if="${if}"/>
+          <param name="set" expression="unless-value" unless="${if}"/>
+          <param name="empty" expression="if-value" if="if"/>
+          <param name="empty" expression="unless-value" unless="if"/>
+        </xslt>
+      </sequential>
+    </macrodef>
+  </target>
+
+  <target name="testPropertiesNotSet" depends="setUpIfUnlessTests">
+    <xs/>
+    <au:assertResourceContains resource="${output}/out.xml"
+                               value="set='unless-value'"/>
+    <au:assertResourceContains resource="${output}/out.xml"
+                               value="empty='unless-value'"/>
+  </target>
+
+  <target name="testPropertiesSet" depends="setUpIfUnlessTests">
+    <property name="if" value="whatever"/>
+    <xs/>
+    <au:assertResourceContains resource="${output}/out.xml"
+                               value="set='unless-value'"/>
+    <au:assertResourceContains resource="${output}/out.xml"
+                               value="empty='if-value'"/>
+  </target>
+
+  <target name="testIfTrue" depends="setUpIfUnlessTests">
+    <property name="if" value="true"/>
+    <xs/>
+    <au:assertResourceContains resource="${output}/out.xml"
+                               value="set='if-value'"/>
+    <au:assertResourceContains resource="${output}/out.xml"
+                               value="empty='if-value'"/>
+  </target>
+
+  <target name="testIfFalse" depends="setUpIfUnlessTests">
+    <property name="if" value="false"/>
+    <xs/>
+    <au:assertResourceContains resource="${output}/out.xml"
+                               value="set='unless-value'"/>
+    <au:assertResourceContains resource="${output}/out.xml"
+                               value="empty='if-value'"/>
+  </target>
 </project>



Mime
View raw message