|
|
@@ -25,7 +25,7 @@ import org.apache.tools.ant.Project; |
|
|
import org.apache.tools.ant.types.Parameter; |
|
|
import org.apache.tools.ant.types.Parameter; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Filter which includes only those lines that contain all the user-specified |
|
|
|
|
|
|
|
|
* Filter which includes only those lines that contain the user-specified |
|
|
* strings. |
|
|
* strings. |
|
|
* |
|
|
* |
|
|
* Example: |
|
|
* Example: |
|
|
@@ -45,6 +45,19 @@ import org.apache.tools.ant.types.Parameter; |
|
|
* This will include only those lines that contain <code>foo</code> and |
|
|
* This will include only those lines that contain <code>foo</code> and |
|
|
* <code>bar</code>. |
|
|
* <code>bar</code>. |
|
|
* |
|
|
* |
|
|
|
|
|
* Starting Ant 1.10.4, the {@code matchAny} attribute can be used to control whether any one |
|
|
|
|
|
* of the user-specified strings is expected to be contained in the line or all |
|
|
|
|
|
* of them are expected to be contained. |
|
|
|
|
|
* |
|
|
|
|
|
* For example: |
|
|
|
|
|
* |
|
|
|
|
|
* <pre><linecontains matchAny="true"> |
|
|
|
|
|
* * <contains value="foo"> |
|
|
|
|
|
* * <contains value="bar"> |
|
|
|
|
|
* * </linecontains></pre> |
|
|
|
|
|
* |
|
|
|
|
|
* This will include only those lines that contain either <code>foo</code> or <code>bar</code>. |
|
|
|
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
public final class LineContains |
|
|
public final class LineContains |
|
|
extends BaseParamFilterReader |
|
|
extends BaseParamFilterReader |
|
|
@@ -67,6 +80,8 @@ public final class LineContains |
|
|
|
|
|
|
|
|
private boolean negate = false; |
|
|
private boolean negate = false; |
|
|
|
|
|
|
|
|
|
|
|
private boolean matchAny = false; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Constructor for "dummy" instances. |
|
|
* Constructor for "dummy" instances. |
|
|
* |
|
|
* |
|
|
@@ -116,9 +131,24 @@ public final class LineContains |
|
|
|
|
|
|
|
|
for (line = readLine(); line != null; line = readLine()) { |
|
|
for (line = readLine(); line != null; line = readLine()) { |
|
|
boolean matches = true; |
|
|
boolean matches = true; |
|
|
for (int i = 0; matches && i < containsSize; i++) { |
|
|
|
|
|
String containsStr = contains.elementAt(i); |
|
|
|
|
|
|
|
|
for (int i = 0; i < containsSize; i++) { |
|
|
|
|
|
final String containsStr = contains.elementAt(i); |
|
|
matches = line.contains(containsStr); |
|
|
matches = line.contains(containsStr); |
|
|
|
|
|
if (!matches) { |
|
|
|
|
|
if (this.matchAny) { |
|
|
|
|
|
// this one didn't match, but we are expected to have |
|
|
|
|
|
// any one of them match. so try next |
|
|
|
|
|
continue; |
|
|
|
|
|
} else { |
|
|
|
|
|
// all were expected to match, but this one didn't. |
|
|
|
|
|
// so no point checking the rest |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} else if (this.matchAny) { |
|
|
|
|
|
// we were expected to match any of the contains |
|
|
|
|
|
// and this one did. so no more checks needed |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if (matches ^ isNegated()) { |
|
|
if (matches ^ isNegated()) { |
|
|
break; |
|
|
break; |
|
|
@@ -157,6 +187,31 @@ public final class LineContains |
|
|
return negate; |
|
|
return negate; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* |
|
|
|
|
|
* @param matchAny True if this {@link LineContains} is considered a match, |
|
|
|
|
|
* if {@code any} of the {@code contains} value match. False |
|
|
|
|
|
* if {@code all} of the {@code contains} value are expected |
|
|
|
|
|
* to match |
|
|
|
|
|
* @since Ant 1.10.4 |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
public void setMatchAny(final boolean matchAny) { |
|
|
|
|
|
this.matchAny = matchAny; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @return Returns true if this {@link LineContains} is considered a match, |
|
|
|
|
|
* if {@code any} of the {@code contains} value match. False |
|
|
|
|
|
* if {@code all} of the {@code contains} value are expected |
|
|
|
|
|
* to match |
|
|
|
|
|
* |
|
|
|
|
|
* @since Ant 1.10.4 |
|
|
|
|
|
*/ |
|
|
|
|
|
public boolean isMatchAny() { |
|
|
|
|
|
return this.matchAny; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 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. |
|
|
@@ -195,6 +250,7 @@ public final class LineContains |
|
|
LineContains newFilter = new LineContains(rdr); |
|
|
LineContains newFilter = new LineContains(rdr); |
|
|
newFilter.setContains(getContains()); |
|
|
newFilter.setContains(getContains()); |
|
|
newFilter.setNegate(isNegated()); |
|
|
newFilter.setNegate(isNegated()); |
|
|
|
|
|
newFilter.setMatchAny(isMatchAny()); |
|
|
return newFilter; |
|
|
return newFilter; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|