Browse Source

filtersets that are nested into filersets don't work as the code tries

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-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
967ec861a2
5 changed files with 54 additions and 6 deletions
  1. +2
    -0
      WHATSNEW
  2. +8
    -3
      docs/manual/CoreTypes/filterset.html
  3. +17
    -0
      src/etc/testcases/types/filterset.xml
  4. +1
    -1
      src/main/org/apache/tools/ant/types/FilterSet.java
  5. +26
    -2
      src/testcases/org/apache/tools/ant/types/FilterSetTest.java

+ 2
- 0
WHATSNEW View File

@@ -42,6 +42,8 @@ Fixed bugs:

* <property environment=... /> now works on OS/400.

* <filterset> nested into <filterset>s didn't work.

Other changes:
--------------



+ 8
- 3
docs/manual/CoreTypes/filterset.html View File

@@ -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>&lt;target&gt;</CODE> - i.e., as
children of
<CODE>&lt;project&gt;</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
<code>begintoken</code> and/or
<code>endtoken</code> attributes to define what to match.</p>


+ 17
- 0
src/etc/testcases/types/filterset.xml View File

@@ -31,6 +31,23 @@
</copy>
</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">
<delete file="dest1.txt" quiet="true" />
<delete file="dest2.txt" quiet="true" />


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

@@ -467,7 +467,7 @@ public class FilterSet extends DataType implements Cloneable {
*
* @param filterSet the filterset to be added to this filterset
*/
public void addFilterSet(FilterSet filterSet) {
public void addConfiguredFilterSet(FilterSet filterSet) {
if (isReference()) {
throw noChildrenAllowed();
}


+ 26
- 2
src/testcases/org/apache/tools/ant/types/FilterSetTest.java View File

@@ -62,6 +62,7 @@ import junit.framework.TestCase;
import junit.framework.AssertionFailedError;

import java.io.*;
import java.util.Hashtable;

/**
* FilterSet testing
@@ -109,7 +110,6 @@ public class FilterSetTest extends BuildFileTest {
* actually resolve.
*/
public void testRecursive() {
System.out.println("testRecursive");
String result = "it works line";
String line="@test@ line";
FilterSet fs = new FilterSet();
@@ -126,7 +126,6 @@ public class FilterSetTest extends BuildFileTest {
* infinite loop.
*/
public void testInfinite() {
System.out.println("testInfinite");
String result = "@test@ line testvalue";
String line = "@test@ line @test3@";
FilterSet fs = new FilterSet();
@@ -139,6 +138,31 @@ public class FilterSetTest extends BuildFileTest {
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) {
File file1 = new File(name1);
File file2 = new File(name2);


Loading…
Cancel
Save