Browse Source

Bug 51044 - Allow a <propertyset> in an <expandproperties> filter

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1090431 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 14 years ago
parent
commit
314d4d7ba7
4 changed files with 93 additions and 1 deletions
  1. +4
    -0
      WHATSNEW
  2. +16
    -0
      manual/Types/filterchain.html
  3. +35
    -1
      src/main/org/apache/tools/ant/filters/ExpandProperties.java
  4. +38
    -0
      src/tests/antunit/filters/expandproperties-test.xml

+ 4
- 0
WHATSNEW View File

@@ -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
===================================



+ 16
- 0
manual/Types/filterchain.html View File

@@ -273,6 +273,22 @@ Convenience method:
&lt;/loadfile&gt;
</pre></blockquote>

<p>As of Ant <strong>1.8.3</strong>, a nested
<a href="propertyset.html">PropertySet</a> can be specified:

<blockquote><pre>
&lt;property name=&quot;weather&quot; value=&quot;rain&quot;/&gt;
&lt;loadfile property=&quot;modifiedmessage&quot; srcFile=&quot;loadfile1.tmp&quot;&gt;
&lt;filterchain&gt;
&lt;expandproperties&gt;
&lt;propertyset&gt;
&lt;propertyref name="weather" /&gt;
&lt;/propertyset&gt;
&lt;/expandproperties&gt;
&lt;/filterchain&gt;
&lt;/loadfile&gt;
</pre></blockquote>

<h3><a name="headfilter">HeadFilter</a></h3>

This filter reads the first few lines from the data supplied to it.


+ 35
- 1
src/main/org/apache/tools/ant/filters/ExpandProperties.java View File

@@ -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;
}
}

+ 38
- 0
src/tests/antunit/filters/expandproperties-test.xml View File

@@ -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>

Loading…
Cancel
Save