Browse Source

only add a newline before the first new property rather than every new one

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@901537 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
c2875d3bd8
2 changed files with 117 additions and 0 deletions
  1. +1
    -0
      src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
  2. +116
    -0
      src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml

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

@@ -265,6 +265,7 @@ public class LayoutPreservingProperties extends Properties {
if (((Pair)line).isNew()) {
if (!writtenSep) {
osw.write(LS);
writtenSep = true;
}
}
osw.write(line.toString() + LS);


+ 116
- 0
src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml View File

@@ -0,0 +1,116 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
<import file="../../antunit-base.xml" />

<target name="setUp">
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<echo file="${input}/initial.properties"><![CDATA[#my comment
foo=bar
#second comment
x=1
]]></echo>
</target>

<target name="testCreateWithoutComment" depends="setUp">
<propertyfile file="${output}/created.properties">
<entry key="foo" value="bar"/>
<entry key="x" value="1" type="int"/>
</propertyfile>
<local name="head.in"/>
<local name="head.out"/>
<local name="tail.in"/>
<local name="tail.out"/>
<!-- skip comment -->
<loadfile srcfile="${input}/initial.properties" property="head.in">
<filterchain>
<headfilter lines="1" skip="1"/>
</filterchain>
</loadfile>
<loadfile srcfile="${input}/initial.properties" property="tail.in">
<filterchain>
<tailfilter lines="1"/>
</filterchain>
</loadfile>
<!-- skip date and blank line -->
<loadfile srcfile="${output}/created.properties" property="head.out">
<filterchain>
<headfilter lines="1" skip="2"/>
</filterchain>
</loadfile>
<loadfile srcfile="${output}/created.properties" property="tail.out">
<filterchain>
<tailfilter lines="1"/>
</filterchain>
</loadfile>
<au:assertPropertyEquals name="head.out" value="${head.in}"/>
<au:assertPropertyEquals name="tail.out" value="${tail.in}"/>
</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>
<local name="head.in"/>
<local name="head.out"/>
<local name="middle.in"/>
<local name="middle.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>
<!-- skip comment -->
<loadfile srcfile="${input}/initial.properties" property="middle.in">
<filterchain>
<headfilter lines="1" skip="1"/>
</filterchain>
</loadfile>
<loadfile srcfile="${input}/initial.properties" property="tail.in">
<filterchain>
<tailfilter lines="1"/>
</filterchain>
</loadfile>
<!-- just comment -->
<loadfile srcfile="${output}/created.properties" property="head.out">
<filterchain>
<headfilter lines="1"/>
</filterchain>
</loadfile>
<!-- skip comment, date and blank line -->
<loadfile srcfile="${output}/created.properties" property="middle.out">
<filterchain>
<headfilter lines="1" skip="3"/>
</filterchain>
</loadfile>
<loadfile srcfile="${output}/created.properties" property="tail.out">
<filterchain>
<tailfilter lines="1"/>
</filterchain>
</loadfile>
<au:assertPropertyEquals name="head.out" value="${head.in}"/>
<au:assertPropertyEquals name="middle.out" value="${middle.in}"/>
<au:assertPropertyEquals name="tail.out" value="${tail.in}"/>
</target>

</project>

Loading…
Cancel
Save