ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types FilterReaderSet.java
Date Wed, 27 Feb 2002 20:41:38 GMT
umagesh     02/02/27 12:41:38

  Modified:    proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters
                        HeadFilter.java LineContains.java PrefixLines.java
                        ReplaceTokens.java StripJavaComments.java
                        StripLineBreaks.java StripLineComments.java
                        TabsToSpaces.java TailFilter.java
               proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types
                        FilterReaderSet.java
  Log:
  1.  Provide a mechanism by which filter readers recognized by Ant's core (FilterreaderSet)
can have a better syntax.
  
  2.  Remove double-quotes from javadoc and replace with "
  
  Revision  Changes    Path
  1.5       +6 -6      jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/HeadFilter.java
  
  Index: HeadFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/HeadFilter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- HeadFilter.java	27 Feb 2002 18:14:11 -0000	1.4
  +++ HeadFilter.java	27 Feb 2002 20:41:37 -0000	1.5
  @@ -67,12 +67,12 @@
    * Example:
    * =======
    *
  - * <headfilter lines="3"/>
  + * <headfilter lines="3"/>
    *
    * Or:
    *
  - * <filterreader classname="org.apache.tools.ant.filters.HeadFilter">
  - *    <param name="lines" value="3"/>
  + * <filterreader classname="org.apache.tools.ant.filters.HeadFilter">
  + *    <param name="lines" value="3"/>
    * </filterreader>
    *
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
  @@ -180,15 +180,15 @@
           this.lines = lines;
       }
   
  -    public final long getLines() {
  +    private final long getLines() {
           return lines;
       }
   
  -    public final void setInitialized(final boolean initialized) {
  +    private final void setInitialized(final boolean initialized) {
           this.initialized = initialized;
       }
   
  -    public final boolean getInitialized() {
  +    private final boolean getInitialized() {
           return initialized;
       }
   
  
  
  
  1.2       +67 -5     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/LineContains.java
  
  Index: LineContains.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/LineContains.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LineContains.java	24 Feb 2002 04:08:14 -0000	1.1
  +++ LineContains.java	27 Feb 2002 20:41:37 -0000	1.2
  @@ -3,6 +3,7 @@
   import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  +import java.io.StringReader;
   import java.util.Vector;
   
   import org.apache.tools.ant.types.Parameter;
  @@ -15,6 +16,13 @@
    * Example:
    * =======
    *
  + * &lt;linecontains&gt;
  + *   &lt;contains value=&quot;foo&quot;&gt;
  + *   &lt;contains value=&quot;bar&quot;&gt;
  + * &lt;/linecontains&gt;
  + *
  + * Or:
  + *
    * &lt;filterreader classname="org.apache.tools.ant.filters.LineContains"&gt;
    *    &lt;param type="contains" value="foo"/&gt;
    *    &lt;param type="contains" value="bar"/&gt;
  @@ -26,7 +34,7 @@
    */
   public final class LineContains
       extends FilterReader
  -    implements Parameterizable
  +    implements Parameterizable, CloneableReader
   {
       private static final String CONTAINS_KEY = "contains";
   
  @@ -34,13 +42,27 @@
   
       private boolean initialized = false;
   
  -    private final Vector contains = new Vector();
  -
  -    private int containsSize = 0;
  +    private Vector contains = new Vector();
   
       private String line = null;
   
       /**
  +     * This constructor is a dummy constructor and is
  +     * not meant to be used by any class other than Ant's
  +     * introspection mechanism. This will close the filter
  +     * that is created making it useless for further operations.
  +     */
  +    public LineContains() {
  +        // Dummy constructor to be invoked by Ant's Introspector
  +        super(new StringReader(new String()));
  +        try {
  +            close();
  +        } catch (IOException  ioe) {
  +            // Ignore
  +        }
  +    }
  +
  +    /**
        * Create a new filtered reader.
        *
        * @param in  a Reader object providing the underlying stream.
  @@ -78,9 +100,11 @@
               }
   
               if (line != null) {
  +                int containsSize = contains.size();
                   for (int i = 0; i < containsSize; i++) {
                       String containsStr = (String) contains.elementAt(i);
                       if (line.indexOf(containsStr) == -1) {
  +                        System.out.println("Hello");
                           line = null;
                           break;
                       }
  @@ -116,6 +140,33 @@
           return n;
       }
   
  +    public final void addConfiguredContains(final Contains contains) {
  +        this.contains.addElement(contains.getValue());
  +    }
  +
  +    private void setContains(final Vector contains) {
  +        this.contains = contains;
  +    }
  +
  +    private final Vector getContains() {
  +        return contains;
  +    }
  +
  +    private final void setInitialized(final boolean initialized) {
  +        this.initialized = initialized;
  +    }
  +
  +    private final boolean getInitialized() {
  +        return initialized;
  +    }
  +
  +    public final Reader clone(final Reader rdr) {
  +        LineContains newFilter = new LineContains(rdr);
  +        newFilter.setContains(getContains());
  +        newFilter.setInitialized(true);
  +        return newFilter;
  +    }
  +
       /**
        * Set Parameters
        */
  @@ -131,7 +182,18 @@
                       contains.addElement(parameters[i].getValue());
                   }
               }
  -            containsSize = contains.size();
  +        }
  +    }
  +
  +    public static class Contains {
  +        private String value;
  +
  +        public final void setValue(String contains) {
  +            value = contains;
  +        }
  +
  +        public final String getValue() {
  +            return value;
           }
       }
   }
  
  
  
  1.2       +55 -4     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/PrefixLines.java
  
  Index: PrefixLines.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/PrefixLines.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PrefixLines.java	23 Feb 2002 03:28:04 -0000	1.1
  +++ PrefixLines.java	27 Feb 2002 20:41:37 -0000	1.2
  @@ -3,6 +3,7 @@
   import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  +import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -10,11 +11,22 @@
   /**
    * Attach a prefix to every line
    *
  + * Example:
  + * =======
  + *
  + * &lt;prefixlines prefix=&quot;Foo&quot;/&gt;
  + *
  + * Or:
  + *
  + * &lt;filterreader classname=&quot;org.apache.tools.ant.filters.PrefixLines&quot;&gt;
  + *    &lt;param name=&quot;prefix&quot; value=&quot;Foo&quot;/&gt;
  + * &lt;/filterreader&gt;
  + *
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class PrefixLines
       extends FilterReader
  -    implements Parameterizable
  +    implements Parameterizable, CloneableReader
   {
       /**
        * prefix key
  @@ -30,6 +42,22 @@
       private String queuedData = null;
   
       /**
  +     * This constructor is a dummy constructor and is
  +     * not meant to be used by any class other than Ant's
  +     * introspection mechanism. This will close the filter
  +     * that is created making it useless for further operations.
  +     */
  +    public PrefixLines() {
  +        // Dummy constructor to be invoked by Ant's Introspector
  +        super(new StringReader(new String()));
  +        try {
  +            close();
  +        } catch (IOException  ioe) {
  +            // Ignore
  +        }
  +    }
  +
  +    /**
        * Create a new filtered reader.
        *
        * @param in  a Reader object providing the underlying stream.
  @@ -39,9 +67,9 @@
       }
   
       public final int read() throws IOException {
  -        if (!initialized) {
  +        if (!getInitialized()) {
               initialize();
  -            initialized = true;
  +            setInitialized(true);
           }
   
           int ch = -1;
  @@ -101,12 +129,35 @@
           return n;
       }
   
  +    public final void setPrefix(final String prefix) {
  +        this.prefix = prefix;
  +    }
  +
  +    private final String getPrefix() {
  +        return prefix;
  +    }
  +
  +    private final void setInitialized(final boolean initialized) {
  +        this.initialized = initialized;
  +    }
  +
  +    private final boolean getInitialized() {
  +        return initialized;
  +    }
  +
  +    public final Reader clone(final Reader rdr) {
  +        PrefixLines newFilter = new PrefixLines(rdr);
  +        newFilter.setPrefix(getPrefix());
  +        newFilter.setInitialized(true);
  +        return newFilter;
  +    }
  +
       /**
        * Set Parameters
        */
       public final void setParameters(final Parameter[] parameters) {
           this.parameters = parameters;
  -        initialized = false;
  +        setInitialized(false);
       }
   
       private final void initialize() {
  
  
  
  1.5       +96 -5     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/ReplaceTokens.java
  
  Index: ReplaceTokens.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/ReplaceTokens.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReplaceTokens.java	24 Feb 2002 04:08:14 -0000	1.4
  +++ ReplaceTokens.java	27 Feb 2002 20:41:37 -0000	1.5
  @@ -56,6 +56,7 @@
   import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  +import java.io.StringReader;
   import java.util.Hashtable;
   
   import org.apache.tools.ant.types.Parameter;
  @@ -66,17 +67,24 @@
    *
    * Example Usage:
    * =============
  + *
  + * &lt;replacetokens begintoken=&quot;#&quot; endtoken=&quot;#&quot;&gt;
  + *   &lt;token key=&quot;DATE&quot; value=&quot;${TODAY}&quot;/&gt;
  + * &lt;/replacetokens&gt;
  + *
  + * Or:
  + *
    * &lt;filterreader classname="org.apache.tools.ant.filters.ReplaceTokens"&gt;
    *    &lt;param type="tokenchar" name="begintoken" value="#"/&gt;
    *    &lt;param type="tokenchar" name="endtoken" value="#"/&gt;
  - *    &lt;param type="token" name="DATE" value="${DATE}"/&gt;
  + *    &lt;param type="token" name="DATE" value="${TODAY}"/&gt;
    * &lt;/filterreader&gt;
    *
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class ReplaceTokens
       extends FilterReader
  -    implements Parameterizable
  +    implements Parameterizable, CloneableReader
   {
       private static final char DEFAULT_BEGIN_TOKEN = '@';
   
  @@ -95,6 +103,22 @@
       private char endToken = DEFAULT_END_TOKEN;
   
       /**
  +     * This constructor is a dummy constructor and is
  +     * not meant to be used by any class other than Ant's
  +     * introspection mechanism. This will close the filter
  +     * that is created making it useless for further operations.
  +     */
  +    public ReplaceTokens() {
  +        // Dummy constructor to be invoked by Ant's Introspector
  +        super(new StringReader(new String()));
  +        try {
  +            close();
  +        } catch (IOException  ioe) {
  +            // Ignore
  +        }
  +    }
  +
  +    /**
        * Create a new filtered reader.
        *
        * @param in  a Reader object providing the underlying stream.
  @@ -107,9 +131,9 @@
        * Replace tokens with values.
        */
       public final int read() throws IOException {
  -        if (!initialized) {
  +        if (!getInitialized()) {
               initialize();
  -            initialized = true;
  +            setInitialized(true);
           }
   
           if (queuedData != null && queuedData.length() > 0) {
  @@ -177,12 +201,57 @@
           return n;
       }
   
  +    public final void setBeginToken(final char beginToken) {
  +        this.beginToken = beginToken;
  +    }
  +
  +    private final char getBeginToken() {
  +        return beginToken;
  +    }
  +
  +    public final void setEndToken(final char endToken) {
  +        this.endToken = endToken;
  +    }
  +
  +    private final char getEndToken() {
  +        return endToken;
  +    }
  +
  +    public final void addConfiguredToken(final Token token) {
  +        hash.put(token.getKey(), token.getValue());
  +    }
  +
  +    private void setTokens(final Hashtable hash) {
  +        this.hash = hash;
  +    }
  +
  +    private final Hashtable getTokens() {
  +        return hash;
  +    }
  +
  +    private final void setInitialized(final boolean initialized) {
  +        this.initialized = initialized;
  +    }
  +
  +    private final boolean getInitialized() {
  +        return initialized;
  +    }
  +
  +    public final Reader clone(final Reader rdr) {
  +        ReplaceTokens newFilter = new ReplaceTokens(rdr);
  +        newFilter.setBeginToken(getBeginToken());
  +        newFilter.setEndToken(getEndToken());
  +        newFilter.setTokens(getTokens());
  +        newFilter.setInitialized(true);
  +        return newFilter;
  +    }
  +
       /**
        * Set Parameters
        */
       public final void setParameters(final Parameter[] parameters) {
           this.parameters = parameters;
  -        initialized = false;
  +        setInitialized(false);
       }
   
       /**
  @@ -207,6 +276,28 @@
                       }
                   }
               }
  +        }
  +    }
  +
  +    public static class Token {
  +        private String key;
  +
  +        private String value;
  +
  +        public final void setKey(String key) {
  +            this.key = key;
  +        }
  +
  +        public final void setValue(String value) {
  +            this.value = value;
  +        }
  +
  +        public final String getKey() {
  +            return key;
  +        }
  +
  +        public final String getValue() {
  +            return value;
           }
       }
   }
  
  
  
  1.3       +25 -1     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripJavaComments.java
  
  Index: StripJavaComments.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripJavaComments.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StripJavaComments.java	18 Feb 2002 20:57:36 -0000	1.2
  +++ StripJavaComments.java	27 Feb 2002 20:41:37 -0000	1.3
  @@ -56,6 +56,7 @@
   import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  +import java.io.StringReader;
   
   /**
    * This is a java comment and string stripper reader that filters
  @@ -64,7 +65,25 @@
    * Since this class heavily relies on the single char read function,
    * you are reccomended to make it work on top of a buffered reader.
    */
  -public final class StripJavaComments extends FilterReader {
  +public final class StripJavaComments
  +    extends FilterReader
  +    implements CloneableReader
  +{
  +    /**
  +     * This constructor is a dummy constructor and is
  +     * not meant to be used by any class other than Ant's
  +     * introspection mechanism. This will close the filter
  +     * that is created making it useless for further operations.
  +     */
  +    public StripJavaComments() {
  +        // Dummy constructor to be invoked by Ant's Introspector
  +        super(new StringReader(new String()));
  +        try {
  +            close();
  +        } catch (IOException  ioe) {
  +            // Ignore
  +        }
  +    }
   
       /**
        * Create a new filtered reader.
  @@ -146,5 +165,10 @@
               if (in.read() == -1) return i;
           }
           return n;
  +    }
  +
  +    public final Reader clone(final Reader rdr) {
  +        StripJavaComments newFilter = new StripJavaComments(rdr);
  +        return newFilter;
       }
   }
  
  
  
  1.6       +65 -17    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineBreaks.java
  
  Index: StripLineBreaks.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineBreaks.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StripLineBreaks.java	18 Feb 2002 20:57:36 -0000	1.5
  +++ StripLineBreaks.java	27 Feb 2002 20:41:37 -0000	1.6
  @@ -56,6 +56,7 @@
   import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  +import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -63,12 +64,18 @@
   /**
    * Filter to flatten the stream to a single line.
    *
  + * &lt;striplinebreaks/&gt;
  + *
  + * Or:
  + *
  + * &lt;filterreader classname=&quot;org.apache.tools.ant.filters.StripLineBreaks&quot;/&gt;
  + *
    * @author Steve Loughran
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class StripLineBreaks
       extends FilterReader
  -    implements Parameterizable
  +    implements Parameterizable, CloneableReader
   {
       /**
        * Linebreaks. What do to on funny IBM mainframes with odd line endings?
  @@ -88,6 +95,22 @@
       private boolean initialized = false;
   
       /**
  +     * This constructor is a dummy constructor and is
  +     * not meant to be used by any class other than Ant's
  +     * introspection mechanism. This will close the filter
  +     * that is created making it useless for further operations.
  +     */
  +    public StripLineBreaks() {
  +        // Dummy constructor to be invoked by Ant's Introspector
  +        super(new StringReader(new String()));
  +        try {
  +            close();
  +        } catch (IOException  ioe) {
  +            // Ignore
  +        }
  +    }
  +
  +    /**
        * Create a new filtered reader.
        *
        * @param in  a Reader object providing the underlying stream.
  @@ -98,21 +121,8 @@
   
       public final int read() throws IOException {
           if (!initialized) {
  -            String userDefinedLineBreaks = null;
  -            if (parameters != null) {
  -                for (int i = 0; i < parameters.length; i++) {
  -                    if (LINE_BREAKS_KEY.equals(parameters[i].getName())) {
  -                        userDefinedLineBreaks = parameters[i].getValue();
  -                        break;
  -                    }
  -                }
  -            }
  -
  -            if (userDefinedLineBreaks != null) {
  -                lineBreaks = userDefinedLineBreaks;
  -            }
  -
  -            initialized = true;
  +            initialize();
  +            setInitialized(true);
           }
   
           int ch = in.read();
  @@ -151,11 +161,49 @@
           return n;
       }
   
  +    public final void setLineBreaks(final String lineBreaks) {
  +        this.lineBreaks = lineBreaks;
  +    }
  +
  +    private final String getLineBreaks() {
  +        return lineBreaks;
  +    }
  +
  +    private final void setInitialized(final boolean initialized) {
  +        this.initialized = initialized;
  +    }
  +
  +    private final boolean getInitialized() {
  +        return initialized;
  +    }
  +
  +    public final Reader clone(final Reader rdr) {
  +        StripLineBreaks newFilter = new StripLineBreaks(rdr);
  +        newFilter.setLineBreaks(getLineBreaks());
  +        newFilter.setInitialized(true);
  +        return newFilter;
  +    }
  +
       /**
        * Set Parameters
        */
       public final void setParameters(final Parameter[] parameters) {
           this.parameters = parameters;
  -        initialized = false;
  +        setInitialized(false);
  +    }
  +
  +    private final void initialize() {
  +        String userDefinedLineBreaks = null;
  +        if (parameters != null) {
  +            for (int i = 0; i < parameters.length; i++) {
  +                if (LINE_BREAKS_KEY.equals(parameters[i].getName())) {
  +                    userDefinedLineBreaks = parameters[i].getValue();
  +                    break;
  +                }
  +            }
  +        }
  +        if (userDefinedLineBreaks != null) {
  +            lineBreaks = userDefinedLineBreaks;
  +        }
       }
   }
  
  
  
  1.4       +78 -14    jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineComments.java
  
  Index: StripLineComments.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineComments.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StripLineComments.java	24 Feb 2002 04:08:14 -0000	1.3
  +++ StripLineComments.java	27 Feb 2002 20:41:37 -0000	1.4
  @@ -3,6 +3,7 @@
   import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  +import java.io.StringReader;
   import java.util.Vector;
   
   import org.apache.tools.ant.types.Parameter;
  @@ -14,19 +15,29 @@
    * Example:
    * =======
    *
  - * &lt;filterreader classname="org.apache.tools.ant.filters.StripLineComments"&gt;
  - *    &lt;param type="comment" value="#"/&gt;
  - *    &lt;param type="comment" value="--"/&gt;
  - *    &lt;param type="comment" value="REM "/&gt;
  - *    &lt;param type="comment" value="rem "/&gt;
  - *    &lt;param type="comment" value="//"/&gt;
  + * &lt;striplinecomments&gt;
  + *   &lt;comment value=&quot;#&quot;/&gt;
  + *   &lt;comment value=&quot;--&quot;/&gt;
  + *   &lt;comment value=&quot;REM &quot;/&gt;
  + *   &lt;comment value=&quot;rem &quot;/&gt;
  + *   &lt;comment value=&quot;//&quot;/&gt;
  + * &lt;/striplinecomments&gt;
  + *
  + * Or:
  + *
  + * &lt;filterreader classname=&quot;org.apache.tools.ant.filters.StripLineComments&quot;&gt;
  + *    &lt;param type=&quot;comment&quot; value="#&quot;/&gt;
  + *    &lt;param type=&quot;comment&quot; value=&quot;--&quot;/&gt;
  + *    &lt;param type=&quot;comment&quot; value=&quot;REM &quot;/&gt;
  + *    &lt;param type=&quot;comment&quot; value=&quot;rem &quot;/&gt;
  + *    &lt;param type=&quot;comment&quot; value=&quot;//&quot;/&gt;
    * &lt;/filterreader&gt;
    *
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class StripLineComments
       extends FilterReader
  -    implements Parameterizable
  +    implements Parameterizable, CloneableReader
   {
       private static final String COMMENTS_KEY = "comment";
   
  @@ -34,13 +45,27 @@
   
       private boolean initialized = false;
   
  -    private final Vector comments = new Vector();
  -
  -    private int commentsSize = 0;
  +    private Vector comments = new Vector();
   
       private String line = null;
   
       /**
  +     * This constructor is a dummy constructor and is
  +     * not meant to be used by any class other than Ant's
  +     * introspection mechanism. This will close the filter
  +     * that is created making it useless for further operations.
  +     */
  +    public StripLineComments() {
  +        // Dummy constructor to be invoked by Ant's Introspector
  +        super(new StringReader(new String()));
  +        try {
  +            close();
  +        } catch (IOException  ioe) {
  +            // Ignore
  +        }
  +    }
  +
  +    /**
        * Create a new filtered reader.
        *
        * @param in  a Reader object providing the underlying stream.
  @@ -50,9 +75,9 @@
       }
   
       public final int read() throws IOException {
  -        if (!initialized) {
  +        if (!getInitialized()) {
               initialize();
  -            initialized = true;
  +            setInitialized(true);
           }
   
           int ch = -1;
  @@ -78,6 +103,7 @@
               }
   
               if (line != null) {
  +                int commentsSize = comments.size();
                   for (int i = 0; i < commentsSize; i++) {
                       String comment = (String) comments.elementAt(i);
                       if (line.startsWith(comment)) {
  @@ -115,12 +141,39 @@
           return n;
       }
   
  +    public final void addConfiguredComment(final Comment comment) {
  +        comments.addElement(comment.getValue());
  +    }
  +
  +    private void setComments(final Vector comments) {
  +        this.comments = comments;
  +    }
  +
  +    private final Vector getComments() {
  +        return comments;
  +    }
  +
  +    private final void setInitialized(final boolean initialized) {
  +        this.initialized = initialized;
  +    }
  +
  +    private final boolean getInitialized() {
  +        return initialized;
  +    }
  +
  +    public final Reader clone(final Reader rdr) {
  +        StripLineComments newFilter = new StripLineComments(rdr);
  +        newFilter.setComments(getComments());
  +        newFilter.setInitialized(true);
  +        return newFilter;
  +    }
  +
       /**
        * Set Parameters
        */
       public final void setParameters(final Parameter[] parameters) {
           this.parameters = parameters;
  -        initialized = false;
  +        setInitialized(false);
       }
   
       private final void initialize() {
  @@ -130,7 +183,18 @@
                       comments.addElement(parameters[i].getValue());
                   }
               }
  -            commentsSize = comments.size();
  +        }
  +    }
  +
  +    public static class Comment {
  +        private String value;
  +
  +        public final void setValue(String comment) {
  +            value = comment;
  +        }
  +
  +        public final String getValue() {
  +            return value;
           }
       }
   }
  
  
  
  1.3       +52 -8     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TabsToSpaces.java
  
  Index: TabsToSpaces.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TabsToSpaces.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TabsToSpaces.java	18 Feb 2002 20:57:36 -0000	1.2
  +++ TabsToSpaces.java	27 Feb 2002 20:41:37 -0000	1.3
  @@ -56,7 +56,7 @@
   import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  -import java.util.Hashtable;
  +import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -66,15 +66,20 @@
    *
    * Example Usage:
    * =============
  - * <filterreader classname="org.apache.tools.ant.filters.TabsToSpaces">
  - *    <param name="tablength" value="8"/>
  + *
  + * &lt;tabtospaces tablength=&quot;8&quot;/&gt;
  + *
  + * Or:
  + *
  + * <filterreader classname=&quot;org.apache.tools.ant.filters.TabsToSpaces&quot;>
  + *    <param name=&quot;tablength&quot; value=&quot;8&quot;/>
    * </filterreader>
    *
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class TabsToSpaces
       extends FilterReader
  -    implements Parameterizable
  +    implements Parameterizable, CloneableReader
   {
       private static final int DEFAULT_TAB_LENGTH = 8;
   
  @@ -89,6 +94,22 @@
       private int spacesRemaining = 0;
   
       /**
  +     * This constructor is a dummy constructor and is
  +     * not meant to be used by any class other than Ant's
  +     * introspection mechanism. This will close the filter
  +     * that is created making it useless for further operations.
  +     */
  +    public TabsToSpaces() {
  +        // Dummy constructor to be invoked by Ant's Introspector
  +        super(new StringReader(new String()));
  +        try {
  +            close();
  +        } catch (IOException  ioe) {
  +            // Ignore
  +        }
  +    }
  +
  +    /**
        * Create a new filtered reader.
        *
        * @param in  a Reader object providing the underlying stream.
  @@ -101,9 +122,9 @@
        * Convert tabs with spaces
        */
       public final int read() throws IOException {
  -        if (!initialized) {
  +        if (!getInitialized()) {
               initialize();
  -            initialized = true;
  +            setInitialized(true);
           }
   
           int ch = -1;
  @@ -146,16 +167,39 @@
           return n;
       }
   
  +    public final void setTablength(final int tabLength) {
  +        this.tabLength = tabLength;
  +    }
  +
  +    private final int getTablength() {
  +        return tabLength;
  +    }
  +
  +    private final void setInitialized(final boolean initialized) {
  +        this.initialized = initialized;
  +    }
  +
  +    private final boolean getInitialized() {
  +        return initialized;
  +    }
  +
  +    public final Reader clone(final Reader rdr) {
  +        TabsToSpaces newFilter = new TabsToSpaces(rdr);
  +        newFilter.setTablength(getTablength());
  +        newFilter.setInitialized(true);
  +        return newFilter;
  +    }
  +
       /**
        * Set Parameters
        */
       public final void setParameters(final Parameter[] parameters) {
           this.parameters = parameters;
  -        initialized = false;
  +        setInitialized(false);
       }
   
       /**
  -     * Initialize tokens and load the replacee-replacer hashtable.
  +     * Initialize tokens
        */
       private final void initialize() {
           if (parameters != null) {
  
  
  
  1.4       +51 -7     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TailFilter.java
  
  Index: TailFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TailFilter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TailFilter.java	24 Feb 2002 04:08:14 -0000	1.3
  +++ TailFilter.java	27 Feb 2002 20:41:37 -0000	1.4
  @@ -56,6 +56,7 @@
   import java.io.FilterReader;
   import java.io.IOException;
   import java.io.Reader;
  +import java.io.StringReader;
   
   import org.apache.tools.ant.types.Parameter;
   import org.apache.tools.ant.types.Parameterizable;
  @@ -66,15 +67,19 @@
    * Example:
    * =======
    *
  - * &lt;filterreader classname="org.apache.tools.ant.filters.TailFilter"&gt;
  - *    &lt;param name="lines" value="3"/&gt;
  + * &lt;tailfilter lines=&quot;3&quot;/&gt;
  + *
  + * Or:
  + *
  + * &lt;filterreader classname=&quot;org.apache.tools.ant.filters.TailFilter&quot;&gt;
  + *    &lt;param name=&quot;lines&quot; value=&quot;3&quot;/&gt;
    * &lt;/filterreader&gt;
    *
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    */
   public final class TailFilter
       extends FilterReader
  -    implements Parameterizable
  +    implements Parameterizable, CloneableReader
   {
       private static final String LINES_KEY = "lines";
   
  @@ -97,6 +102,22 @@
       private int bufferPos = 0;
   
       /**
  +     * This constructor is a dummy constructor and is
  +     * not meant to be used by any class other than Ant's
  +     * introspection mechanism. This will close the filter
  +     * that is created making it useless for further operations.
  +     */
  +    public TailFilter() {
  +        // Dummy constructor to be invoked by Ant's Introspector
  +        super(new StringReader(new String()));
  +        try {
  +            close();
  +        } catch (IOException  ioe) {
  +            // Ignore
  +        }
  +    }
  +
  +    /**
        * Create a new filtered reader.
        *
        * @param in  a Reader object providing the underlying stream.
  @@ -110,9 +131,9 @@
        * point.  Grow buffer as needed.
        */
       public final int read() throws IOException {
  -        if (!initialized) {
  +        if (!getInitialized()) {
               initialize();
  -            initialized = true;
  +            setInitialized(true);
           }
   
           if (!completedReadAhead) {
  @@ -200,19 +221,42 @@
           return n;
       }
   
  +    public final void setLines(final long lines) {
  +        this.lines = lines;
  +    }
  +
  +    private final long getLines() {
  +        return lines;
  +    }
  +
  +    private final void setInitialized(final boolean initialized) {
  +        this.initialized = initialized;
  +    }
  +
  +    private final boolean getInitialized() {
  +        return initialized;
  +    }
  +
  +    public final Reader clone(final Reader rdr) {
  +        TailFilter newFilter = new TailFilter(rdr);
  +        newFilter.setLines(getLines());
  +        newFilter.setInitialized(true);
  +        return newFilter;
  +    }
  +
       /**
        * Set Parameters
        */
       public final void setParameters(final Parameter[] parameters) {
           this.parameters = parameters;
  -        initialized = false;
  +        setInitialized(false);
       }
   
       private final void initialize() {
           if (parameters != null) {
               for (int i = 0; i < parameters.length; i++) {
                   if (LINES_KEY.equals(parameters[i].getName())) {
  -                    lines = new Long(parameters[i].getValue()).longValue();
  +                    setLines(new Long(parameters[i].getValue()).longValue());
                       break;
                   }
               }
  
  
  
  1.3       +43 -0     jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/FilterReaderSet.java
  
  Index: FilterReaderSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/FilterReaderSet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FilterReaderSet.java	27 Feb 2002 18:14:11 -0000	1.2
  +++ FilterReaderSet.java	27 Feb 2002 20:41:38 -0000	1.3
  @@ -56,6 +56,14 @@
   import java.util.Vector;
   
   import org.apache.tools.ant.filters.HeadFilter;
  +import org.apache.tools.ant.filters.LineContains;
  +import org.apache.tools.ant.filters.PrefixLines;
  +import org.apache.tools.ant.filters.ReplaceTokens;
  +import org.apache.tools.ant.filters.StripJavaComments;
  +import org.apache.tools.ant.filters.StripLineBreaks;
  +import org.apache.tools.ant.filters.StripLineComments;
  +import org.apache.tools.ant.filters.TabsToSpaces;
  +import org.apache.tools.ant.filters.TailFilter;
   
   /**
    * Set of FilterReaders
  @@ -76,5 +84,40 @@
   
       public final void addHeadFilter(final HeadFilter headFilter) {
           filterReaders.addElement(headFilter);
  +    }
  +
  +    public final void addLineContains(final LineContains lineContains) {
  +        filterReaders.addElement(lineContains);
  +    }
  +
  +    public final void addPrefixLines(final PrefixLines prefixLines) {
  +        filterReaders.addElement(prefixLines);
  +    }
  +
  +    public final void addReplaceTokens(final ReplaceTokens replaceTokens) {
  +        filterReaders.addElement(replaceTokens);
  +    }
  +
  +    public final void addStripJavaComments(final StripJavaComments
  +                                                stripJavaComments) {
  +        filterReaders.addElement(stripJavaComments);
  +    }
  +
  +    public final void addStripLineBreaks(final StripLineBreaks
  +                                                stripLineBreaks) {
  +        filterReaders.addElement(stripLineBreaks);
  +    }
  +
  +    public final void addStripLineComments(final StripLineComments
  +                                                stripLineComments) {
  +        filterReaders.addElement(stripLineComments);
  +    }
  +
  +    public final void addTabsToSpaces(final TabsToSpaces tabsToSpaces) {
  +        filterReaders.addElement(tabsToSpaces);
  +    }
  +
  +    public final void addTailFilter(final TailFilter tailFilter) {
  +        filterReaders.addElement(tailFilter);
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message