Browse Source

Refactored code (as suggested by Costin and Adam) - first run.

1. Moved ChainReaderHelper.java to filters/util
2. Moved setInitialized, getInitialized to base class.
3. Introduced BaseParamFilterReader that implements Parameterizable and has setParameter
4. Null check introduced for LoadFile
5. Convenience method readLine() introduced into BaseFilterReader.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271605 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
87f806d3e4
13 changed files with 240 additions and 382 deletions
  1. +34
    -1
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/BaseFilterReader.java
  2. +106
    -0
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/BaseParamFilterReader.java
  3. +9
    -53
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/HeadFilter.java
  4. +13
    -50
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/LineContains.java
  5. +13
    -50
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/PrefixLines.java
  6. +12
    -40
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/ReplaceTokens.java
  7. +8
    -35
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineBreaks.java
  8. +11
    -48
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineComments.java
  9. +8
    -36
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TabsToSpaces.java
  10. +16
    -61
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TailFilter.java
  11. +1
    -1
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java
  12. +8
    -6
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java
  13. +1
    -1
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java

+ 34
- 1
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/BaseFilterReader.java View File

@@ -66,6 +66,9 @@ import java.io.StringReader;
public abstract class BaseFilterReader
extends FilterReader
{
/** Have the parameters passed been interpreted? */
private boolean initialized = false;

/**
* This constructor is a dummy constructor and is
* not meant to be used by any class other than Ant's
@@ -132,7 +135,7 @@ public abstract class BaseFilterReader
* @exception IllegalArgumentException If <code>n</code> is negative.
* @exception IOException If an I/O error occurs
*/
public final long skip(long n) throws IOException {
public final long skip(final long n) throws IOException {
if (n < 0L) {
throw new IllegalArgumentException("skip value is negative");
}
@@ -144,4 +147,34 @@ public abstract class BaseFilterReader
}
return n;
}

/**
* Set the initialized status.
*/
protected final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
protected final boolean getInitialized() {
return initialized;
}

/**
* Read till EOL
*/
protected final String readLine() throws IOException {
int ch = in.read();
String line = (ch == -1) ? null : "";
while (ch != -1) {
line += (char) ch;
if (ch == '\n') {
break;
}
ch = in.read();
}
return line;
}
}

+ 106
- 0
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/BaseParamFilterReader.java View File

@@ -0,0 +1,106 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
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;

/**
* Parameterized Base class for core filter readers.
*
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public abstract class BaseParamFilterReader
extends BaseFilterReader
implements Parameterizable
{
/** The passed in parameter array. */
private Parameter[] parameters;

/**
* 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 BaseParamFilterReader() {
super();
}

/**
* Create a new filtered reader.
*
* @param in a Reader object providing the underlying stream.
*/
public BaseParamFilterReader(final Reader in) {
super(in);
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
setInitialized(false);
}

protected final Parameter[] getParameters() {
return parameters;
}
}

+ 9
- 53
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/HeadFilter.java View File

@@ -57,7 +57,6 @@ import java.io.IOException;
import java.io.Reader;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
* Read the first n lines (Default is first 10 lines)
@@ -76,27 +75,18 @@ import org.apache.tools.ant.types.Parameterizable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class HeadFilter
extends BaseFilterReader
implements Parameterizable, ChainableReader
extends BaseParamFilterReader
implements ChainableReader
{
/** Lines key to represent the number of lines to be returned. */
private static final String LINES_KEY = "lines";

/** The passed in parameter array. */
private Parameter[] parameters;

/** Have the parameters passed been interpreted? */
private boolean initialized = false;

/** Number of lines currently read in. */
private long linesRead = 0;

/** Default number of lines returned. */
private long lines = 10;

/** If the next character being read is a linefeed, must it be ignored? */
private boolean ignoreLineFeed = false;

/**
* This constructor is a dummy constructor and is
* not meant to be used by any class other than Ant's
@@ -131,21 +121,8 @@ public final class HeadFilter

ch = in.read();

if (ignoreLineFeed) {
if (ch == '\n') {
ch = in.read();
}
ignoreLineFeed = false;
}

switch (ch) {
case '\r':
ch = '\n';
ignoreLineFeed = true;
//fall through
case '\n':
linesRead++;
break;
if (ch == '\n') {
linesRead++;
}
}

@@ -166,20 +143,6 @@ public final class HeadFilter
return lines;
}

/**
* Set the initialized status.
*/
private final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
private final boolean getInitialized() {
return initialized;
}

/**
* Create a new HeadFilter using the passed in
* Reader for instantiation.
@@ -191,22 +154,15 @@ public final class HeadFilter
return newFilter;
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
setInitialized(false);
}

/**
* Scan for the lines parameter.
*/
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();
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (LINES_KEY.equals(params[i].getName())) {
lines = new Long(params[i].getValue()).longValue();
break;
}
}


+ 13
- 50
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/LineContains.java View File

@@ -58,7 +58,6 @@ import java.io.Reader;
import java.util.Vector;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
* Filter Reader to fetch only those lines that contain user specified
@@ -84,18 +83,12 @@ import org.apache.tools.ant.types.Parameterizable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class LineContains
extends BaseFilterReader
implements Parameterizable, ChainableReader
extends BaseParamFilterReader
implements ChainableReader
{
/** contains key */
private static final String CONTAINS_KEY = "contains";

/** The passed in parameter array. */
private Parameter[] parameters;

/** Have the parameters passed been interpreted? */
private boolean initialized = false;

/** Vector that holds the strings that input lines must contain. */
private Vector contains = new Vector();

@@ -126,9 +119,9 @@ public final class LineContains
* user defined values.
*/
public final int read() throws IOException {
if (!initialized) {
if (!getInitialized()) {
initialize();
initialized = true;
setInitialized(true);
}

int ch = -1;
@@ -141,19 +134,10 @@ public final class LineContains
line = line.substring(1);
}
} else {
ch = in.read();
while (ch != -1) {
if (line == null) {
line = "";
}
line = line + (char) ch;
if (ch == '\n') {
break;
}
ch = in.read();
}

if (line != null) {
line = readLine();
if (line == null) {
ch = -1;
} else {
int containsSize = contains.size();
for (int i = 0; i < containsSize; i++) {
String containsStr = (String) contains.elementAt(i);
@@ -191,20 +175,6 @@ public final class LineContains
return contains;
}

/**
* Set the initialized status.
*/
private final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
private final boolean getInitialized() {
return initialized;
}

/**
* Create a new LineContains using the passed in
* Reader for instantiation.
@@ -216,22 +186,15 @@ public final class LineContains
return newFilter;
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
initialized = false;
}

/**
* Parse params to add user defined contains strings.
*/
private final void initialize() {
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (CONTAINS_KEY.equals(parameters[i].getType())) {
contains.addElement(parameters[i].getValue());
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (CONTAINS_KEY.equals(params[i].getType())) {
contains.addElement(params[i].getValue());
}
}
}


+ 13
- 50
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/PrefixLines.java View File

@@ -57,7 +57,6 @@ import java.io.IOException;
import java.io.Reader;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
* Attach a prefix to every line
@@ -76,18 +75,12 @@ import org.apache.tools.ant.types.Parameterizable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class PrefixLines
extends BaseFilterReader
implements Parameterizable, ChainableReader
extends BaseParamFilterReader
implements ChainableReader
{
/** prefix key */
private static final String PREFIX_KEY = "prefix";

/** The passed in parameter array. */
private Parameter[] parameters;

/** Have the parameters passed been interpreted? */
private boolean initialized = false;

/** The prefix to be used. */
private String prefix = null;

@@ -135,22 +128,13 @@ public final class PrefixLines
queuedData = null;
}
} else {
ch = in.read();
while (ch != -1) {
if (queuedData == null) {
if (prefix != null) {
queuedData = prefix;
} else {
queuedData = "";
}
queuedData = readLine();
if (queuedData == null) {
ch = -1;
} else {
if (prefix != null) {
queuedData = prefix + queuedData;
}
queuedData += (char) ch;
if (ch == '\n') {
break;
}
ch = in.read();
}
if (queuedData != null) {
return read();
}
}
@@ -171,20 +155,6 @@ public final class PrefixLines
return prefix;
}

/**
* Set the initialized status.
*/
private final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
private final boolean getInitialized() {
return initialized;
}

/**
* Create a new PrefixLines using the passed in
* Reader for instantiation.
@@ -196,22 +166,15 @@ public final class PrefixLines
return newFilter;
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
setInitialized(false);
}

/**
* Initialize prefix if available from the param element.
*/
private final void initialize() {
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (PREFIX_KEY.equals(parameters[i].getName())) {
prefix = parameters[i].getValue();
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (PREFIX_KEY.equals(params[i].getName())) {
prefix = params[i].getValue();
break;
}
}


+ 12
- 40
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/ReplaceTokens.java View File

@@ -58,7 +58,6 @@ import java.io.Reader;
import java.util.Hashtable;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
* Replace tokens with user supplied values
@@ -81,8 +80,8 @@ import org.apache.tools.ant.types.Parameterizable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class ReplaceTokens
extends BaseFilterReader
implements Parameterizable, ChainableReader
extends BaseParamFilterReader
implements ChainableReader
{
/** Default begin token character. */
private static final char DEFAULT_BEGIN_TOKEN = '@';
@@ -93,15 +92,9 @@ public final class ReplaceTokens
/** Data that must be read from, if not null. */
private String queuedData = null;

/** The passed in parameter array. */
private Parameter[] parameters;

/** Hashtable to hold the replacee-replacer pairs. */
private Hashtable hash = new Hashtable();

/** Have the parameters passed been interpreted? */
private boolean initialized;

/** Begin token. */
private char beginToken = DEFAULT_BEGIN_TOKEN;

@@ -225,20 +218,6 @@ public final class ReplaceTokens
return hash;
}

/**
* Set the initialized status.
*/
private final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
private final boolean getInitialized() {
return initialized;
}

/**
* Create a new ReplaceTokens using the passed in
* Reader for instantiation.
@@ -252,32 +231,25 @@ public final class ReplaceTokens
return newFilter;
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
setInitialized(false);
}

/**
* Initialize tokens and load the replacee-replacer hashtable.
*/
private final void initialize() {
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (parameters[i] != null) {
final String type = parameters[i].getType();
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (params[i] != null) {
final String type = params[i].getType();
if ("tokenchar".equals(type)) {
final String name = parameters[i].getName();
final String name = params[i].getName();
if ("begintoken".equals(name)) {
beginToken = parameters[i].getValue().charAt(0);
beginToken = params[i].getValue().charAt(0);
} else if ("endtoken".equals(name)) {
endToken = parameters[i].getValue().charAt(0);
endToken = params[i].getValue().charAt(0);
}
} else if ("token".equals(type)) {
final String name = parameters[i].getName();
final String value = parameters[i].getValue();
final String name = params[i].getName();
final String value = params[i].getValue();
hash.put(name, value);
}
}


+ 8
- 35
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineBreaks.java View File

@@ -57,7 +57,6 @@ import java.io.IOException;
import java.io.Reader;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
* Filter to flatten the stream to a single line.
@@ -72,8 +71,8 @@ import org.apache.tools.ant.types.Parameterizable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class StripLineBreaks
extends BaseFilterReader
implements Parameterizable, ChainableReader
extends BaseParamFilterReader
implements ChainableReader
{
/**
* Linebreaks. What do to on funny IBM mainframes with odd line endings?
@@ -86,15 +85,10 @@ public final class StripLineBreaks
*/
private static final String LINE_BREAKS_KEY = "linebreaks";

/** The passed in parameter array. */
private Parameter[] parameters;

/** Holds the characters that are recognized as line breaks. */
private String lineBreaks = DEFAULT_LINE_BREAKS;

/** Have the parameters passed been interpreted? */
private boolean initialized = false;

/**
* This constructor is a dummy constructor and is
* not meant to be used by any class other than Ant's
@@ -120,7 +114,7 @@ public final class StripLineBreaks
* next one.
*/
public final int read() throws IOException {
if (!initialized) {
if (!getInitialized()) {
initialize();
setInitialized(true);
}
@@ -150,20 +144,6 @@ public final class StripLineBreaks
return lineBreaks;
}

/**
* Set the initialized status.
*/
private final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
private final boolean getInitialized() {
return initialized;
}

/**
* Create a new StripLineBreaks object using the passed in
* Reader for instantiation.
@@ -175,23 +155,16 @@ public final class StripLineBreaks
return newFilter;
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
setInitialized(false);
}

/**
* Line break characters set using the param element.
*/
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();
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (LINE_BREAKS_KEY.equals(params[i].getName())) {
userDefinedLineBreaks = params[i].getValue();
break;
}
}


+ 11
- 48
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineComments.java View File

@@ -58,7 +58,6 @@ import java.io.Reader;
import java.util.Vector;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
* This is a line comment stripper reader
@@ -87,18 +86,12 @@ import org.apache.tools.ant.types.Parameterizable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class StripLineComments
extends BaseFilterReader
implements Parameterizable, ChainableReader
extends BaseParamFilterReader
implements ChainableReader
{
/** The type that param recognizes to set the comments. */
private static final String COMMENTS_KEY = "comment";

/** The passed in parameter array. */
private Parameter[] parameters;

/** Have the parameters passed been interpreted? */
private boolean initialized = false;

/** Vector that holds comments. */
private Vector comments = new Vector();

@@ -144,19 +137,10 @@ public final class StripLineComments
line = line.substring(1);
}
} else {
ch = in.read();
while (ch != -1) {
if (line == null) {
line = "";
}
line = line + (char) ch;
if (ch == '\n') {
break;
}
ch = in.read();
}

if (line != null) {
line = readLine();
if (line == null) {
ch = -1;
} else {
int commentsSize = comments.size();
for (int i = 0; i < commentsSize; i++) {
String comment = (String) comments.elementAt(i);
@@ -193,20 +177,6 @@ public final class StripLineComments
return comments;
}

/**
* Set the initialized status.
*/
private final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
private final boolean getInitialized() {
return initialized;
}

/**
* Create a new StripLineComments object using the passed in
* Reader for instantiation.
@@ -218,22 +188,15 @@ public final class StripLineComments
return newFilter;
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
setInitialized(false);
}

/**
* Comments set using the param element.
*/
private final void initialize() {
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (COMMENTS_KEY.equals(parameters[i].getType())) {
comments.addElement(parameters[i].getValue());
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (COMMENTS_KEY.equals(params[i].getType())) {
comments.addElement(params[i].getValue());
}
}
}


+ 8
- 36
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TabsToSpaces.java View File

@@ -57,7 +57,6 @@ import java.io.IOException;
import java.io.Reader;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
* Converts tabs to spaces.
@@ -76,8 +75,8 @@ import org.apache.tools.ant.types.Parameterizable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class TabsToSpaces
extends BaseFilterReader
implements Parameterizable, ChainableReader
extends BaseParamFilterReader
implements ChainableReader
{
/** The default tab length is 8 */
private static final int DEFAULT_TAB_LENGTH = 8;
@@ -85,12 +84,6 @@ public final class TabsToSpaces
/** The name that param recognizes to set the tablength. */
private static final String TAB_LENGTH_KEY = "tablength";

/** The passed in parameter array. */
private Parameter[] parameters;

/** Have the parameters passed been interpreted? */
private boolean initialized;

/** Default tab length. */
private int tabLength = DEFAULT_TAB_LENGTH;

@@ -154,20 +147,6 @@ public final class TabsToSpaces
return tabLength;
}

/**
* Set the initialized status.
*/
private final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
private final boolean getInitialized() {
return initialized;
}

/**
* Create a new TabsToSpaces object using the passed in
* Reader for instantiation.
@@ -179,24 +158,17 @@ public final class TabsToSpaces
return newFilter;
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
setInitialized(false);
}

/**
* Initialize tokens
*/
private final void initialize() {
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (parameters[i] != null) {
if (TAB_LENGTH_KEY.equals(parameters[i].getName())) {
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (params[i] != null) {
if (TAB_LENGTH_KEY.equals(params[i].getName())) {
tabLength =
new Integer(parameters[i].getValue()).intValue();
new Integer(params[i].getValue()).intValue();
break;
}
}


+ 16
- 61
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/TailFilter.java View File

@@ -57,7 +57,6 @@ import java.io.IOException;
import java.io.Reader;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
* Read the last n lines. Default is last 10 lines.
@@ -76,27 +75,18 @@ import org.apache.tools.ant.types.Parameterizable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class TailFilter
extends BaseFilterReader
implements Parameterizable, ChainableReader
extends BaseParamFilterReader
implements ChainableReader
{
/** The name that param recognizes to set the number of lines. */
private static final String LINES_KEY = "lines";

/** The passed in parameter array. */
private Parameter[] parameters;

/** Have the parameters passed been interpreted? */
private boolean initialized = false;

/** Number of lines currently read in. */
private long linesRead = 0;

/** Default number of lines returned. */
private long lines = 10;

/** If the next character being read is a linefeed, must it be ignored? */
private boolean ignoreLineFeed = false;

/** Buffer to hold in characters read ahead. */
private char[] buffer = new char[4096];

@@ -156,31 +146,17 @@ public final class TailFilter
}
}

if (ignoreLineFeed) {
if (ch == '\n') {
ch = in.read();
}
ignoreLineFeed = false;
}

switch (ch) {
case '\r':
ch = '\n';
ignoreLineFeed = true;
//fall through
case '\n':
linesRead++;
if (ch == '\n') {
++linesRead;

if (linesRead == lines + 1) {
int i = 0;
for (i = returnedCharPos + 1; buffer[i] != '\n'; i++) {
}
returnedCharPos = i;
linesRead--;
if (linesRead == lines) {
int i = 0;
for (i = returnedCharPos + 1; buffer[i] != '\n'; i++) {
}
break;
}
if (ch == -1) {
returnedCharPos = i;
--linesRead;
}
} else if (ch == -1) {
break;
}

@@ -212,20 +188,6 @@ public final class TailFilter
return lines;
}

/**
* Set the initialized status.
*/
private final void setInitialized(final boolean initialized) {
this.initialized = initialized;
}

/**
* Get the initialized status.
*/
private final boolean getInitialized() {
return initialized;
}

/**
* Create a new TailFilter using the passed in
* Reader for instantiation.
@@ -237,22 +199,15 @@ public final class TailFilter
return newFilter;
}

/**
* Set Parameters
*/
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
setInitialized(false);
}

/**
* Scan for the lines parameter.
*/
private final void initialize() {
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (LINES_KEY.equals(parameters[i].getName())) {
setLines(new Long(parameters[i].getValue()).longValue());
Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if (LINES_KEY.equals(params[i].getName())) {
setLines(new Long(params[i].getValue()).longValue());
break;
}
}


proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/ChainReaderHelper.java → proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/util/ChainReaderHelper.java View File

@@ -51,7 +51,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.util;
package org.apache.tools.ant.filters.util;

import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;

+ 8
- 6
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java View File

@@ -57,7 +57,7 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.FilterChain;
import org.apache.tools.ant.util.ChainReaderHelper;
import org.apache.tools.ant.filters.util.ChainReaderHelper;

import java.io.*;
import java.util.Vector;
@@ -197,12 +197,14 @@ public final class LoadFile extends Task {

String text = crh.processStream();

if(evaluateProperties) {
text = project.replaceProperties(text);
if (text != null) {
if(evaluateProperties) {
text = project.replaceProperties(text);
}
project.setNewProperty(property, text);
log("loaded " + text.length() + " characters",Project.MSG_VERBOSE);
log(property+" := "+text,Project.MSG_DEBUG);
}
project.setNewProperty(property, text);
log("loaded " + text.length() + " characters",Project.MSG_VERBOSE);
log(property+" := "+text,Project.MSG_DEBUG);

} catch (final IOException ioe) {
final String message = "Unable to load file: " + ioe.toString();


+ 1
- 1
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java View File

@@ -57,7 +57,7 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.FilterChain;
import org.apache.tools.ant.util.ChainReaderHelper;
import org.apache.tools.ant.filters.util.ChainReaderHelper;

import java.io.*;
import java.util.Vector;


Loading…
Cancel
Save