Author: bodewig
Date: Thu Dec  5 17:19:24 2013
New Revision: 1548210

URL: http://svn.apache.org/r1548210
Log:
Add nested propertyset to filterset.  PR 55794.  Submitted by Richard Steele

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/WHATSNEW
    ant/core/trunk/contributors.xml
    ant/core/trunk/manual/Types/filterset.html
    ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java
    ant/core/trunk/src/tests/antunit/types/filterset-test.xml

Modified: ant/core/trunk/CONTRIBUTORS
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=1548210&r1=1548209&r2=1548210&view=diff
==============================================================================
--- ant/core/trunk/CONTRIBUTORS (original)
+++ ant/core/trunk/CONTRIBUTORS Thu Dec  5 17:19:24 2013
@@ -295,6 +295,7 @@ Raphael Pierquin
 Ray Waldin
 Remie Bolte
 Richard Evans
+Richard Steele
 Rick Beton
 Robert Anderson
 Robert Clark

Modified: ant/core/trunk/WHATSNEW
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1548210&r1=1548209&r2=1548210&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Dec  5 17:19:24 2013
@@ -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
 ===================================
 

Modified: ant/core/trunk/contributors.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=1548210&r1=1548209&r2=1548210&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Thu Dec  5 17:19:24 2013
@@ -1190,6 +1190,10 @@
     <last>Evans</last>
   </name>
   <name>
+    <first>Richard</first>
+    <last>Steele</last>
+  </name>
+  <name>
     <first>Rick</first>
     <last>Beton</last>
   </name>

Modified: ant/core/trunk/manual/Types/filterset.html
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/manual/Types/filterset.html?rev=1548210&r1=1548209&r2=1548210&view=diff
==============================================================================
--- ant/core/trunk/manual/Types/filterset.html (original)
+++ ant/core/trunk/manual/Types/filterset.html Thu Dec  5 17:19:24 2013
@@ -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>%DAT
   &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>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java?rev=1548210&r1=1548209&r2=1548210&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java Thu Dec  
5 17:19:24 2013
@@ -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 
     }
 
     /**
-    * 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;
     }

Modified: ant/core/trunk/src/tests/antunit/types/filterset-test.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/filterset-test.xml?rev=1548210&r1=1548209&r2=1548210&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/filterset-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/types/filterset-test.xml Thu Dec  5 
17:19:24 2013
@@ -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
[email protected]@ - should change
[email protected]@ - should change
[email protected]@ - should not change
+@cccc@ - should not change
+    </echo>
+    <echo file="${output}/expected.txt">
+Filter with property set test
+1111 - should change
+2222 - should change
[email protected]@ - 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>


Reply via email to