ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: Can I strip lines using a FilterReader (opposite of Linecontains)
Date Wed, 17 Sep 2003 15:24:59 GMT
You will need to write a custom filter.

If you are using ant 1.6 (nighty build) it
is fairly easy to write your custom filter:

FilterNotContains:

package org.acme;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.filters.TokenFilter;

public class FilterNotContains
    extends TokenFilter.ChainableReaderFilter {

    private String notContains;

    public void setString(String notContains) {
        this.notContains = notContains;
    }

    public String filter(String input) {
        if (notContains == null) {
            throw new BuildException(
                "Missing attribute \"string\"");
        }
        if (input.indexOf(notContains) == -1) {
            return input;
        } else {
            return null;
        }
    }
}

build.xml:
  <target name="notcontains">
    <mkdir dir="classes"/>
    <javac srcdir="src" destdir="classes"/>
    <typedef name="filter.notcontains"
             classname="org.acme.FilterNotContains"
             classpath="classes"/>
    <concat>
      This is some text
      This line should be ignored
      <filterchain>
        <filter.notcontains string="be ignored"/>
      </filterchain>
    </concat>
  </target>

Peter.
On Wednesday 17 September 2003 14:43, mark stephens wrote:
> Hi,
>
> I am trying to use A FilterReader to remove certain lines from the
> source code (ie line containing '/**Java1.4 only*/' are removed so I can
> compile for just 1.3).
>
> What I really want is the opposite of <linecontains> but I can't see how
> to use this as a not contains. Any advice please?
>
> Regards,
>
> MArk
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message