Browse Source

add prefix attribute to loadproperties task + more tests

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@916051 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 15 years ago
parent
commit
af5bab224e
4 changed files with 67 additions and 2 deletions
  1. +3
    -1
      WHATSNEW
  2. +6
    -1
      docs/manual/CoreTasks/loadproperties.html
  3. +14
    -0
      src/main/org/apache/tools/ant/taskdefs/LoadProperties.java
  4. +44
    -0
      src/tests/antunit/taskdefs/loadproperties-test.xml

+ 3
- 1
WHATSNEW View File

@@ -52,7 +52,9 @@ Other changes:
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
======================================


+ 6
- 1
docs/manual/CoreTasks/loadproperties.html View File

@@ -72,6 +72,12 @@ filter.</p>
to a <code>&lt;path&gt;</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 @@ on the fly and load the contents as Ant properties.

</body>
</html>


+ 14
- 0
src/main/org/apache/tools/ant/taskdefs/LoadProperties.java View File

@@ -60,6 +60,11 @@ public class LoadProperties extends Task {
* 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.
@@ -127,6 +132,14 @@ public class LoadProperties extends Task {
return getRequiredJavaResource().getClasspath();
}

/**
* 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
*
@@ -174,6 +187,7 @@ public class LoadProperties extends Task {

Property propertyTask = new Property();
propertyTask.bindToOwner(this);
propertyTask.setPrefix(prefix);
propertyTask.addProperties(props);
}
} catch (final IOException ioe) {


+ 44
- 0
src/tests/antunit/taskdefs/loadproperties-test.xml View File

@@ -97,6 +97,50 @@ http.@SERVER@ = ${server}
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


Loading…
Cancel
Save