From 77959a23ae933d353a9c9e4996ec0c86927892e1 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Mon, 11 Sep 2000 10:45:16 +0000 Subject: [PATCH] shouldn't change the timestamp of files if it doesn't actually replace anything. Submitted by: Scotte Zinn git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267980 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/Replace.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Replace.java b/src/main/org/apache/tools/ant/taskdefs/Replace.java index 1ca611d79..736c969db 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Replace.java +++ b/src/main/org/apache/tools/ant/taskdefs/Replace.java @@ -154,17 +154,26 @@ public class Replace extends MatchingTask { String val = stringReplace(value.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 bw.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) { ioe.printStackTrace(); throw new BuildException(ioe, location);