ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject cvs commit: ant/src/etc/testcases/taskdefs/optional replaceregexp.xml
Date Thu, 21 Aug 2003 19:42:15 GMT
antoine     2003/08/21 12:42:15

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/taskdefs/optional
                        ReplaceRegExp.java
               src/testcases/org/apache/tools/ant/taskdefs/optional
                        ReplaceRegExpTest.java
               src/etc/testcases/taskdefs/optional replaceregexp.xml
  Log:
  Avoid altering unnecessarily the timestamps of the directories of the
  files processed by replaceregexp
  PR: 22541
  
  Revision  Changes    Path
  1.489     +4 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.488
  retrieving revision 1.489
  diff -u -r1.488 -r1.489
  --- WHATSNEW	21 Aug 2003 16:56:11 -0000	1.488
  +++ WHATSNEW	21 Aug 2003 19:42:15 -0000	1.489
  @@ -143,6 +143,10 @@
   * <replaceregexp> didn't work for multi-byte encodings if byline was false.
     Bugzilla Report 19187.
   
  +* <replaceregexp> was altering unnecessarily the timestamp of the directories
  +  containing the files to process
  +  Bugzilla Report 22541.
  +
   * file names that include spaces need to be quoted inside the @argfile
     argument using forked <javac> and (all JDKS).  Bugzilla Report 10499.
     NB : a first correction was only introducing quotes for JDK 1.4
  
  
  
  1.26      +1 -2      ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
  
  Index: ReplaceRegExp.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ReplaceRegExp.java	19 Jul 2003 11:20:15 -0000	1.25
  +++ ReplaceRegExp.java	21 Aug 2003 19:42:15 -0000	1.26
  @@ -317,8 +317,7 @@
       /** Perform the replace on the entire file  */
       protected void doReplace(File f, int options)
            throws IOException {
  -        File parentDir = fileUtils.getParentFile(f);
  -        File temp = fileUtils.createTempFile("replace", ".txt", parentDir);
  +        File temp = fileUtils.createTempFile("replace", ".txt", null);
   
           Reader r = null;
           FileWriter w = null;
  
  
  
  1.7       +19 -10    ant/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
  
  Index: ReplaceRegExpTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ReplaceRegExpTest.java	7 Mar 2003 11:23:12 -0000	1.6
  +++ ReplaceRegExpTest.java	21 Aug 2003 19:42:15 -0000	1.7
  @@ -68,13 +68,13 @@
    * @version $Revision$
    */
   public class ReplaceRegExpTest extends BuildFileTest {
  -
  +    private static final String PROJECT_PATH = "src/etc/testcases/taskdefs/optional";
       public ReplaceRegExpTest(String name) {
           super(name);
       }
       
       public void setUp() { 
  -        configureProject("src/etc/testcases/taskdefs/optional/replaceregexp.xml");
  +        configureProject(PROJECT_PATH + "/replaceregexp.xml");
       }
       
       public void tearDown() { 
  @@ -85,7 +85,7 @@
           Properties original = new Properties();
           FileInputStream propsFile = null;
           try {
  -            propsFile = new FileInputStream("src/etc/testcases/taskdefs/optional/replaceregexp.properties");
  +            propsFile = new FileInputStream(PROJECT_PATH + "/replaceregexp.properties");
               original.load(propsFile);
           } finally {
               if (propsFile != null) {
  @@ -100,7 +100,7 @@
   
           Properties after = new Properties();
           try {
  -            propsFile = new FileInputStream("src/etc/testcases/taskdefs/optional/test.properties");
  +            propsFile = new FileInputStream(PROJECT_PATH + "/test.properties");
               after.load(propsFile);
           } finally {
               if (propsFile != null) {
  @@ -112,21 +112,30 @@
           assertNull(after.get("OldAbc"));
           assertEquals("AbcDef", after.get("NewProp"));
       }
  -
  +    // inspired by bug 22541
  +    public void testDirectoryDateDoesNotChange() {
  +        executeTarget("touchDirectory");
  +        File myFile = new File(PROJECT_PATH + "/" + getProject().getProperty("tmpregexp"));
  +        long timeStampBefore = myFile.lastModified();
  +        executeTarget("testDirectoryDateDoesNotChange");
  +        long timeStampAfter = myFile.lastModified();
  +        assertEquals("directory date should not change",
  +            timeStampBefore, timeStampAfter);
  +    }
       public void testDontAddNewline1() throws IOException {
           executeTarget("testDontAddNewline1");
           assertTrue("Files match",
                      FileUtils.newFileUtils()
  -                   .contentEquals(new File("src/etc/testcases/taskdefs/optional/test.properties"),
  -                                  new File("src/etc/testcases/taskdefs/optional/replaceregexp2.result.properties")));
  +                   .contentEquals(new File(PROJECT_PATH + "/test.properties"),
  +                                  new File(PROJECT_PATH + "/replaceregexp2.result.properties")));
       }
   
       public void testDontAddNewline2() throws IOException {
           executeTarget("testDontAddNewline2");
           assertTrue("Files match",
                      FileUtils.newFileUtils()
  -                   .contentEquals(new File("src/etc/testcases/taskdefs/optional/test.properties"),
  -                                  new File("src/etc/testcases/taskdefs/optional/replaceregexp2.result.properties")));
  +                   .contentEquals(new File(PROJECT_PATH + "/test.properties"),
  +                                  new File(PROJECT_PATH + "/replaceregexp2.result.properties")));
       }
   
   }// ReplaceRegExpTest
  
  
  
  1.5       +14 -1     ant/src/etc/testcases/taskdefs/optional/replaceregexp.xml
  
  Index: replaceregexp.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/replaceregexp.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- replaceregexp.xml	16 Sep 2002 16:19:29 -0000	1.4
  +++ replaceregexp.xml	21 Aug 2003 19:42:15 -0000	1.5
  @@ -1,5 +1,5 @@
   <project name="test" default="def" basedir=".">
  -
  +  <property name="tmpregexp" value="tmpregexp"/>
     <target name="def">
       <fail>This build file should only be run from within the testcase</fail>
     </target>
  @@ -18,6 +18,18 @@
         <substitution expression="NewProp=\1\2" />
       </replaceregexp>
     </target>
  +  <!-- use in conjunction with testDirectoryDateDoesNotChange to make sure something
will happen -->
  +  <target name="touchDirectory">
  +    <mkdir dir="${tmpregexp}"/>
  +    <copy file="replaceregexp.properties" tofile="${tmpregexp}/test.properties" />
  +    <sleep seconds="2"/>
  +  </target>
  +  <target name="testDirectoryDateDoesNotChange">
  +    <replaceregexp file="${tmpregexp}/test.properties" byline="true">
  +      <regexp pattern="foo" />
  +        <substitution expression="bar"/>
  +      </replaceregexp>
  +  </target>
   
     <target name="testDontAddNewline1" depends="setup-nl">
       <replaceregexp file="test.properties" byline="false">
  @@ -35,6 +47,7 @@
   
     <target name="cleanup">
       <delete file="test.properties" />
  +    <delete dir="${tmpregexp}" quiet="true"/>
     </target>
   
   </project>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message