Browse Source

Added an ignorecontents attribute to <different>

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276707 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 21 years ago
parent
commit
f7a5fe1058
3 changed files with 38 additions and 12 deletions
  1. +2
    -0
      WHATSNEW
  2. +10
    -1
      docs/manual/CoreTypes/selectors.html
  3. +26
    -11
      src/main/org/apache/tools/ant/types/selectors/DifferentSelector.java

+ 2
- 0
WHATSNEW View File

@@ -37,6 +37,8 @@ Changes that could break older environments:
Other changes:
--------------

* New attribute ignorecontents for <different> selector

Fixed bugs:
-----------



+ 10
- 1
docs/manual/CoreTypes/selectors.html View File

@@ -300,7 +300,8 @@
<li> Files with different lengths are different.
<li> If <tt>ignoreFileTimes</tt> is turned off, then differing file
timestamps will cause files to be regarded as different.
<li> Finally a byte-for-byte check is run against the two files
<li> Unless<tt>ignoreContents</tt> is set to true, a byte-for-byte check is run
against the two files
</ol>

This is a useful selector to work with programs and tasks that don't handle
@@ -342,6 +343,14 @@
</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">ignoreContents</td>
<td valign="top">Whether to do a byte per byte compare.
Default is false (contents are compared).
Since ant 1.6.3
</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">granularity</td>
<td valign="top">The number of milliseconds leeway to give before


+ 26
- 11
src/main/org/apache/tools/ant/types/selectors/DifferentSelector.java View File

@@ -25,10 +25,14 @@ import java.io.IOException;

/**
* This selector selects files against a mapped set of target files, selecting
* all those files which are different. A byte-by-byte comparision is performed
* on equal length files; files with different lengths are deemed different
* automatically; files with identical timestamps are viewed as matching by
* all those files which are different.
* Files with different lengths are deemed different
* automatically
* Files with identical timestamps are viewed as matching by
* default, unless you specify otherwise.
* Contents are compared if the lengths are the same
* and the timestamps are ignored or the same,
* except if you decide to ignore contents to gain speed.
* <p>
* This is a useful selector to work with programs and tasks that don't handle
* dependency checking properly; Even if a predecessor task always creates its
@@ -47,6 +51,7 @@ public class DifferentSelector extends MappingSelector {
private FileUtils fileUtils = FileUtils.newFileUtils();

private boolean ignoreFileTimes = true;
private boolean ignoreContents = false;


/**
@@ -56,7 +61,14 @@ public class DifferentSelector extends MappingSelector {
public void setIgnoreFileTimes(boolean ignoreFileTimes) {
this.ignoreFileTimes = ignoreFileTimes;
}

/**
* This flag tells the selector to ignore contents
* @param ignoreContents if true ignore contents
* @since ant 1.6.3
*/
public void setIgnoreContents(boolean ignoreContents) {
this.ignoreContents = ignoreContents;
}
/**
* this test is our selection test that compared the file with the destfile
* @param srcfile the source file
@@ -86,13 +98,16 @@ public class DifferentSelector extends MappingSelector {
return true;
}
}

//here do a bulk comparison
try {
return !fileUtils.contentEquals(srcfile, destfile);
} catch (IOException e) {
throw new BuildException("while comparing " + srcfile + " and "
+ destfile, e);
if (!ignoreContents) {
//here do a bulk comparison
try {
return !fileUtils.contentEquals(srcfile, destfile);
} catch (IOException e) {
throw new BuildException("while comparing " + srcfile + " and "
+ destfile, e);
}
} else {
return false;
}
}
}

Loading…
Cancel
Save