You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2010/01/22 06:14:16 UTC
svn commit: r902000 - in /ant/core/trunk: WHATSNEW
src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml
Author: bodewig
Date: Fri Jan 22 05:14:15 2010
New Revision: 902000
URL: http://svn.apache.org/viewvc?rev=902000&view=rev
Log:
don't add the same comment over and over again. Related to PR 48558
Modified:
ant/core/trunk/WHATSNEW
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=902000&r1=901999&r2=902000&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jan 22 05:14:15 2010
@@ -20,6 +20,10 @@
* <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:
--------------
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=902000&r1=901999&r2=902000&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:14:15 2010
@@ -259,8 +259,14 @@
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) {
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=902000&r1=901999&r2=902000&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:14:15 2010
@@ -26,13 +26,16 @@
#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 @@
</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 @@
<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>