to access nested elements before they have been configured. PR: 9056 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273381 13f79535-47bb-0310-9956-ffa450edef68master
@@ -42,6 +42,8 @@ Fixed bugs: | |||||
* <property environment=... /> now works on OS/400. | * <property environment=... /> now works on OS/400. | ||||
* <filterset> nested into <filterset>s didn't work. | |||||
Other changes: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -14,9 +14,14 @@ or be read in from a file. FilterSets can appear inside tasks that support this | |||||
feature or at the same level as <CODE><target></CODE> - i.e., as | feature or at the same level as <CODE><target></CODE> - i.e., as | ||||
children of | children of | ||||
<CODE><project></CODE>.</P> | <CODE><project></CODE>.</P> | ||||
<P>FilterSets support the <code>id</code> and <code>refid</code> attributes. | |||||
You can define a FilterSet with an <code>id</code> attribute and then refer | |||||
to that definition from another FilterSet with a <code>refid</code> attribute. | |||||
<p>FilterSets support the <code>id</code> and <code>refid</code> | |||||
attributes. You can define a FilterSet with an <code>id</code> | |||||
attribute and then refer to that definition from another FilterSet | |||||
with a <code>refid</code> attribute. It is also possible to nest | |||||
filtersets into filtersets to get a set union of the contained | |||||
filters.</p> | |||||
<p>In addition, FilterSets can specify | <p>In addition, FilterSets can specify | ||||
<code>begintoken</code> and/or | <code>begintoken</code> and/or | ||||
<code>endtoken</code> attributes to define what to match.</p> | <code>endtoken</code> attributes to define what to match.</p> | ||||
@@ -31,6 +31,23 @@ | |||||
</copy> | </copy> | ||||
</target> | </target> | ||||
<target name="test-nested-filtersets"> | |||||
<filterset id="1"> | |||||
<filter token="token1" value="value1"/> | |||||
</filterset> | |||||
<filterset id="2"> | |||||
<filterset refid="testset.one"/> | |||||
</filterset> | |||||
<filterset id="3"> | |||||
<filterset id="4"> | |||||
<filter token="token4" value="value4"/> | |||||
</filterset> | |||||
</filterset> | |||||
<filterset id="5"> | |||||
<filterset refid="1"/> | |||||
</filterset> | |||||
</target> | |||||
<target name="cleanup"> | <target name="cleanup"> | ||||
<delete file="dest1.txt" quiet="true" /> | <delete file="dest1.txt" quiet="true" /> | ||||
<delete file="dest2.txt" quiet="true" /> | <delete file="dest2.txt" quiet="true" /> | ||||
@@ -467,7 +467,7 @@ public class FilterSet extends DataType implements Cloneable { | |||||
* | * | ||||
* @param filterSet the filterset to be added to this filterset | * @param filterSet the filterset to be added to this filterset | ||||
*/ | */ | ||||
public void addFilterSet(FilterSet filterSet) { | |||||
public void addConfiguredFilterSet(FilterSet filterSet) { | |||||
if (isReference()) { | if (isReference()) { | ||||
throw noChildrenAllowed(); | throw noChildrenAllowed(); | ||||
} | } | ||||
@@ -62,6 +62,7 @@ import junit.framework.TestCase; | |||||
import junit.framework.AssertionFailedError; | import junit.framework.AssertionFailedError; | ||||
import java.io.*; | import java.io.*; | ||||
import java.util.Hashtable; | |||||
/** | /** | ||||
* FilterSet testing | * FilterSet testing | ||||
@@ -109,7 +110,6 @@ public class FilterSetTest extends BuildFileTest { | |||||
* actually resolve. | * actually resolve. | ||||
*/ | */ | ||||
public void testRecursive() { | public void testRecursive() { | ||||
System.out.println("testRecursive"); | |||||
String result = "it works line"; | String result = "it works line"; | ||||
String line="@test@ line"; | String line="@test@ line"; | ||||
FilterSet fs = new FilterSet(); | FilterSet fs = new FilterSet(); | ||||
@@ -126,7 +126,6 @@ public class FilterSetTest extends BuildFileTest { | |||||
* infinite loop. | * infinite loop. | ||||
*/ | */ | ||||
public void testInfinite() { | public void testInfinite() { | ||||
System.out.println("testInfinite"); | |||||
String result = "@test@ line testvalue"; | String result = "@test@ line testvalue"; | ||||
String line = "@test@ line @test3@"; | String line = "@test@ line @test3@"; | ||||
FilterSet fs = new FilterSet(); | FilterSet fs = new FilterSet(); | ||||
@@ -139,6 +138,31 @@ public class FilterSetTest extends BuildFileTest { | |||||
assertEquals(result, fs.replaceTokens(line)); | assertEquals(result, fs.replaceTokens(line)); | ||||
} | } | ||||
public void testNestedFilterSets() { | |||||
executeTarget("test-nested-filtersets"); | |||||
FilterSet fs = (FilterSet) getProject().getReference("1"); | |||||
Hashtable filters = fs.getFilterHash(); | |||||
assertEquals(1, filters.size()); | |||||
assertEquals("value1", filters.get("token1")); | |||||
fs = (FilterSet) getProject().getReference("2"); | |||||
filters = fs.getFilterHash(); | |||||
assertEquals(2, filters.size()); | |||||
assertEquals("1111", filters.get("aaaa")); | |||||
assertEquals("2222", filters.get("bbbb")); | |||||
fs = (FilterSet) getProject().getReference("3"); | |||||
filters = fs.getFilterHash(); | |||||
assertEquals(1, filters.size()); | |||||
assertEquals("value4", filters.get("token4")); | |||||
fs = (FilterSet) getProject().getReference("5"); | |||||
filters = fs.getFilterHash(); | |||||
assertEquals(1, filters.size()); | |||||
assertEquals("value1", filters.get("token1")); | |||||
} | |||||
private boolean compareFiles(String name1, String name2) { | private boolean compareFiles(String name1, String name2) { | ||||
File file1 = new File(name1); | File file1 = new File(name1); | ||||
File file2 = new File(name2); | File file2 = new File(name2); | ||||