Author: mbenson
Date: Thu Feb 25 00:06:04 2010
New Revision: 916051
URL: http://svn.apache.org/viewvc?rev=916051&view=rev
Log:
add prefix attribute to loadproperties task + more tests
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/CoreTasks/loadproperties.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java
ant/core/trunk/src/tests/antunit/taskdefs/loadproperties-test.xml
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=916051&r1=916050&r2=916051&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Feb 25 00:06:04 2010
@@ -52,7 +52,9 @@
Bugzilla Report 48755.
* Add removeKeepExtension option to NetRexxC task.
- Bugzilla Report 48788.
+ Bugzilla Report 48788.
+
+ * Add prefix attribute to loadproperties task.
Changes from Ant 1.8.0RC1 TO Ant 1.8.0
======================================
Modified: ant/core/trunk/docs/manual/CoreTasks/loadproperties.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/loadproperties.html?rev=916051&r1=916050&r2=916051&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/loadproperties.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/loadproperties.html Thu Feb 25
00:06:04 2010
@@ -72,6 +72,12 @@
to a <code><path></code> defined elsewhere..</td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">prefix</td>
+ <td valign="top">Prefix to apply to loaded properties;
+ a "." is appended to the prefix if not specified. <em>Since Ant
1.8.1</em></td>
+ <td align="center" valign="top">No</td>
+ </tr>
</table>
<h3>Parameters specified as nested elements</h3>
@@ -124,4 +130,3 @@
</body>
</html>
-
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java?rev=916051&r1=916050&r2=916051&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java
Thu Feb 25 00:06:04 2010
@@ -60,6 +60,11 @@
* Encoding to use for input; defaults to the platform's default encoding.
*/
private String encoding = null;
+
+ /**
+ * Prefix for loaded properties.
+ */
+ private String prefix = null;
/**
* Set the file to load.
@@ -128,6 +133,14 @@
}
/**
+ * Set the prefix to load these properties under.
+ * @param prefix to set
+ */
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
* load Ant properties from the source file or resource
*
* @exception BuildException if something goes wrong with the build
@@ -174,6 +187,7 @@
Property propertyTask = new Property();
propertyTask.bindToOwner(this);
+ propertyTask.setPrefix(prefix);
propertyTask.addProperties(props);
}
} catch (final IOException ioe) {
Modified: ant/core/trunk/src/tests/antunit/taskdefs/loadproperties-test.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/loadproperties-test.xml?rev=916051&r1=916050&r2=916051&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/loadproperties-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/loadproperties-test.xml Thu Feb
25 00:06:04 2010
@@ -97,6 +97,50 @@
value="http://${server1.http.server}:${server1.http.port}"/>
</target>
+ <target name="testLineCommentsWithoutFiltering">
+ <loadproperties>
+ <string value="#foo=bar" />
+ </loadproperties>
+ <au:assertFalse>
+ <isset property="foo" />
+ </au:assertFalse>
+ </target>
+
+ <target name="testPrefixAttributeProperties">
+ <loadproperties prefix="prefixFromAttribute.">
+ <string>foo=foo
+bar=bar
+baz=${foo} ${bar}
+ </string>
+ </loadproperties>
+ <au:assertTrue>
+ <and>
+ <equals arg1="foo" arg2="${prefixFromAttribute.foo}" />
+ <equals arg1="bar" arg2="${prefixFromAttribute.bar}" />
+ <equals arg1="foo bar" arg2="${prefixFromAttribute.baz}" />
+ </and>
+ </au:assertTrue>
+ </target>
+
+ <target name="testSelfContainedPrefixFilterFailure"
+ description="Show why the prefix attribute is needed">
+ <loadproperties>
+ <string>foo=foo
+bar=bar
+baz=${foo} ${bar}
+ </string>
+ <filterchain>
+ <prefixlines prefix="prefixFromFilter." />
+ </filterchain>
+ </loadproperties>
+ <au:assertTrue>
+ <and>
+ <equals arg1="$${foo} $${bar}" arg2="${prefixFromFilter.baz}" />
+ <isset property="prefixFromFilter." />
+ </and>
+ </au:assertTrue>
+ </target>
+
<target name="write properties.tmp" depends="setUp">
<echo file="${properties.tmp}">
#tpfr.a=a