git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@358863 13f79535-47bb-0310-9956-ffa450edef68master
@@ -335,6 +335,8 @@ Other changes: | |||||
* add textfile attribute to the filesmatch condition. | * add textfile attribute to the filesmatch condition. | ||||
* new resourcesmatch condition. | |||||
Changes from Ant 1.6.4 to Ant 1.6.5 | Changes from Ant 1.6.4 to Ant 1.6.5 | ||||
=================================== | =================================== | ||||
@@ -221,7 +221,8 @@ TCP/IP listener at the specified host and port.</p> | |||||
</table> | </table> | ||||
<h4>filesmatch</h4> | <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 | 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 | 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. | or the filenames match the answer is so obvious the detailed test is omitted. | ||||
@@ -245,8 +246,9 @@ or the filenames match the answer is so obvious the detailed test is omitted. | |||||
</tr> | </tr> | ||||
<tr> | <tr> | ||||
<td valign="top">textfile</td> | <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> | ||||
<td align="center">No</td> | <td align="center">No</td> | ||||
</tr> | </tr> | ||||
@@ -676,6 +678,34 @@ Probe for the maven repository being reachable using the hostname, ten second ti | |||||
<resourcecount refid="myresourcecollection" when="greater" length="0" /> | <resourcecount refid="myresourcecollection" when="greater" length="0" /> | ||||
</pre> | </pre> | ||||
<p>Verify that a resource collection is not empty.</p> | <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> | <hr> | ||||
<p align="center">Copyright © 2001-2005 Apache Software | <p align="center">Copyright © 2001-2005 Apache Software | ||||
Foundation. All rights Reserved.</p> | Foundation. All rights Reserved.</p> | ||||
@@ -185,6 +185,16 @@ | |||||
<echo>${filesmatch-existence}</echo> | <echo>${filesmatch-existence}</echo> | ||||
</target> | </target> | ||||
<target name="filesmatch-neitherexist"> | |||||
<fail> | |||||
<condition> | |||||
<not> | |||||
<filesmatch file1="idonotexist" file2="andneitherdoi" /> | |||||
</not> | |||||
</condition> | |||||
</fail> | |||||
</target> | |||||
<target name="filesmatch-different"> | <target name="filesmatch-different"> | ||||
<echo file="match1.txt" message="012345676890" /> | <echo file="match1.txt" message="012345676890" /> | ||||
<echo file="match2.txt" message="012345676889" /> | <echo file="match2.txt" message="012345676889" /> | ||||
@@ -395,6 +405,97 @@ | |||||
</fail> | </fail> | ||||
</target> | </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> | |||||
<target name="cleanup" > | <target name="cleanup" > | ||||
<delete> | <delete> | ||||
<fileset dir="." includes="match?.txt,match??.txt" /> | <fileset dir="." includes="match?.txt,match??.txt" /> | ||||
@@ -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; | |||||
} | |||||
} |
@@ -4,6 +4,21 @@ filterreader=org.apache.tools.ant.types.AntFilterReader | |||||
filterset=org.apache.tools.ant.types.FilterSet | filterset=org.apache.tools.ant.types.FilterSet | ||||
mapper=org.apache.tools.ant.types.Mapper | mapper=org.apache.tools.ant.types.Mapper | ||||
redirector=org.apache.tools.ant.types.RedirectorElement | 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 | # different filename mappers | ||||
identitymapper=org.apache.tools.ant.util.IdentityMapper | identitymapper=org.apache.tools.ant.util.IdentityMapper | ||||
flattenmapper=org.apache.tools.ant.util.FlatFileNameMapper | flattenmapper=org.apache.tools.ant.util.FlatFileNameMapper | ||||
@@ -16,27 +31,15 @@ compositemapper=org.apache.tools.ant.util.CompositeMapper | |||||
chainedmapper=org.apache.tools.ant.util.ChainedMapper | chainedmapper=org.apache.tools.ant.util.ChainedMapper | ||||
filtermapper=org.apache.tools.ant.types.mappers.FilterMapper | 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 | issigned=org.apache.tools.ant.taskdefs.condition.IsSigned | ||||
isfileselected=org.apache.tools.ant.taskdefs.condition.IsFileSelected | isfileselected=org.apache.tools.ant.taskdefs.condition.IsFileSelected | ||||
isreachable=org.apache.tools.ant.taskdefs.condition.IsReachable | 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 | scriptcondition=org.apache.tools.ant.types.optional.ScriptCondition | ||||
xor=org.apache.tools.ant.taskdefs.condition.Xor | xor=org.apache.tools.ant.taskdefs.condition.Xor | ||||
parsersupports=org.apache.tools.ant.taskdefs.condition.ParserSupports | parsersupports=org.apache.tools.ant.taskdefs.condition.ParserSupports | ||||
scriptmapper=org.apache.tools.ant.types.optional.ScriptMapper | |||||
isfailure=org.apache.tools.ant.taskdefs.condition.IsFailure | isfailure=org.apache.tools.ant.taskdefs.condition.IsFailure | ||||
resourcesmatch=org.apache.tools.ant.taskdefs.condition.ResourcesMatch | |||||
#ResourceCollections: | #ResourceCollections: | ||||
dirset=org.apache.tools.ant.types.DirSet | dirset=org.apache.tools.ant.types.DirSet | ||||
@@ -170,6 +170,10 @@ public class ConditionTest extends BuildFileTest { | |||||
executeTarget("filesmatch-same-eol"); | executeTarget("filesmatch-same-eol"); | ||||
} | } | ||||
public void testFilesmatchNeitherExist() { | |||||
executeTarget("filesmatch-neitherexist"); | |||||
} | |||||
public void testContains() { | public void testContains() { | ||||
expectPropertySet("contains","contains"); | expectPropertySet("contains","contains"); | ||||
} | } | ||||
@@ -237,5 +241,37 @@ public class ConditionTest extends BuildFileTest { | |||||
public void testElse() { | public void testElse() { | ||||
executeTarget("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"); | |||||
} | |||||
} |