2. Remove double-quotes from javadoc and replace with " git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271584 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -67,12 +67,12 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| * 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 @@ public final class HeadFilter | |||
| 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; | |||
| } | |||
| @@ -3,6 +3,7 @@ package org.apache.tools.ant.filters; | |||
| 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 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| * Example: | |||
| * ======= | |||
| * | |||
| * <linecontains> | |||
| * <contains value="foo"> | |||
| * <contains value="bar"> | |||
| * </linecontains> | |||
| * | |||
| * Or: | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.LineContains"> | |||
| * <param type="contains" value="foo"/> | |||
| * <param type="contains" value="bar"/> | |||
| @@ -26,7 +34,7 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| */ | |||
| public final class LineContains | |||
| extends FilterReader | |||
| implements Parameterizable | |||
| implements Parameterizable, CloneableReader | |||
| { | |||
| private static final String CONTAINS_KEY = "contains"; | |||
| @@ -34,12 +42,26 @@ public final class LineContains | |||
| 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. | |||
| * | |||
| @@ -78,9 +100,11 @@ public final class LineContains | |||
| } | |||
| 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 @@ public final class LineContains | |||
| 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 @@ public final class LineContains | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -3,6 +3,7 @@ package org.apache.tools.ant.filters; | |||
| 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 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| /** | |||
| * Attach a prefix to every line | |||
| * | |||
| * Example: | |||
| * ======= | |||
| * | |||
| * <prefixlines prefix="Foo"/> | |||
| * | |||
| * Or: | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.PrefixLines"> | |||
| * <param name="prefix" value="Foo"/> | |||
| * </filterreader> | |||
| * | |||
| * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a> | |||
| */ | |||
| public final class PrefixLines | |||
| extends FilterReader | |||
| implements Parameterizable | |||
| implements Parameterizable, CloneableReader | |||
| { | |||
| /** | |||
| * prefix key | |||
| @@ -29,6 +41,22 @@ public final class PrefixLines | |||
| 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. | |||
| * | |||
| @@ -39,9 +67,9 @@ public final class PrefixLines | |||
| } | |||
| public final int read() throws IOException { | |||
| if (!initialized) { | |||
| if (!getInitialized()) { | |||
| initialize(); | |||
| initialized = true; | |||
| setInitialized(true); | |||
| } | |||
| int ch = -1; | |||
| @@ -101,12 +129,35 @@ public final class PrefixLines | |||
| 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() { | |||
| @@ -56,6 +56,7 @@ package org.apache.tools.ant.filters; | |||
| 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 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| * | |||
| * Example Usage: | |||
| * ============= | |||
| * | |||
| * <replacetokens begintoken="#" endtoken="#"> | |||
| * <token key="DATE" value="${TODAY}"/> | |||
| * </replacetokens> | |||
| * | |||
| * Or: | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.ReplaceTokens"> | |||
| * <param type="tokenchar" name="begintoken" value="#"/> | |||
| * <param type="tokenchar" name="endtoken" value="#"/> | |||
| * <param type="token" name="DATE" value="${DATE}"/> | |||
| * <param type="token" name="DATE" value="${TODAY}"/> | |||
| * </filterreader> | |||
| * | |||
| * @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 = '@'; | |||
| @@ -94,6 +102,22 @@ public final class ReplaceTokens | |||
| 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. | |||
| * | |||
| @@ -107,9 +131,9 @@ public final class ReplaceTokens | |||
| * 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 @@ public final class ReplaceTokens | |||
| 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); | |||
| } | |||
| /** | |||
| @@ -209,4 +278,26 @@ public final class ReplaceTokens | |||
| } | |||
| } | |||
| } | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -56,6 +56,7 @@ package org.apache.tools.ant.filters; | |||
| 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 @@ import java.io.Reader; | |||
| * 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. | |||
| @@ -147,4 +166,9 @@ public final class StripJavaComments extends FilterReader { | |||
| } | |||
| return n; | |||
| } | |||
| public final Reader clone(final Reader rdr) { | |||
| StripJavaComments newFilter = new StripJavaComments(rdr); | |||
| return newFilter; | |||
| } | |||
| } | |||
| @@ -56,6 +56,7 @@ package org.apache.tools.ant.filters; | |||
| 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 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| /** | |||
| * Filter to flatten the stream to a single line. | |||
| * | |||
| * <striplinebreaks/> | |||
| * | |||
| * Or: | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.StripLineBreaks"/> | |||
| * | |||
| * @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? | |||
| @@ -87,6 +94,22 @@ public final class StripLineBreaks | |||
| 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. | |||
| * | |||
| @@ -98,21 +121,8 @@ public final class StripLineBreaks | |||
| 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 @@ public final class StripLineBreaks | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -3,6 +3,7 @@ package org.apache.tools.ant.filters; | |||
| 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 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| * Example: | |||
| * ======= | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.StripLineComments"> | |||
| * <param type="comment" value="#"/> | |||
| * <param type="comment" value="--"/> | |||
| * <param type="comment" value="REM "/> | |||
| * <param type="comment" value="rem "/> | |||
| * <param type="comment" value="//"/> | |||
| * <striplinecomments> | |||
| * <comment value="#"/> | |||
| * <comment value="--"/> | |||
| * <comment value="REM "/> | |||
| * <comment value="rem "/> | |||
| * <comment value="//"/> | |||
| * </striplinecomments> | |||
| * | |||
| * Or: | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.StripLineComments"> | |||
| * <param type="comment" value="#"/> | |||
| * <param type="comment" value="--"/> | |||
| * <param type="comment" value="REM "/> | |||
| * <param type="comment" value="rem "/> | |||
| * <param type="comment" value="//"/> | |||
| * </filterreader> | |||
| * | |||
| * @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,12 +45,26 @@ public final class StripLineComments | |||
| 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. | |||
| * | |||
| @@ -50,9 +75,9 @@ public final class StripLineComments | |||
| } | |||
| public final int read() throws IOException { | |||
| if (!initialized) { | |||
| if (!getInitialized()) { | |||
| initialize(); | |||
| initialized = true; | |||
| setInitialized(true); | |||
| } | |||
| int ch = -1; | |||
| @@ -78,6 +103,7 @@ public final class StripLineComments | |||
| } | |||
| 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 @@ public final class StripLineComments | |||
| 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 @@ public final class StripLineComments | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -56,7 +56,7 @@ package org.apache.tools.ant.filters; | |||
| 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 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| * | |||
| * Example Usage: | |||
| * ============= | |||
| * <filterreader classname="org.apache.tools.ant.filters.TabsToSpaces"> | |||
| * <param name="tablength" value="8"/> | |||
| * | |||
| * <tabtospaces tablength="8"/> | |||
| * | |||
| * Or: | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.TabsToSpaces"> | |||
| * <param name="tablength" value="8"/> | |||
| * </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; | |||
| @@ -88,6 +93,22 @@ public final class TabsToSpaces | |||
| 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. | |||
| * | |||
| @@ -101,9 +122,9 @@ public final class TabsToSpaces | |||
| * 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 @@ public final class TabsToSpaces | |||
| 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) { | |||
| @@ -56,6 +56,7 @@ package org.apache.tools.ant.filters; | |||
| 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 @@ import org.apache.tools.ant.types.Parameterizable; | |||
| * Example: | |||
| * ======= | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.TailFilter"> | |||
| * <param name="lines" value="3"/> | |||
| * <tailfilter lines="3"/> | |||
| * | |||
| * Or: | |||
| * | |||
| * <filterreader classname="org.apache.tools.ant.filters.TailFilter"> | |||
| * <param name="lines" value="3"/> | |||
| * </filterreader> | |||
| * | |||
| * @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"; | |||
| @@ -96,6 +101,22 @@ public final class TailFilter | |||
| 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. | |||
| * | |||
| @@ -110,9 +131,9 @@ public final class TailFilter | |||
| * 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 @@ public final class TailFilter | |||
| 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; | |||
| } | |||
| } | |||
| @@ -56,6 +56,14 @@ package org.apache.tools.ant.types; | |||
| 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 | |||
| @@ -77,4 +85,39 @@ public final class FilterReaderSet { | |||
| 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); | |||
| } | |||
| } | |||