diff --git a/WHATSNEW b/WHATSNEW index 0fd37f8f1..ee7bb12f3 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -20,6 +20,10 @@ Fixed bugs: * task didn't report build file location when a remote operation failed Bugzilla Report 48578. + * would add the same comment each time it updated an + existing property file. + Bugzilla Report 48558. + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java b/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java index 6d29c7264..a0650795d 100644 --- a/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java +++ b/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java @@ -259,8 +259,14 @@ public class LayoutPreservingProperties extends Properties { osw.write("#" + (new Date()).toString() + LS); boolean writtenSep = false; - for (Iterator i = logicalLines.iterator(); i.hasNext();) { + boolean maySkipComment = header != null; + for (Iterator i = logicalLines.iterator(); i.hasNext(); + maySkipComment = false) { 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) { diff --git a/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml b/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml index c5fff7bfe..cc9b2c441 100644 --- a/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml +++ b/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml @@ -26,13 +26,16 @@ foo=bar #second comment x=1 ]]> + + + + + + - - - - + @@ -64,10 +67,7 @@ x=1 - - - - + @@ -113,4 +113,81 @@ x=1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +