@@ -19,6 +19,7 @@ package org.apache.tools.ant.filters;
import java.io.IOException;
import java.io.IOException;
import java.io.Reader;
import java.io.Reader;
import java.util.Vector;
import java.util.Vector;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameter;
/**
/**
@@ -49,6 +50,9 @@ public final class LineContains
/** Parameter name for the words to filter on. */
/** Parameter name for the words to filter on. */
private static final String CONTAINS_KEY = "contains";
private static final String CONTAINS_KEY = "contains";
/** Parameter name for the words to filter on. */
private static final String NEGATE_KEY = "negate";
/** Vector that holds the strings that input lines must contain. */
/** Vector that holds the strings that input lines must contain. */
private Vector contains = new Vector();
private Vector contains = new Vector();
@@ -59,6 +63,8 @@ public final class LineContains
*/
*/
private String line = null;
private String line = null;
private boolean negate = false;
/**
/**
* Constructor for "dummy" instances.
* Constructor for "dummy" instances.
*
*
@@ -104,31 +110,22 @@ public final class LineContains
line = line.substring(1);
line = line.substring(1);
}
}
} else {
} else {
line = readLine();
final int containsSize = contains.size();
final int containsSize = contains.size();
while (line != null) {
for (int i = 0; i < containsSize; i++) {
for (line = readLine(); line != null; line = readLine()) {
boolean matches = true;
for (int i = 0; matches && i < containsSize; i++) {
String containsStr = (String) contains.elementAt(i);
String containsStr = (String) contains.elementAt(i);
if (line.indexOf(containsStr) == -1) {
line = null;
break;
}
matches = line.indexOf(containsStr) >= 0;
}
}
if (line == null) {
// line didn't match
line = readLine();
} else {
if (matches ^ isNegated()) {
break;
break;
}
}
}
}
if (line != null) {
if (line != null) {
return read();
return read();
}
}
}
}
return ch;
return ch;
}
}
@@ -142,6 +139,22 @@ public final class LineContains
this.contains.addElement(contains.getValue());
this.contains.addElement(contains.getValue());
}
}
/**
* Set the negation mode. Default false (no negation).
* @param b the boolean negation mode to set.
*/
public void setNegate(boolean b) {
negate = b;
}
/**
* Find out whether we have been negated.
* @return boolean negation flag.
*/
public boolean isNegated() {
return negate;
}
/**
/**
* Sets the vector of words which must be contained within a line read
* Sets the vector of words which must be contained within a line read
* from the original stream in order for it to match this filter.
* from the original stream in order for it to match this filter.
@@ -179,7 +192,7 @@ public final class LineContains
public Reader chain(final Reader rdr) {
public Reader chain(final Reader rdr) {
LineContains newFilter = new LineContains(rdr);
LineContains newFilter = new LineContains(rdr);
newFilter.setContains(getContains());
newFilter.setContains(getContains());
newFilter.setInitialized(true );
newFilter.setNegate(isNegated() );
return newFilter;
return newFilter;
}
}
@@ -192,6 +205,8 @@ public final class LineContains
for (int i = 0; i < params.length; i++) {
for (int i = 0; i < params.length; i++) {
if (CONTAINS_KEY.equals(params[i].getType())) {
if (CONTAINS_KEY.equals(params[i].getType())) {
contains.addElement(params[i].getValue());
contains.addElement(params[i].getValue());
} else if (NEGATE_KEY.equals(params[i].getType())) {
setNegate(Project.toBoolean(params[i].getValue()));
}
}
}
}
}
}