git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@358828 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -333,6 +333,8 @@ Other changes: | |||||
| * new GreedyInputHandler added. | * new GreedyInputHandler added. | ||||
| * add textfile attribute to the filesmatch condition. | |||||
| Changes from Ant 1.6.4 to Ant 1.6.5 | Changes from Ant 1.6.4 to Ant 1.6.5 | ||||
| =================================== | =================================== | ||||
| @@ -236,12 +236,19 @@ or the filenames match the answer is so obvious the detailed test is omitted. | |||||
| <tr> | <tr> | ||||
| <td valign="top">file1</td> | <td valign="top">file1</td> | ||||
| <td valign="top">First file to test</td> | <td valign="top">First file to test</td> | ||||
| <td align="center">Yes.</td> | |||||
| <td align="center">Yes</td> | |||||
| </tr> | </tr> | ||||
| <tr> | <tr> | ||||
| <td valign="top">file2</td> | <td valign="top">file2</td> | ||||
| <td valign="top">Second file to test</td> | <td valign="top">Second file to test</td> | ||||
| <td align="center">Yes.</td> | |||||
| <td align="center">Yes</td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td valign="top">textfile</td> | |||||
| <td valign="top">Whether to ignore line endings when comparing files; | |||||
| default <i>false</i> | |||||
| </td> | |||||
| <td align="center">No</td> | |||||
| </tr> | </tr> | ||||
| </table> | </table> | ||||
| @@ -196,9 +196,8 @@ | |||||
| file2="match2.txt" /> | file2="match2.txt" /> | ||||
| </condition> | </condition> | ||||
| <echo>${filesmatch-different}</echo> | <echo>${filesmatch-different}</echo> | ||||
| </target> | |||||
| </target> | |||||
| <target name="filesmatch-match" > | <target name="filesmatch-match" > | ||||
| <echo file="match3.txt" message="012345676890" /> | <echo file="match3.txt" message="012345676890" /> | ||||
| <echo file="match4.txt" message="012345676890" /> | <echo file="match4.txt" message="012345676890" /> | ||||
| @@ -210,6 +209,32 @@ | |||||
| <echo>${filesmatch-match}</echo> | <echo>${filesmatch-match}</echo> | ||||
| </target> | </target> | ||||
| <target name="filesmatch-different-eol" > | |||||
| <echo file="match7.txt" message="012345676890" /> | |||||
| <echo file="match8.txt" message="012345676890" /> | |||||
| <fixcrlf file="match7.txt" eol="cr" fixlast="true" /> | |||||
| <fixcrlf file="match8.txt" eol="lf" fixlast="true" /> | |||||
| <fail> | |||||
| <condition> | |||||
| <filesmatch file1="match7.txt" file2="match8.txt" /> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="filesmatch-same-eol" > | |||||
| <echo file="match9.txt" message="012345676890" /> | |||||
| <echo file="match10.txt" message="012345676890" /> | |||||
| <fixcrlf file="match9.txt" eol="cr" fixlast="true" /> | |||||
| <fixcrlf file="match10.txt" eol="lf" fixlast="true" /> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <filesmatch file1="match9.txt" file2="match10.txt" textfile="true" /> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="filesmatch-different-sizes"> | <target name="filesmatch-different-sizes"> | ||||
| <echo file="match5.txt" message="012345676890" /> | <echo file="match5.txt" message="012345676890" /> | ||||
| <echo file="match6.txt" message="0123456768" /> | <echo file="match6.txt" message="0123456768" /> | ||||
| @@ -374,12 +399,9 @@ | |||||
| </target> | </target> | ||||
| <target name="cleanup" > | <target name="cleanup" > | ||||
| <delete file="match1.txt" /> | |||||
| <delete file="match2.txt" /> | |||||
| <delete file="match3.txt" /> | |||||
| <delete file="match4.txt" /> | |||||
| <delete file="match5.txt" /> | |||||
| <delete file="match6.txt" /> | |||||
| <delete> | |||||
| <fileset dir="." includes="match?.txt,match??.txt" /> | |||||
| </delete> | |||||
| </target> | </target> | ||||
| </project> | </project> | ||||
| @@ -22,7 +22,7 @@ import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.util.FileUtils; | 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. | * content. Timestamps are not at all looked at. | ||||
| * | * | ||||
| * @since Ant 1.5 | * @since Ant 1.5 | ||||
| @@ -40,6 +40,8 @@ public class FilesMatch implements Condition { | |||||
| */ | */ | ||||
| private File file1, file2; | private File file1, file2; | ||||
| private boolean textfile = false; | |||||
| /** | /** | ||||
| * Sets the File1 attribute | * Sets the File1 attribute | ||||
| @@ -60,6 +62,14 @@ public class FilesMatch implements Condition { | |||||
| this.file2 = file2; | 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 | * comparison method of the interface | ||||
| * | * | ||||
| @@ -78,7 +88,7 @@ public class FilesMatch implements Condition { | |||||
| //#now match the files | //#now match the files | ||||
| boolean matches = false; | boolean matches = false; | ||||
| try { | try { | ||||
| matches = FILE_UTILS.contentEquals(file1, file2); | |||||
| matches = FILE_UTILS.contentEquals(file1, file2, textfile); | |||||
| } catch (IOException ioe) { | } catch (IOException ioe) { | ||||
| throw new BuildException("when comparing files: " | throw new BuildException("when comparing files: " | ||||
| + ioe.getMessage(), ioe); | + ioe.getMessage(), ioe); | ||||
| @@ -162,6 +162,14 @@ public class ConditionTest extends BuildFileTest { | |||||
| "filesmatch-different-onemissing"); | "filesmatch-different-onemissing"); | ||||
| } | } | ||||
| public void testFilesmatchDifferentEol() { | |||||
| executeTarget("filesmatch-different-eol"); | |||||
| } | |||||
| public void testFilesmatchSameEol() { | |||||
| executeTarget("filesmatch-same-eol"); | |||||
| } | |||||
| public void testContains() { | public void testContains() { | ||||
| expectPropertySet("contains","contains"); | expectPropertySet("contains","contains"); | ||||
| } | } | ||||