diff --git a/WHATSNEW b/WHATSNEW
index ada6b42af..bd6725b5d 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -52,6 +52,10 @@ Other changes:
* The concat task now permits the name of its exposed resource
by means of its 'resourcename' attribute.
+ * The expandproperties filter now accepts a nested propertyset
+ which, if specified, provides the properties for expansion.
+ Bugzilla Report 51044.
+
Changes from Ant 1.8.1 TO Ant 1.8.2
===================================
diff --git a/manual/Types/filterchain.html b/manual/Types/filterchain.html
index b9f893ad8..0a06c7155 100644
--- a/manual/Types/filterchain.html
+++ b/manual/Types/filterchain.html
@@ -273,6 +273,22 @@ Convenience method:
</loadfile>
+
As of Ant 1.8.3, a nested
+ PropertySet can be specified:
+
+
+<property name="weather" value="rain"/>
+<loadfile property="modifiedmessage" srcFile="loadfile1.tmp">
+ <filterchain>
+ <expandproperties>
+ <propertyset>
+ <propertyref name="weather" />
+ </propertyset>
+ </expandproperties>
+ </filterchain>
+</loadfile>
+
+
This filter reads the first few lines from the data supplied to it.
diff --git a/src/main/org/apache/tools/ant/filters/ExpandProperties.java b/src/main/org/apache/tools/ant/filters/ExpandProperties.java
index a07ce5b6e..443c6b3f1 100644
--- a/src/main/org/apache/tools/ant/filters/ExpandProperties.java
+++ b/src/main/org/apache/tools/ant/filters/ExpandProperties.java
@@ -19,7 +19,14 @@ package org.apache.tools.ant.filters;
import java.io.IOException;
import java.io.Reader;
+import java.util.Properties;
+
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.PropertyHelper;
+import org.apache.tools.ant.property.GetProperty;
+import org.apache.tools.ant.property.ParseProperties;
+import org.apache.tools.ant.types.PropertySet;
/**
* Expands Ant properties, if any, in the data.
@@ -34,8 +41,10 @@ import org.apache.tools.ant.Project;
public final class ExpandProperties
extends BaseFilterReader
implements ChainableReader {
+
/** Data that must be read from, if not null. */
private String queuedData = null;
+ private PropertySet propertySet;
/**
* Constructor for "dummy" instances.
@@ -56,6 +65,17 @@ public final class ExpandProperties
super(in);
}
+ /**
+ * Restrict the expanded properties using a PropertySet.
+ * @param propertySet replacement lookup
+ */
+ public void add(PropertySet propertySet) {
+ if (this.propertySet != null) {
+ throw new BuildException("expandproperties filter accepts only one propertyset");
+ }
+ this.propertySet = propertySet;
+ }
+
/**
* Returns the next character in the filtered stream. The original
* stream is first read in fully, and the Ant properties are expanded.
@@ -88,7 +108,20 @@ public final class ExpandProperties
ch = -1;
} else {
Project project = getProject();
- queuedData = project.replaceProperties(queuedData);
+ GetProperty getProperty;
+ if (propertySet == null) {
+ getProperty = PropertyHelper.getPropertyHelper(project);
+ } else {
+ final Properties props = propertySet.getProperties();
+ getProperty = new GetProperty() {
+
+ public Object getProperty(String name) {
+ return props.getProperty(name);
+ }
+ };
+ }
+ queuedData = new ParseProperties(project, PropertyHelper.getPropertyHelper(project)
+ .getExpanders(), getProperty).parseProperties(queuedData).toString();
return read();
}
}
@@ -108,6 +141,7 @@ public final class ExpandProperties
public Reader chain(final Reader rdr) {
ExpandProperties newFilter = new ExpandProperties(rdr);
newFilter.setProject(getProject());
+ newFilter.add(propertySet);
return newFilter;
}
}
diff --git a/src/tests/antunit/filters/expandproperties-test.xml b/src/tests/antunit/filters/expandproperties-test.xml
index 0d8bafc1f..44195fe3c 100644
--- a/src/tests/antunit/filters/expandproperties-test.xml
+++ b/src/tests/antunit/filters/expandproperties-test.xml
@@ -36,4 +36,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+