You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mb...@apache.org on 2011/04/08 22:27:05 UTC
svn commit: r1090431 - in /ant/core/trunk: WHATSNEW
manual/Types/filterchain.html
src/main/org/apache/tools/ant/filters/ExpandProperties.java
src/tests/antunit/filters/expandproperties-test.xml
Author: mbenson
Date: Fri Apr 8 20:27:04 2011
New Revision: 1090431
URL: http://svn.apache.org/viewvc?rev=1090431&view=rev
Log:
Bug 51044 - Allow a <propertyset> in an <expandproperties> filter
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/manual/Types/filterchain.html
ant/core/trunk/src/main/org/apache/tools/ant/filters/ExpandProperties.java
ant/core/trunk/src/tests/antunit/filters/expandproperties-test.xml
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1090431&r1=1090430&r2=1090431&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Apr 8 20:27:04 2011
@@ -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
===================================
Modified: ant/core/trunk/manual/Types/filterchain.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/Types/filterchain.html?rev=1090431&r1=1090430&r2=1090431&view=diff
==============================================================================
--- ant/core/trunk/manual/Types/filterchain.html (original)
+++ ant/core/trunk/manual/Types/filterchain.html Fri Apr 8 20:27:04 2011
@@ -273,6 +273,22 @@ Convenience method:
</loadfile>
</pre></blockquote>
+<p>As of Ant <strong>1.8.3</strong>, a nested
+ <a href="propertyset.html">PropertySet</a> can be specified:
+
+<blockquote><pre>
+<property name="weather" value="rain"/>
+<loadfile property="modifiedmessage" srcFile="loadfile1.tmp">
+ <filterchain>
+ <expandproperties>
+ <propertyset>
+ <propertyref name="weather" />
+ </propertyset>
+ </expandproperties>
+ </filterchain>
+</loadfile>
+</pre></blockquote>
+
<h3><a name="headfilter">HeadFilter</a></h3>
This filter reads the first few lines from the data supplied to it.
Modified: ant/core/trunk/src/main/org/apache/tools/ant/filters/ExpandProperties.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/filters/ExpandProperties.java?rev=1090431&r1=1090430&r2=1090431&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/filters/ExpandProperties.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/filters/ExpandProperties.java Fri Apr 8 20:27:04 2011
@@ -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.
@@ -57,6 +66,17 @@ public final class ExpandProperties
}
/**
+ * 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.
* The results of this expansion are then queued so they can be read
@@ -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;
}
}
Modified: ant/core/trunk/src/tests/antunit/filters/expandproperties-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/filters/expandproperties-test.xml?rev=1090431&r1=1090430&r2=1090431&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/filters/expandproperties-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/filters/expandproperties-test.xml Fri Apr 8 20:27:04 2011
@@ -36,4 +36,42 @@
</au:assertTrue>
</target>
+ <target name="testSubset">
+ <au:assertTrue>
+ <resourcesmatch>
+ <string value="FOO $${bar} BAZ" />
+ <concat>
+ <string value="$${foo} $${bar} $${baz}" />
+ <filterchain>
+ <expandproperties>
+ <propertyset>
+ <propertyref name="foo" />
+ <propertyref name="baz" />
+ </propertyset>
+ </expandproperties>
+ </filterchain>
+ </concat>
+ </resourcesmatch>
+ </au:assertTrue>
+ </target>
+
+ <target name="testMappedPropertySet">
+ <au:assertTrue>
+ <resourcesmatch>
+ <string value="FOO BAR BAZ" />
+ <concat>
+ <string value="$${food} $${bard} $${bazd}" />
+ <filterchain>
+ <expandproperties>
+ <propertyset>
+ <propertyref builtin="all" />
+ <globmapper from="*" to="*d" />
+ </propertyset>
+ </expandproperties>
+ </filterchain>
+ </concat>
+ </resourcesmatch>
+ </au:assertTrue>
+ </target>
+
</project>