Browse Source

<replace> shouldn't change the timestamp of files if it doesn't

actually replace anything.
Submitted by:	Scotte Zinn <szinn@patronix.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267980 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
77959a23ae
1 changed files with 16 additions and 7 deletions
  1. +16
    -7
      src/main/org/apache/tools/ant/taskdefs/Replace.java

+ 16
- 7
src/main/org/apache/tools/ant/taskdefs/Replace.java View File

@@ -154,17 +154,26 @@ public class Replace extends MatchingTask {
String val = stringReplace(value.getText(), "\n", linesep); String val = stringReplace(value.getText(), "\n", linesep);
String tok = stringReplace(token.getText(), "\n", linesep); String tok = stringReplace(token.getText(), "\n", linesep);


// for each found token, replace with value and write to the
// output file
buf = stringReplace(buf, tok, val);
bw.write(buf,0,buf.length());
bw.flush();
// for each found token, replace with value
String newString = stringReplace(buf, tok, val);
boolean changes = !newString.equals(buf);

if (changes) {
bw.write(newString,0,newString.length());
bw.flush();
}
// cleanup // cleanup
bw.close(); bw.close();
br.close(); br.close();
src.delete();
temp.renameTo(src);

// If there were changes, move the new one to the old one, otherwise, delete the new one
if (changes) {
src.delete();
temp.renameTo(src);
} else {
temp.delete();
}
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
throw new BuildException(ioe, location); throw new BuildException(ioe, location);


Loading…
Cancel
Save