git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277431 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -49,6 +49,15 @@ file.</p> <p>The <code><or></code> condition has the same | |||
| shortcut semantics as the Java || operator, as soon as one of the | |||
| nested conditions is true, no other condition will be evaluated.</p> | |||
| <h4>xor</h4> | |||
| <p>The <code><xor></code> element performs an exclusive | |||
| or on all nested elements, similar to the <code>^</code> operator | |||
| in Java. It only evaluates to true if an odd number of nested conditions | |||
| are true. There is no shortcutting of evaluation, unlike the <code><and></code> | |||
| and <code><or></code> tests. | |||
| It doesn't have any attributes and accepts all nested | |||
| elements of the condition task as nested elements as well.</p> | |||
| <h4>available</h4> | |||
| <p>This condition is identical to the <a | |||
| href="available.html">Available</a> task, all attributes and nested | |||
| @@ -0,0 +1,95 @@ | |||
| <project default="all"> | |||
| <!-- | |||
| Xor semantics | |||
| in out | |||
| == === | |||
| 00 0 | |||
| 01 1 | |||
| 10 1 | |||
| 00 0 | |||
| --> | |||
| <target name="testEmpty" > | |||
| <fail message="empty test"> | |||
| <condition> | |||
| <xor/> | |||
| </condition> | |||
| </fail> | |||
| </target> | |||
| <target name="test1" > | |||
| <fail message="testTrue"> | |||
| <condition> | |||
| <not> | |||
| <xor> | |||
| <istrue value="true" /> | |||
| </xor> | |||
| </not> | |||
| </condition> | |||
| </fail> | |||
| </target> | |||
| <target name="test0" > | |||
| <fail message="testFalse"> | |||
| <condition> | |||
| <xor> | |||
| <istrue value="" /> | |||
| </xor> | |||
| </condition> | |||
| </fail> | |||
| </target> | |||
| <target name="test10" > | |||
| <fail message="test10"> | |||
| <condition> | |||
| <not> | |||
| <xor> | |||
| <istrue value="true" /> | |||
| <istrue value="" /> | |||
| </xor> | |||
| </not> | |||
| </condition> | |||
| </fail> | |||
| </target> | |||
| <target name="test01" > | |||
| <fail message="test01"> | |||
| <condition> | |||
| <not> | |||
| <xor> | |||
| <istrue value="" /> | |||
| <istrue value="true" /> | |||
| </xor> | |||
| </not> | |||
| </condition> | |||
| </fail> | |||
| </target> | |||
| <target name="test00" > | |||
| <fail message="test10"> | |||
| <condition> | |||
| <xor> | |||
| <istrue value="" /> | |||
| <istrue value="" /> | |||
| </xor> | |||
| </condition> | |||
| </fail> | |||
| </target> | |||
| <target name="test11" > | |||
| <fail message="test11"> | |||
| <condition> | |||
| <xor> | |||
| <istrue value="" /> | |||
| <istrue value="" /> | |||
| </xor> | |||
| </condition> | |||
| </fail> | |||
| </target> | |||
| </project> | |||
| @@ -0,0 +1,46 @@ | |||
| /* | |||
| * Copyright 2005 The Apache Software Foundation | |||
| * | |||
| * Licensed 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.tools.ant.taskdefs.condition; | |||
| import org.apache.tools.ant.BuildException; | |||
| import java.util.Enumeration; | |||
| /** | |||
| * <tt>Xor</tt> task to exclusive or operations. | |||
| * This does not shortcut stuff | |||
| */ | |||
| public class Xor extends ConditionBase implements Condition { | |||
| /** | |||
| * @return true if all the contained conditions evaluates to true | |||
| * @throws org.apache.tools.ant.BuildException | |||
| * if an error occurs | |||
| */ | |||
| public boolean eval() throws BuildException { | |||
| Enumeration e = getConditions(); | |||
| //initial state is false. | |||
| boolean state=false; | |||
| while (e.hasMoreElements()) { | |||
| Condition c = (Condition) e.nextElement(); | |||
| //every condition is xored against the previous one | |||
| state ^= c.eval(); | |||
| } | |||
| return state; | |||
| } | |||
| } | |||
| @@ -41,4 +41,4 @@ ispingable=org.apache.tools.ant.taskdefs.optional.condition.IsPingable | |||
| mavenrepository=org.apache.tools.ant.taskdefs.repository.MavenRepository | |||
| scriptselector=org.apache.tools.ant.types.optional.ScriptSelector | |||
| scriptcondition=org.apache.tools.ant.types.optional.ScriptCondition | |||
| xor=org.apache.tools.ant.taskdefs.condition.Xor | |||
| @@ -0,0 +1,67 @@ | |||
| /* | |||
| * Copyright 2005 The Apache Software Foundation | |||
| * | |||
| * Licensed 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.tools.ant.taskdefs.condition; | |||
| import org.apache.tools.ant.BuildFileTest; | |||
| /** | |||
| * Test that Xor follows the conventional boolean logic semantics | |||
| * (a ^ b) === (a||b)&!(a&&b) | |||
| */ | |||
| public class XorTest extends BuildFileTest { | |||
| public XorTest(String name) { | |||
| super(name); | |||
| } | |||
| /** | |||
| * The JUnit setup method | |||
| */ | |||
| public void setUp() { | |||
| configureProject("src/etc/testcases/taskdefs/conditions/xor.xml"); | |||
| } | |||
| public void testEmpty() { | |||
| executeTarget("testEmpty"); | |||
| } | |||
| public void test0() { | |||
| executeTarget("test0"); | |||
| } | |||
| public void test1() { | |||
| executeTarget("test1"); | |||
| } | |||
| public void test00() { | |||
| executeTarget("test00"); | |||
| } | |||
| public void test10() { | |||
| executeTarget("test10"); | |||
| } | |||
| public void test01() { | |||
| executeTarget("test01"); | |||
| } | |||
| public void test11() { | |||
| executeTarget("test11"); | |||
| } | |||
| } | |||