Browse Source

Hey, TokenFilters can be used in filterchains with no effort, didn't know that

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@808306 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
9d15809c91
3 changed files with 15 additions and 3 deletions
  1. +2
    -0
      docs/manual/CoreTypes/filterchain.html
  2. +1
    -3
      src/main/org/apache/tools/ant/filters/UniqFilter.java
  3. +12
    -0
      src/tests/antunit/filters/uniq-test.xml

+ 2
- 0
docs/manual/CoreTypes/filterchain.html View File

@@ -1365,6 +1365,8 @@ Delete tabs from lines, trim the lines and removes empty lines.
<p>Suppresses all tokens that match their ancestor token. It is most
useful if combined with a sort filter.</p>

<p>This filter may be used directly within a filterchain.</p>

<h4>Example:</h4>

This suppresses duplicate lines.


+ 1
- 3
src/main/org/apache/tools/ant/filters/UniqFilter.java View File

@@ -26,12 +26,10 @@ package org.apache.tools.ant.filters;
*
* @since Ant 1.8.0
*/
public class UniqFilter implements TokenFilter.Filter {
public class UniqFilter extends TokenFilter.ChainableReaderFilter {

private String lastLine = null;

public UniqFilter() { }

public String filter(String string) {
return lastLine == null || !lastLine.equals(string)
? (lastLine = string) : null;


+ 12
- 0
src/tests/antunit/filters/uniq-test.xml View File

@@ -23,6 +23,18 @@
</target>

<target name="testUniqFilter" depends="setUp">
<copy file="input/uniq.txt"
tofile="${output}/uniq.txt">
<filterchain>
<uniqfilter/>
</filterchain>
</copy>
<au:assertFilesMatch
expected="expected/uniq.txt"
actual="${output}/uniq.txt"/>
</target>

<target name="testUniqTokenFilter" depends="setUp">
<copy file="input/uniq.txt"
tofile="${output}/uniq.txt">
<filterchain>


Loading…
Cancel
Save