Browse Source

don't add the same comment over and over again. Related to PR 48558

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@902000 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
a9f17b8762
3 changed files with 96 additions and 9 deletions
  1. +4
    -0
      WHATSNEW
  2. +7
    -1
      src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
  3. +85
    -8
      src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml

+ 4
- 0
WHATSNEW View File

@@ -20,6 +20,10 @@ Fixed bugs:
* <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.
Bugzilla Report 48558.

Other changes:
--------------



+ 7
- 1
src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java View File

@@ -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) {


+ 85
- 8
src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml View File

@@ -26,13 +26,16 @@ foo=bar
#second comment
x=1
]]></echo>
<presetdef name="pf">
<propertyfile file="${output}/created.properties">
<entry key="foo" value="bar"/>
<entry key="x" value="1" type="int"/>
</propertyfile>
</presetdef>
</target>

<target name="testCreateWithoutComment" depends="setUp">
<propertyfile file="${output}/created.properties">
<entry key="foo" value="bar"/>
<entry key="x" value="1" type="int"/>
</propertyfile>
<pf/>
<local name="head.in"/>
<local name="head.out"/>
<local name="tail.in"/>
@@ -64,10 +67,7 @@ x=1
</target>

<target name="testCreateWithComment" depends="setUp">
<propertyfile file="${output}/created.properties" comment="my comment">
<entry key="foo" value="bar"/>
<entry key="x" value="1" type="int"/>
</propertyfile>
<pf comment="my comment"/>
<local name="head.in"/>
<local name="head.out"/>
<local name="middle.in"/>
@@ -113,4 +113,81 @@ x=1
<au:assertPropertyEquals name="tail.out" value="${tail.in}"/>
</target>

<target name="-updateSetUp" depends="setUp">
<copy file="${input}/initial.properties"
tofile="${output}/created.properties"/>
</target>

<target name="testUpdateWithoutComment" depends="-updateSetUp">
<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="testUpdateWithNewComment" depends="-updateSetUp">
<pf comment="new comment"/>
<local name="head.in"/>
<local name="head.out"/>
<local name="tail.in"/>
<local name="tail.out"/>
<property name="head.in" value="#new comment${line.separator}"/>
<!-- just comment -->
<loadfile srcfile="${output}/created.properties" property="head.out">
<filterchain>
<headfilter lines="1"/>
</filterchain>
</loadfile>
<loadfile srcfile="${input}/initial.properties" property="tail.in"/>
<!-- skip new 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>

<target name="testUpdateWithSameComment" depends="-updateSetUp">
<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>

Loading…
Cancel
Save