From 9b8fa0748f63b3fa68ff20eb449699eaf1c6432f Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 5 Dec 2013 17:19:24 +0000 Subject: [PATCH] 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 --- CONTRIBUTORS | 1 + WHATSNEW | 3 ++ contributors.xml | 4 +++ manual/Types/filterset.html | 16 +++++++++ .../org/apache/tools/ant/types/FilterSet.java | 27 ++++++++++++--- src/tests/antunit/types/filterset-test.xml | 33 +++++++++++++++++++ 6 files changed, 80 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 9f184fd0e..172058b3b 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -295,6 +295,7 @@ Raphael Pierquin Ray Waldin Remie Bolte Richard Evans +Richard Steele Rick Beton Robert Anderson Robert Clark diff --git a/WHATSNEW b/WHATSNEW index 7c1920c92..45a3fe70e 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -29,6 +29,9 @@ Other changes: * Addition of 'skipNonTests' attribute to and tasks to allow the tasks to skip classes that don't contain tests. + * now supports a nested to specify filters. + Bugzilla Report 55794. + Changes from Ant 1.9.1 TO Ant 1.9.2 =================================== diff --git a/contributors.xml b/contributors.xml index 06cf723fb..9b663e7b6 100644 --- a/contributors.xml +++ b/contributors.xml @@ -1189,6 +1189,10 @@ Richard Evans + + Richard + Steele + Rick Beton diff --git a/manual/Types/filterset.html b/manual/Types/filterset.html index 0ac198991..8b0dfe185 100644 --- a/manual/Types/filterset.html +++ b/manual/Types/filterset.html @@ -45,6 +45,9 @@ filters.

Filtersets are used for doing replacements in tasks such as <copy>, etc.

+

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

+

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

@@ -181,4 +184,17 @@ but wish to replace the token %DATE* with today's date.

<filterset refid="myFilterSet"/> </copy> + +

You are copying the version.txt file to the dist +directory from the build directory +but wish to replace the token @project.date@ with the property of the same name.

+
+<copy file="${build.dir}/version.txt" toFile="${dist.dir}/version.txt">
+  <filterset>
+    <propertyset>
+      <propertyref name="project.date"/>
+    </propertyset>
+  </filterset>
+</copy>
+
diff --git a/src/main/org/apache/tools/ant/types/FilterSet.java b/src/main/org/apache/tools/ant/types/FilterSet.java index 64ca40825..2ac6eee11 100644 --- a/src/main/org/apache/tools/ant/types/FilterSet.java +++ b/src/main/org/apache/tools/ant/types/FilterSet.java @@ -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> entries = p.entrySet(); + for (Map.Entry 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; } diff --git a/src/tests/antunit/types/filterset-test.xml b/src/tests/antunit/types/filterset-test.xml index 506f3be1a..f1654f6d4 100644 --- a/src/tests/antunit/types/filterset-test.xml +++ b/src/tests/antunit/types/filterset-test.xml @@ -60,4 +60,37 @@ actual="${afterfiltering}"/> + + + + +Filter with property set test +@foo.x@ - should change +@foo.y@ - should change +@bar.x@ - should not change +@cccc@ - should not change + + +Filter with property set test +1111 - should change +2222 - should change +@bar.x@ - should not change +@cccc@ - should not change + + + + + + + + + + + + + +