You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@locus.apache.org on 2000/09/11 12:45:17 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Replace.java

bodewig     00/09/11 03:45:16

  Modified:    src/main/org/apache/tools/ant/taskdefs Replace.java
  Log:
  <replace> shouldn't change the timestamp of files if it doesn't
  actually replace anything.
  Submitted by:	Scotte Zinn <sz...@patronix.com>
  
  Revision  Changes    Path
  1.5       +16 -7     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java
  
  Index: Replace.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Replace.java	2000/08/07 14:51:45	1.4
  +++ Replace.java	2000/09/11 10:45:16	1.5
  @@ -154,17 +154,26 @@
               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);