Author: mbenson
Date: Sat Feb 27 00:05:34 2010
New Revision: 916874
URL: http://svn.apache.org/viewvc?rev=916874&view=rev
Log:
moving ConditionEvaluator to ConditionTypeEvaluator; creating
ConditionsEvaluator to merge (by delegation) the functionality of the
ConditionTypeEvaluator and the LogicalOperationEvaluator
Added:
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionTypeEvaluator.java
- copied, changed from r916855,
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionsEvaluator.java
ant/antlibs/props/trunk/src/tests/antunit/condition-type-test.xml
ant/antlibs/props/trunk/src/tests/antunit/conditions-test.xml
Removed:
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
ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml
Modified: ant/antlibs/props/trunk/docs/index.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/docs/index.html?rev=916874&r1=916873&r2=916874&view=diff
==============================================================================
--- ant/antlibs/props/trunk/docs/index.html (original)
+++ ant/antlibs/props/trunk/docs/index.html Sat Feb 27 00:05:34 2010
@@ -129,6 +129,14 @@
setting the given attibute values and evaluates to either
Boolean.TRUE or Boolean.FALSE. Usage looks
like <em>${os(family=unix)}</em> / <em>${!os(family=unix)}</em>.
+ Additionally, logical operations are supported.
+ In order of precedence, these are !, &, ^, and |, with +
+ being a secondary alias for & since & is a special character
+ to the XML format. When you want to combine logical operations
+ with typed Ant conditions, the typed conditions should be
+ specified as nested properties and the <a href="#nested">nested
+ evaluator</a> should be included with your active
+ PropertyHelper delegates.
This is probably most useful together with the
<code>if</code>/<code>unless</code> attributes of tasks or targets.
</td>
Copied:
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionTypeEvaluator.java
(from r916855,
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/ConditionTypeEvaluator.java?p2=ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionTypeEvaluator.java&p1=ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionEvaluator.java&r1=916855&r2=916874&rev=916874&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/ConditionTypeEvaluator.java
Sat Feb 27 00:05:34 2010
@@ -36,7 +36,7 @@
* <code>[!]<em>condition</em>(<em>attribute</em>=<em>value</em>)</code>,
* for example <code>os(family=unix)</code> or <code>!os(family=unix)</code>.
*/
-public class ConditionEvaluator extends RegexBasedEvaluator {
+public class ConditionTypeEvaluator extends RegexBasedEvaluator {
private static final Pattern COMMA = Pattern.compile(",");
private static final Pattern EQ = Pattern.compile("=");
@@ -64,9 +64,9 @@
;
/**
- * Create a new ConditionEvaluator instance.
+ * Create a new ConditionTypeEvaluator instance.
*/
- public ConditionEvaluator() {
+ public ConditionTypeEvaluator() {
super(PATTERN);
}
Added:
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionsEvaluator.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionsEvaluator.java?rev=916874&view=auto
==============================================================================
---
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionsEvaluator.java
(added)
+++
ant/antlibs/props/trunk/src/main/org/apache/ant/props/ConditionsEvaluator.java
Sat Feb 27 00:05:34 2010
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ant.props;
+
+import org.apache.ant.props.DelegatingPropertyEvaluator;
+
+/**
+ * PropertyEvaluator that delegates to ConditionTypeEvaluator
+ * and LogicalOperationEvaluator for a more all-encompassing
+ * treatment of condition processing. Wants NestedPropertyExpander.
+ */
+public class ConditionsEvaluator extends DelegatingPropertyEvaluator {
+ /**
+ * Construct a new ConditionsEvaluator.
+ */
+ public ConditionsEvaluator() {
+ addDelegate(new ConditionTypeEvaluator());
+ addDelegate(new LogicalOperationEvaluator());
+ }
+
+}
Modified: ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml?rev=916874&r1=916873&r2=916874&view=diff
==============================================================================
--- ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml (original)
+++ ant/antlibs/props/trunk/src/main/org/apache/ant/props/antlib.xml Sat Feb 27
00:05:34 2010
@@ -22,5 +22,5 @@
<typedef name="stringops"
classname="org.apache.ant.props.stringops.StringOperationsEvaluator" />
<typedef name="types"
classname="org.apache.ant.props.ComponentTypeEvaluator" />
<typedef name="encodeURL"
classname="org.apache.ant.props.EncodeURLEvaluator" />
- <typedef name="conditions"
classname="org.apache.ant.props.ConditionEvaluator" />
+ <typedef name="conditions"
classname="org.apache.ant.props.ConditionsEvaluator" />
</antlib>
Added: ant/antlibs/props/trunk/src/tests/antunit/condition-type-test.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/tests/antunit/condition-type-test.xml?rev=916874&view=auto
==============================================================================
--- ant/antlibs/props/trunk/src/tests/antunit/condition-type-test.xml (added)
+++ ant/antlibs/props/trunk/src/tests/antunit/condition-type-test.xml Sat Feb
27 00:05:34 2010
@@ -0,0 +1,111 @@
+<?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"
+ xmlns:props="antlib:org.apache.ant.props" default="antunit">
+ <typedef name="condition-type"
+ classname="org.apache.ant.props.ConditionTypeEvaluator" />
+ <propertyhelper>
+ <condition-type />
+ <props:nested />
+ </propertyhelper>
+
+ <target name="if-available"
+
if="${available(classname=org.apache.ant.props.ConditionTypeEvaluator)}">
+ <property name="testAvailable.pass" value="true" />
+ </target>
+
+ <target name="unless-available"
+
unless="${available(classname=org.apache.ant.props.ConditionTypeEvaluator)}">
+ <property name="testAvailable.fail" value="true" />
+ </target>
+
+ <target name="testAvailable" depends="if-available,unless-available">
+ <au:assertTrue>
+ <and>
+ <istrue value="${testAvailable.pass}" />
+ <not><istrue value="${testAvailable.fail}" /></not>
+ </and>
+ </au:assertTrue>
+ </target>
+
+ <target name="set-prop">
+ <property name="foo" value="bar"/>
+ </target>
+
+ <target name="if-equals" if="${equals(arg1=bar,arg2=${foo})}">
+ <property name="testTrueEquals.pass" value="true" />
+ </target>
+
+ <target name="unless-equals" unless="${equals(arg1=bar,arg2=${foo})}">
+ <property name="testFalseEquals.pass" value="true" />
+ </target>
+
+ <target name="testTrueEquals" depends="set-prop,if-equals,unless-equals">
+ <au:assertTrue>
+ <istrue value="${testTrueEquals.pass}" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testFalseEquals" depends="if-equals,unless-equals"
+ description="Pass is inconclusive">
+ <au:assertTrue>
+ <istrue value="${testFalseEquals.pass}" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testEvalToTextFalse">
+ <au:assertTrue>
+ <!-- equals takes objects; embedding values in () forces string
conversion -->
+ <equals arg1="(false)" arg2="(${equals(arg1=bar,arg2=${foo})})" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testEvalToTextTrue" depends="set-prop">
+ <au:assertTrue>
+ <!-- equals takes objects; embedding values in () forces string
conversion -->
+ <equals arg1="(true)" arg2="(${equals(arg1=bar,arg2=${foo})})" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testIsTrue" depends="set-prop">
+ <au:assertTrue>
+ <istrue value="${equals(arg1=bar,arg2=${foo})}" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testNotIsTrue" description="Pass is inconclusive">
+ <au:assertFalse>
+ <istrue value="${equals(arg1=bar,arg2=${foo})}" />
+ </au:assertFalse>
+ </target>
+
+ <target name="antunit">
+ <antunit xmlns="antlib:org.apache.ant.antunit">
+ <plainlistener />
+ <file file="${ant.file}" xmlns="antlib:org.apache.tools.ant" />
+ </antunit>
+ </target>
+
+ <target name="testNegation">
+ <property name="foo" value="false" />
+ <au:assertTrue>
+ <istrue value="${!istrue(value=${foo})}" />
+ </au:assertTrue>
+ </target>
+
+</project>
Added: ant/antlibs/props/trunk/src/tests/antunit/conditions-test.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/props/trunk/src/tests/antunit/conditions-test.xml?rev=916874&view=auto
==============================================================================
--- ant/antlibs/props/trunk/src/tests/antunit/conditions-test.xml (added)
+++ ant/antlibs/props/trunk/src/tests/antunit/conditions-test.xml Sat Feb 27
00:05:34 2010
@@ -0,0 +1,113 @@
+<?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"
+ xmlns:props="antlib:org.apache.ant.props" default="antunit">
+
+ <propertyhelper>
+ <props:conditions />
+ <props:nested />
+ </propertyhelper>
+
+ <target name="if-available"
+
if="${${available(classname=org.apache.ant.props.ConditionsEvaluator)} |
false}">
+ <property name="testAvailable.pass" value="true" />
+ </target>
+
+ <target name="unless-available"
+
unless="${${available(classname=org.apache.ant.props.ConditionsEvaluator)}
& true}">
+ <property name="testAvailable.fail" value="true" />
+ </target>
+
+ <target name="testAvailable" depends="if-available,unless-available">
+ <propertyhelper>
+ <props:stringops />
+ </propertyhelper>
+ <au:assertTrue>
+ <istrue value="${${testAvailable.pass:-false} &
!${testAvailable.fail:-false}}" />
+ </au:assertTrue>
+ </target>
+
+ <target name="set-prop">
+ <property name="foo" value="bar" />
+ </target>
+
+ <target name="if-equals" if="${${equals(arg1=bar,arg2=${foo})} | false}">
+ <property name="testTrueEquals.pass" value="true" />
+ </target>
+
+ <target name="unless-equals"
+ unless="${${equals(arg1=bar,arg2=${foo})} & true}">
+ <property name="testFalseEquals.pass" value="true" />
+ </target>
+
+ <target name="testTrueEquals" depends="set-prop,if-equals,unless-equals">
+ <au:assertTrue>
+ <istrue value="${testTrueEquals.pass}" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testFalseEquals" depends="if-equals,unless-equals"
+ description="Pass is inconclusive">
+ <au:assertTrue>
+ <istrue value="${testFalseEquals.pass}" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testEvalToTextFalse">
+ <au:assertTrue>
+ <!-- equals takes objects; embedding values in () forces string
conversion -->
+ <equals arg1="(false)"
+ arg2="(${${equals(arg1=bar,arg2=${foo})} & true})" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testEvalToTextTrue" depends="set-prop">
+ <au:assertTrue>
+ <!-- equals takes objects; embedding values in () forces string
conversion -->
+ <equals arg1="(true)"
+ arg2="(${${equals(arg1=bar,arg2=${foo})} | false})" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testIsTrue" depends="set-prop">
+ <au:assertTrue>
+ <istrue value="${${equals(arg1=bar,arg2=${foo})} | false}" />
+ </au:assertTrue>
+ </target>
+
+ <target name="testNotIsTrue" description="Pass is inconclusive">
+ <au:assertFalse>
+ <istrue value="${${equals(arg1=bar,arg2=${foo})} & true}" />
+ </au:assertFalse>
+ </target>
+
+ <target name="antunit">
+ <antunit xmlns="antlib:org.apache.ant.antunit">
+ <plainlistener />
+ <file file="${ant.file}" xmlns="antlib:org.apache.tools.ant" />
+ </antunit>
+ </target>
+
+ <target name="testNegation">
+ <property name="foo" value="false" />
+ <au:assertTrue>
+ <istrue value="${!${istrue(value=${foo})}}" />
+ </au:assertTrue>
+ </target>
+
+</project>