ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r358863 - in /ant/core/trunk: ./ docs/manual/CoreTasks/ src/etc/testcases/taskdefs/ src/main/org/apache/tools/ant/taskdefs/condition/ src/main/org/apache/tools/ant/types/ src/testcases/org/apache/tools/ant/taskdefs/
Date Fri, 23 Dec 2005 20:15:56 GMT
Author: mbenson
Date: Fri Dec 23 12:15:49 2005
New Revision: 358863

URL: http://svn.apache.org/viewcvs?rev=358863&view=rev
Log:
add the resourcesmatch condition.

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourcesMatch.java  
(with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/conditions.html
    ant/core/trunk/src/etc/testcases/taskdefs/condition.xml
    ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewcvs/ant/core/trunk/WHATSNEW?rev=358863&r1=358862&r2=358863&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Dec 23 12:15:49 2005
@@ -335,6 +335,8 @@
 
 * add textfile attribute to the filesmatch condition.
 
+* new resourcesmatch condition.
+
 Changes from Ant 1.6.4 to Ant 1.6.5
 ===================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/conditions.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/conditions.html?rev=358863&r1=358862&r2=358863&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/conditions.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/conditions.html Fri Dec 23 12:15:49 2005
@@ -221,7 +221,8 @@
 </table>
 
 <h4>filesmatch</h4>
-<p>Test two files for matching. Nonexistence of either file results in "false".
+<p>Test two files for matching. Nonexistence of one file results in "false",
+although if neither exists they are considered equal in terms of content.
 This test does a byte for byte comparision, so test time scales with
 byte size. NB: if the files are different sizes, one of them is missing
 or the filenames match the answer is so obvious the detailed test is omitted.
@@ -245,8 +246,9 @@
   </tr>
   <tr>
     <td valign="top">textfile</td>
-    <td valign="top">Whether to ignore line endings when comparing files;
-        default <i>false</i>
+    <td valign="top">Whether to ignore line endings
+        when comparing files; defaults to <i>false</i>, while
+        <i>true</i> bypasses the size comparison.
     </td>
     <td align="center">No</td>
   </tr>
@@ -676,6 +678,34 @@
 &lt;resourcecount refid=&quot;myresourcecollection&quot; when=&quot;greater&quot;
length=&quot;0&quot; /&gt;
 </pre>
 <p>Verify that a resource collection is not empty.</p>
+
+<h4>resourcesmatch</h4>
+<p>Test resources for matching. Nonexistence of one or more resources results in
+"false", although if none exists they are considered equal in terms of content.
+By default this test does a byte for byte comparision, so test time scales with
+byte size. NB: if the files are different sizes, one of them is missing
+or the filenames match the answer is so obvious the detailed test is omitted.
+The resources to check are specified as nested
+<a href="../CoreTypes/resources.html#collection">resource collections</a>,
+meaning that more than two resources can be checked; in this case all resources
+must match. <b>Since Ant 1.7</b>
+</p>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td width="12%" valign="top"><b>Attribute</b></td>
+    <td width="78%" valign="top"><b>Description</b></td>
+    <td width="10%" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">astext</td>
+    <td valign="top">Whether to ignore line endings
+        when comparing resource content; defaults to <i>false</i>,
+        while <i>true</i> bypasses the size comparison.
+    </td>
+    <td align="center">No</td>
+  </tr>
+</table>
+
 <hr>
 <p align="center">Copyright &copy; 2001-2005 Apache Software
 Foundation. All rights Reserved.</p>

Modified: ant/core/trunk/src/etc/testcases/taskdefs/condition.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/condition.xml?rev=358863&r1=358862&r2=358863&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/condition.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/condition.xml Fri Dec 23 12:15:49 2005
@@ -185,6 +185,16 @@
     <echo>${filesmatch-existence}</echo>
   </target>
 
+  <target name="filesmatch-neitherexist">
+    <fail>
+      <condition>
+        <not>
+          <filesmatch file1="idonotexist" file2="andneitherdoi" />
+        </not>
+      </condition>
+    </fail>
+  </target>
+
   <target name="filesmatch-different">
     <echo file="match1.txt" message="012345676890" />
     <echo file="match2.txt" message="012345676889" />
@@ -391,6 +401,97 @@
             </and>
           </not>
         </or>
+      </condition>
+    </fail>
+  </target>
+
+  <target name="resourcesmatch-error">
+    <condition property="errorexpected">
+      <resourcesmatch />
+    </condition>
+  </target>
+
+  <target name="resourcesmatch-match-empty">
+    <condition property="errorexpected">
+      <resourcesmatch>
+        <resources />
+      </resourcesmatch>
+    </condition>
+  </target>
+
+  <target name="resourcesmatch-match-one">
+    <condition property="errorexpected">
+      <resourcesmatch>
+        <string value="foo" />
+      </resourcesmatch>
+    </condition>
+  </target>
+
+  <target name="resourcesmatch-match-binary">
+    <fail>
+      <condition>
+        <not>
+          <resourcesmatch>
+            <string value="foo" />
+            <string value="foo" />
+          </resourcesmatch>
+        </not>
+      </condition>
+    </fail>
+  </target>
+
+  <target name="resourcesmatch-match-multiple-binary">
+    <fail>
+      <condition>
+        <not>
+          <resourcesmatch>
+            <string value="foo" />
+            <string value="foo" />
+            <string value="foo" />
+          </resourcesmatch>
+        </not>
+      </condition>
+    </fail>
+  </target>
+
+  <target name="resourcesmatch-differ">
+    <echo file="match11.txt" message="foo" />
+    <fixcrlf file="match11.txt" eol="crlf" fixlast="true" />
+    <fail>
+      <condition>
+        <resourcesmatch>
+          <file file="match11.txt" />
+          <string value="foo" />
+        </resourcesmatch>
+      </condition>
+    </fail>
+  </target>
+
+  <target name="resourcesmatch-match-text">
+    <echo file="match11.txt" message="foo" />
+    <fixcrlf file="match11.txt" eol="crlf" />
+    <fail>
+      <condition>
+        <not>
+          <resourcesmatch astext="true">
+            <file file="match11.txt" />
+            <string value="foo" />
+          </resourcesmatch>
+        </not>
+      </condition>
+    </fail>
+  </target>
+
+  <target name="resourcesmatch-noneexist">
+    <fail>
+      <condition>
+        <not>
+          <resourcesmatch>
+            <resource name="foo" exists="false" />
+            <resource name="bar" exists="false" />
+            <resource name="baz" exists="false" />
+          </resourcesmatch>
+        </not>
       </condition>
     </fail>
   </target>

Added: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourcesMatch.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourcesMatch.java?rev=358863&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourcesMatch.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourcesMatch.java Fri
Dec 23 12:15:49 2005
@@ -0,0 +1,92 @@
+/*
+ * 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 java.io.IOException;
+import java.util.Iterator;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.Union;
+import org.apache.tools.ant.util.ResourceUtils;
+
+/**
+ * Compares resources for equality based on size and content.
+ * All resources specified must match; no resource collections
+ * specified is an error condition; if resource collections are
+ * specified, but yield fewer than two elements, the condition
+ * evaluates to <code>true</code>.
+ * @since Ant 1.7
+ */
+public class ResourcesMatch implements Condition {
+
+    private Union resources = null;
+    private boolean asText = false;
+
+    /**
+     * Set whether to treat resources as if they were text files,
+     * ignoring line endings.
+     * @param astext whether to ignore line endings.
+     */
+    public void setAsText(boolean asText) {
+        this.asText = asText;
+    }
+
+    /**
+     * Add a resource collection.
+     * @param rc the resource collection to add.
+     */
+    public void add(ResourceCollection rc) {
+        if (rc == null) {
+            return;
+        }
+        resources = resources == null ? new Union() : resources;
+        resources.add(rc);
+    }
+
+    /**
+     * Verify that all resources match.
+     * @return true if all resources are equal.
+     * @exception BuildException if there is an error.
+     */
+    public boolean eval() throws BuildException {
+        if (resources == null) {
+            throw new BuildException(
+                "You must specify one or more nested resource collections");
+        }
+        if (resources.size() > 1) {
+            Iterator i = resources.iterator();
+            Resource r1 = (Resource) i.next();
+            Resource r2 = null;
+
+            while (i.hasNext()) {
+                r2 = (Resource) i.next();
+                try {
+                    if (!ResourceUtils.contentEquals(r1, r2, asText)) {
+                        return false;
+                    }
+                } catch (IOException ioe) {
+                    throw new BuildException("when comparing resources "
+                        + r1.toString() + " and " + r2.toString(), ioe);
+                }
+                r1 = r2;
+            }
+        }
+        return true;
+    }
+}

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/condition/ResourcesMatch.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties?rev=358863&r1=358862&r2=358863&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties Fri Dec 23 12:15:49
2005
@@ -4,6 +4,21 @@
 filterset=org.apache.tools.ant.types.FilterSet
 mapper=org.apache.tools.ant.types.Mapper
 redirector=org.apache.tools.ant.types.RedirectorElement
+patternset=org.apache.tools.ant.types.PatternSet
+regexp=org.apache.tools.ant.types.RegularExpression
+substitution=org.apache.tools.ant.types.Substitution
+xmlcatalog=org.apache.tools.ant.types.XMLCatalog
+extensionSet=org.apache.tools.ant.taskdefs.optional.extension.ExtensionSet
+extension=org.apache.tools.ant.taskdefs.optional.extension.ExtensionAdapter
+selector=org.apache.tools.ant.types.selectors.SelectSelector
+signedselector=org.apache.tools.ant.types.selectors.SignedSelector
+scriptfilter=org.apache.tools.ant.types.optional.ScriptFilter
+assertions=org.apache.tools.ant.types.Assertions
+concatfilter=org.apache.tools.ant.filters.ConcatFilter
+mavenrepository=org.apache.tools.ant.taskdefs.repository.MavenRepository
+scriptselector=org.apache.tools.ant.types.optional.ScriptSelector
+scriptmapper=org.apache.tools.ant.types.optional.ScriptMapper
+
 # different filename mappers
 identitymapper=org.apache.tools.ant.util.IdentityMapper
 flattenmapper=org.apache.tools.ant.util.FlatFileNameMapper
@@ -16,27 +31,15 @@
 chainedmapper=org.apache.tools.ant.util.ChainedMapper
 filtermapper=org.apache.tools.ant.types.mappers.FilterMapper
 
-patternset=org.apache.tools.ant.types.PatternSet
-regexp=org.apache.tools.ant.types.RegularExpression
-substitution=org.apache.tools.ant.types.Substitution
-xmlcatalog=org.apache.tools.ant.types.XMLCatalog
-extensionSet=org.apache.tools.ant.taskdefs.optional.extension.ExtensionSet
-extension=org.apache.tools.ant.taskdefs.optional.extension.ExtensionAdapter
-selector=org.apache.tools.ant.types.selectors.SelectSelector
-signedselector=org.apache.tools.ant.types.selectors.SignedSelector
-scriptfilter=org.apache.tools.ant.types.optional.ScriptFilter
-assertions=org.apache.tools.ant.types.Assertions
-concatfilter=org.apache.tools.ant.filters.ConcatFilter
+#conditions:
 issigned=org.apache.tools.ant.taskdefs.condition.IsSigned
 isfileselected=org.apache.tools.ant.taskdefs.condition.IsFileSelected
 isreachable=org.apache.tools.ant.taskdefs.condition.IsReachable
-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
 parsersupports=org.apache.tools.ant.taskdefs.condition.ParserSupports
-scriptmapper=org.apache.tools.ant.types.optional.ScriptMapper
 isfailure=org.apache.tools.ant.taskdefs.condition.IsFailure
+resourcesmatch=org.apache.tools.ant.taskdefs.condition.ResourcesMatch
 
 #ResourceCollections:
 dirset=org.apache.tools.ant.types.DirSet

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java?rev=358863&r1=358862&r2=358863&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java Fri Dec
23 12:15:49 2005
@@ -170,6 +170,10 @@
         executeTarget("filesmatch-same-eol");
     }
 
+    public void testFilesmatchNeitherExist() {
+        executeTarget("filesmatch-neitherexist");
+    }
+
     public void testContains() {
         expectPropertySet("contains","contains");
     }
@@ -237,5 +241,37 @@
     public void testElse() {
         executeTarget("testElse");
     }
-}
 
+    public void testResourcesmatchError() {
+        expectBuildException("resourcesmatch-error",
+            "should fail because no resources specified");
+    }
+
+    public void testResourcesmatchEmpty() {
+        executeTarget("resourcesmatch-match-empty");
+    }
+
+    public void testResourcesmatchOne() {
+        executeTarget("resourcesmatch-match-one");
+    }
+
+    public void testResourcesmatchBinary() {
+        executeTarget("resourcesmatch-match-binary");
+    }
+
+    public void testResourcesmatchMultipleBinary() {
+        executeTarget("resourcesmatch-match-multiple-binary");
+    }
+
+    public void testResourcesmatchDiffer() {
+        executeTarget("resourcesmatch-differ");
+    }
+
+    public void testResourcesmatchText() {
+        executeTarget("resourcesmatch-match-text");
+    }
+
+    public void testResourcesmatchNoneExist() {
+        executeTarget("resourcesmatch-noneexist");
+    }
+}



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


Mime
View raw message