You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by st...@apache.org on 2005/01/22 23:01:15 UTC

cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs/condition XorTest.java

stevel      2005/01/22 14:01:15

  Modified:    docs/manual/CoreTasks conditions.html
               src/main/org/apache/tools/ant/types defaults.properties
  Added:       src/etc/testcases/taskdefs/conditions xor.xml
               src/main/org/apache/tools/ant/taskdefs/condition Xor.java
               src/testcases/org/apache/tools/ant/taskdefs/condition
                        XorTest.java
  Log:
  Xor. Not strictly necessary, but the logical equivalent is a dog to type.
  
  Revision  Changes    Path
  1.26      +9 -0      ant/docs/manual/CoreTasks/conditions.html
  
  Index: conditions.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/conditions.html,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- conditions.html	17 Jan 2005 21:54:34 -0000	1.25
  +++ conditions.html	22 Jan 2005 22:01:15 -0000	1.26
  @@ -49,6 +49,15 @@
   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>&lt;xor&gt;</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>&lt;and&gt;</code>
  +and <code>&lt;or&gt;</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
  
  
  
  1.36      +1 -1      ant/src/main/org/apache/tools/ant/types/defaults.properties
  
  Index: defaults.properties
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/defaults.properties,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- defaults.properties	17 Jan 2005 21:54:34 -0000	1.35
  +++ defaults.properties	22 Jan 2005 22:01:15 -0000	1.36
  @@ -41,4 +41,4 @@
   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
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/conditions/xor.xml
  
  Index: xor.xml
  ===================================================================
  <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>
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/taskdefs/condition/Xor.java
  
  Index: Xor.java
  ===================================================================
  /*
   * 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;
      }
  
  }
  
  
  
  1.1                  ant/src/testcases/org/apache/tools/ant/taskdefs/condition/XorTest.java
  
  Index: XorTest.java
  ===================================================================
  /*
   * 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");
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org