Browse Source

Add nested propertyset to filterset. PR 55794. Submitted by Richard Steele

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1548210 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
9b8fa0748f
6 changed files with 80 additions and 4 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +16
    -0
      manual/Types/filterset.html
  5. +23
    -4
      src/main/org/apache/tools/ant/types/FilterSet.java
  6. +33
    -0
      src/tests/antunit/types/filterset-test.xml

+ 1
- 0
CONTRIBUTORS View File

@@ -295,6 +295,7 @@ Raphael Pierquin
Ray Waldin
Remie Bolte
Richard Evans
Richard Steele
Rick Beton
Robert Anderson
Robert Clark


+ 3
- 0
WHATSNEW View File

@@ -29,6 +29,9 @@ Other changes:
* Addition of 'skipNonTests' attribute to <junit> and <batchtest>
tasks to allow the tasks to skip classes that don't contain tests.

* <filterset> now supports a nested <propertyset> to specify filters.
Bugzilla Report 55794.

Changes from Ant 1.9.1 TO Ant 1.9.2
===================================



+ 4
- 0
contributors.xml View File

@@ -1189,6 +1189,10 @@
<first>Richard</first>
<last>Evans</last>
</name>
<name>
<first>Richard</first>
<last>Steele</last>
</name>
<name>
<first>Rick</first>
<last>Beton</last>


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

@@ -45,6 +45,9 @@ filters.</p>
<p>Filtersets are used for doing
replacements in tasks such as <code>&lt;copy&gt;</code>, etc.</p>

<p>Filters can also by specified by one or more nested propertysets, the
contents of which are applied when the filterset is created.</p>

<p>If you specify multiple values for the same token, the last one
defined within a filterset will be used.</p>

@@ -181,4 +184,17 @@ but wish to replace the token <code>%DATE*</code> with today's date.</p>
&lt;filterset refid=&quot;myFilterSet&quot;/&gt;
&lt;/copy&gt;
</pre></blockquote>

<p>You are copying the <code>version.txt</code> file to the <code>dist</code>
directory from the <code>build</code> directory
but wish to replace the token <code>&#64;project.date&#64;</code> with the property of the same name.</p>
<blockquote><pre>
&lt;copy file=&quot;${build.dir}/version.txt&quot; toFile=&quot;${dist.dir}/version.txt&quot;&gt;
&lt;filterset&gt;
&lt;propertyset&gt;
&lt;propertyref name=&quot;project.date&quot;/&gt;
&lt;/propertyset&gt;
&lt;/filterset&gt;
&lt;/copy&gt;
</pre></blockquote>
</body></html>

+ 23
- 4
src/main/org/apache/tools/ant/types/FilterSet.java View File

@@ -21,7 +21,9 @@ import java.io.File;
import java.io.FileInputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;

import org.apache.tools.ant.Project;
@@ -458,10 +460,27 @@ public class FilterSet extends DataType implements Cloneable {
}

/**
* Test to see if this filter set has filters.
*
* @return Return true if there are filters in this set.
*/
* Adds the properties provided by the specified PropertySet to this filterset.
*
* @param propertySet the propertyset to be added to this propertyset
*/
public synchronized void addConfiguredPropertySet(PropertySet propertySet) {
if (isReference()) {
throw noChildrenAllowed();
}
Properties p = propertySet.getProperties();
Set<Map.Entry<Object,Object>> entries = p.entrySet();
for (Map.Entry<Object, Object> entry : entries) {
addFilter(new Filter(String.valueOf(entry.getKey()),
String.valueOf(entry.getValue())));
}
}

/**
* Test to see if this filter set has filters.
*
* @return Return true if there are filters in this set.
*/
public synchronized boolean hasFilters() {
return getFilters().size() > 0;
}


+ 33
- 0
src/tests/antunit/types/filterset-test.xml View File

@@ -60,4 +60,37 @@
actual="${afterfiltering}"/>
</target>

<target name="testNestedPropertySet">
<mkdir dir="${output}"/>
<mkdir dir="${input}"/>
<echo file="${input}/src.txt">
Filter with property set test
@foo.x@ - should change
@foo.y@ - should change
@bar.x@ - should not change
@cccc@ - should not change
</echo>
<echo file="${output}/expected.txt">
Filter with property set test
1111 - should change
2222 - should change
@bar.x@ - should not change
@cccc@ - should not change
</echo>
<property name="foo.x" value="1111" />
<property name="foo.y" value="2222" />
<copy todir="${output}">
<fileset dir="${input}"/>
<filterset>
<propertyset>
<propertyref prefix="foo." />
</propertyset>
</filterset>
</copy>
<au:assertFilesMatch
actual="${output}/src.txt"
expected="${output}/expected.txt"
/>
</target>

</project>

Loading…
Cancel
Save