git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1548210 13f79535-47bb-0310-9956-ffa450edef68master
@@ -295,6 +295,7 @@ Raphael Pierquin | |||||
Ray Waldin | Ray Waldin | ||||
Remie Bolte | Remie Bolte | ||||
Richard Evans | Richard Evans | ||||
Richard Steele | |||||
Rick Beton | Rick Beton | ||||
Robert Anderson | Robert Anderson | ||||
Robert Clark | Robert Clark | ||||
@@ -29,6 +29,9 @@ Other changes: | |||||
* Addition of 'skipNonTests' attribute to <junit> and <batchtest> | * Addition of 'skipNonTests' attribute to <junit> and <batchtest> | ||||
tasks to allow the tasks to skip classes that don't contain tests. | 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 | Changes from Ant 1.9.1 TO Ant 1.9.2 | ||||
=================================== | =================================== | ||||
@@ -1189,6 +1189,10 @@ | |||||
<first>Richard</first> | <first>Richard</first> | ||||
<last>Evans</last> | <last>Evans</last> | ||||
</name> | </name> | ||||
<name> | |||||
<first>Richard</first> | |||||
<last>Steele</last> | |||||
</name> | |||||
<name> | <name> | ||||
<first>Rick</first> | <first>Rick</first> | ||||
<last>Beton</last> | <last>Beton</last> | ||||
@@ -45,6 +45,9 @@ filters.</p> | |||||
<p>Filtersets are used for doing | <p>Filtersets are used for doing | ||||
replacements in tasks such as <code><copy></code>, etc.</p> | replacements in tasks such as <code><copy></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 | <p>If you specify multiple values for the same token, the last one | ||||
defined within a filterset will be used.</p> | 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> | |||||
<filterset refid="myFilterSet"/> | <filterset refid="myFilterSet"/> | ||||
</copy> | </copy> | ||||
</pre></blockquote> | </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>@project.date@</code> with the property of the same name.</p> | |||||
<blockquote><pre> | |||||
<copy file="${build.dir}/version.txt" toFile="${dist.dir}/version.txt"> | |||||
<filterset> | |||||
<propertyset> | |||||
<propertyref name="project.date"/> | |||||
</propertyset> | |||||
</filterset> | |||||
</copy> | |||||
</pre></blockquote> | |||||
</body></html> | </body></html> |
@@ -21,7 +21,9 @@ import java.io.File; | |||||
import java.io.FileInputStream; | import java.io.FileInputStream; | ||||
import java.util.Enumeration; | import java.util.Enumeration; | ||||
import java.util.Hashtable; | import java.util.Hashtable; | ||||
import java.util.Map; | |||||
import java.util.Properties; | import java.util.Properties; | ||||
import java.util.Set; | |||||
import java.util.Vector; | import java.util.Vector; | ||||
import org.apache.tools.ant.Project; | 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() { | public synchronized boolean hasFilters() { | ||||
return getFilters().size() > 0; | return getFilters().size() > 0; | ||||
} | } | ||||
@@ -60,4 +60,37 @@ | |||||
actual="${afterfiltering}"/> | actual="${afterfiltering}"/> | ||||
</target> | </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> | </project> |