From bc6cf071abcbfb870beb789101bcded16fa137d6 Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Fri, 23 Dec 2005 16:47:09 +0000 Subject: [PATCH] add textfile attribute to filesmatch condition. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@358828 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 2 + docs/manual/CoreTasks/conditions.html | 11 +++++- src/etc/testcases/taskdefs/condition.xml | 38 +++++++++++++++---- .../ant/taskdefs/condition/FilesMatch.java | 14 ++++++- .../tools/ant/taskdefs/ConditionTest.java | 8 ++++ 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index c409d7295..04bfd98d3 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -333,6 +333,8 @@ Other changes: * new GreedyInputHandler added. +* add textfile attribute to the filesmatch condition. + Changes from Ant 1.6.4 to Ant 1.6.5 =================================== diff --git a/docs/manual/CoreTasks/conditions.html b/docs/manual/CoreTasks/conditions.html index 1dc67e26f..86c682bee 100644 --- a/docs/manual/CoreTasks/conditions.html +++ b/docs/manual/CoreTasks/conditions.html @@ -236,12 +236,19 @@ or the filenames match the answer is so obvious the detailed test is omitted. file1 First file to test - Yes. + Yes file2 Second file to test - Yes. + Yes + + + textfile + Whether to ignore line endings when comparing files; + default false + + No diff --git a/src/etc/testcases/taskdefs/condition.xml b/src/etc/testcases/taskdefs/condition.xml index 2b0aed56c..ed11198e1 100644 --- a/src/etc/testcases/taskdefs/condition.xml +++ b/src/etc/testcases/taskdefs/condition.xml @@ -196,9 +196,8 @@ file2="match2.txt" /> ${filesmatch-different} - + - @@ -210,6 +209,32 @@ ${filesmatch-match} + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -374,12 +399,9 @@ - - - - - - + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java b/src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java index 5308db050..ecb17e99f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/FilesMatch.java @@ -22,7 +22,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.util.FileUtils; /** - * Compares two files for bitwise equality based on size and + * Compares two files for equality based on size and * content. Timestamps are not at all looked at. * * @since Ant 1.5 @@ -40,6 +40,8 @@ public class FilesMatch implements Condition { */ private File file1, file2; + private boolean textfile = false; + /** * Sets the File1 attribute @@ -60,6 +62,14 @@ public class FilesMatch implements Condition { this.file2 = file2; } + /** + * Set whether to ignore line endings when comparing files. + * @param textfile whether to ignore line endings. + */ + public void setTextfile(boolean textfile) { + this.textfile = textfile; + } + /** * comparison method of the interface * @@ -78,7 +88,7 @@ public class FilesMatch implements Condition { //#now match the files boolean matches = false; try { - matches = FILE_UTILS.contentEquals(file1, file2); + matches = FILE_UTILS.contentEquals(file1, file2, textfile); } catch (IOException ioe) { throw new BuildException("when comparing files: " + ioe.getMessage(), ioe); diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java index ae7dd1d71..744f029ea 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/ConditionTest.java @@ -162,6 +162,14 @@ public class ConditionTest extends BuildFileTest { "filesmatch-different-onemissing"); } + public void testFilesmatchDifferentEol() { + executeTarget("filesmatch-different-eol"); + } + + public void testFilesmatchSameEol() { + executeTarget("filesmatch-same-eol"); + } + public void testContains() { expectPropertySet("contains","contains"); }