ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r902004 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/util/DateUtils.java src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml
Date Fri, 22 Jan 2010 05:40:58 GMT
Author: bodewig
Date: Fri Jan 22 05:40:57 2010
New Revision: 902004

URL: http://svn.apache.org/viewvc?rev=902004&view=rev
Log:
Don't add new Date comments each time the file is written.  PR 48558

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
    ant/core/trunk/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=902004&r1=902003&r2=902004&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jan 22 05:40:57 2010
@@ -20,8 +20,8 @@
  * <scp> task didn't report build file location when a remote operation failed
    Bugzilla Report 48578.  
 
- * <propertyfile> would add the same comment each time it updated an
-   existing property file.
+ * <propertyfile> would add the same comment and a date line each time
+   it updated an existing property file.
    Bugzilla Report 48558.
 
 Other changes:

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java?rev=902004&r1=902003&r2=902004&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/DateUtils.java Fri Jan 22 05:40:57 2010
@@ -233,6 +233,22 @@
     }
 
     /**
+     * Parses the string in a format suitable for a SMTP date header.
+     *
+     * @param datestr string to be parsed
+     *
+     * @return a java.util.Date object as parsed by the format.
+     * @exception ParseException if the supplied string cannot be parsed by
+     * this pattern.
+     * @since Ant 1.8.0
+     */
+    public static Date parseDateFromHeader(String datestr) throws ParseException {
+        synchronized (DATE_HEADER_FORMAT_INT) {
+            return DATE_HEADER_FORMAT_INT.parse(datestr);
+        }
+    }
+
+    /**
      * Parse a string as a datetime using the ISO8601_DATETIME format which is
      * <code>yyyy-MM-dd'T'HH:mm:ss</code>
      *

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java?rev=902004&r1=902003&r2=902004&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java Fri
Jan 22 05:40:57 2010
@@ -253,20 +253,38 @@
     public void store(OutputStream out, String header) throws IOException {
         OutputStreamWriter osw = new OutputStreamWriter(out, "ISO-8859-1");
 
+        int skipLines = 0;
+        int totalLines = logicalLines.size();
+
         if (header != null) {
             osw.write("#" + header + LS);
+            if (totalLines > 0
+                && logicalLines.get(0) instanceof Comment
+                && header.equals(logicalLines.get(0).toString().substring(1))) {
+                skipLines = 1;
+            }
         }
-        osw.write("#" + (new Date()).toString() + LS);
+
+        // we may be updatiung a file written by this class, replace
+        // the date comment instead of adding a new one and preserving
+        // the one written last time
+        if (totalLines > skipLines
+            && logicalLines.get(skipLines) instanceof Comment) {
+            try {
+                DateUtils.parseDateFromHeader(logicalLines
+                                              .get(skipLines)
+                                              .toString().substring(1));
+                skipLines++;
+            } catch (java.text.ParseException pe) {
+                // not an existing date comment
+            }
+        }
+        osw.write("#" + DateUtils.getDateForHeader() + LS);
 
         boolean writtenSep = false;
-        boolean maySkipComment = header != null;
-        for (Iterator i = logicalLines.iterator(); i.hasNext();
-             maySkipComment = false) {
+        for (Iterator i = logicalLines.subList(skipLines, totalLines).iterator();
+             i.hasNext(); ) {
             LogicalLine line = (LogicalLine) i.next();
-            if (maySkipComment && line instanceof Comment && 
-                header.equals(line.toString().substring(1))) {
-                continue;
-            }
             if (line instanceof Pair) {
                 if (((Pair)line).isNew()) {
                     if (!writtenSep) {

Modified: ant/core/trunk/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml?rev=902004&r1=902003&r2=902004&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml Fri Jan
22 05:40:57 2010
@@ -190,4 +190,54 @@
     <au:assertPropertyEquals name="tail.out" value="${tail.in}"/>
   </target>
 
+  <target name="testRepeatedUpdateWithoutComment" depends="-updateSetUp">
+    <pf/>
+    <pf/>
+    <local name="head.in"/>
+    <local name="head.out"/>
+    <loadfile srcfile="${input}/initial.properties" property="head.in"/>
+    <!-- skip date -->
+    <loadfile srcfile="${output}/created.properties" property="head.out">
+      <filterchain>
+        <headfilter skip="1"/>
+      </filterchain>
+    </loadfile>
+    <au:assertPropertyEquals name="head.out" value="${head.in}"/>
+  </target>
+
+  <target name="testRepeatedUpdateWithSameComment" depends="-updateSetUp">
+    <pf comment="my comment"/>
+    <pf comment="my comment"/>
+    <local name="head.in"/>
+    <local name="head.out"/>
+    <local name="tail.in"/>
+    <local name="tail.out"/>
+    <!-- just comment -->
+    <loadfile srcfile="${input}/initial.properties" property="head.in">
+      <filterchain>
+        <headfilter lines="1"/>
+      </filterchain>
+    </loadfile>
+    <!-- just comment -->
+    <loadfile srcfile="${output}/created.properties" property="head.out">
+      <filterchain>
+        <headfilter lines="1"/>
+      </filterchain>
+    </loadfile>
+    <!-- skip comment -->
+    <loadfile srcfile="${input}/initial.properties" property="tail.in">
+      <filterchain>
+        <headfilter skip="1"/>
+      </filterchain>
+    </loadfile>
+    <!-- skip comment and date -->
+    <loadfile srcfile="${output}/created.properties" property="tail.out">
+      <filterchain>
+        <headfilter skip="2"/>
+      </filterchain>
+    </loadfile>
+    <au:assertPropertyEquals name="head.out" value="${head.in}"/>
+    <au:assertPropertyEquals name="tail.out" value="${tail.in}"/>
+  </target>
+
 </project>



Mime
View raw message