Selects all the Java source files which were modified in the
1.5 release.
@@ -385,11 +393,11 @@
@@ -408,18 +416,18 @@
present |
- Whether we are requiring that a file is present in
+ | Whether we are requiring that a file is present in
the src directory tree only, or in both the src and the target
directory tree. Valid values are:
- - srconly - select files only if they are in the src
+
- srconly - select files only if they are in the src
directory tree but not in the target directory tree
- both - select files only if they are present both in the
src and target directory trees
Default is both. Setting this attribute to "srconly"
- is equivalent to wrapping the selector in the <not>
- selector container.
+ is equivalent to wrapping the selector in the <not>
+ selector container.
|
No |
@@ -433,7 +441,7 @@
</fileset>
- Selects all the Java source files which are new in the
+
Selects all the Java source files which are new in the
1.5 release.
@@ -560,7 +568,7 @@
soon as it finds a selector that does not select the file,
so it is not guaranteed to check every selector.
-
+
Here is an example of how to use the And Selector:
@@ -614,8 +622,8 @@
</fileset>
- Selects all the HTML files which contain at least two of the three
- phrases "project", "taskdef", and "IntrospectionHelper" (this last phrase must
+
Selects all the HTML files which contain at least two of the three
+ phrases "project", "taskdef", and "IntrospectionHelper" (this last phrase must
match case exactly).
@@ -628,7 +636,7 @@
soon as it finds a selector that selects the file,
so it is not guaranteed to check every selector.
-
+
Here is an example of how to use the None Selector:
@@ -642,7 +650,7 @@
</fileset>
- Selects only Java files which do not have equivalent java or
+
Selects only Java files which do not have equivalent java or
class files in the dest directory.
@@ -653,7 +661,7 @@
The <not>
tag reverses the meaning of the
single selector it contains.
-
+
Here is an example of how to use the Not Selector:
@@ -677,7 +685,7 @@
soon as it finds a selector that selects the file,
so it is not guaranteed to check every selector.
-
+
Here is an example of how to use the Or Selector:
@@ -691,7 +699,7 @@
</fileset>
- Selects all the files in the top directory along with all the
+
Selects all the files in the top directory along with all the
image files below it.
diff --git a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
index e84e60eff..4d4135a00 100644
--- a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
@@ -74,8 +74,10 @@ public class ContainsSelector extends BaseExtendSelector {
private String contains = null;
private boolean casesensitive = true;
+ private boolean ignorewhitespace = false;
public final static String CONTAINS_KEY = "text";
public final static String CASE_KEY = "casesensitive";
+ public final static String WHITESPACE_KEY = "ignorewhitespace";
public ContainsSelector() {
@@ -90,6 +92,12 @@ public class ContainsSelector extends BaseExtendSelector {
} else {
buf.append("false");
}
+ buf.append(" ignorewhitespace: ");
+ if (ignorewhitespace) {
+ buf.append("true");
+ } else {
+ buf.append("false");
+ }
buf.append("}");
return buf.toString();
}
@@ -112,6 +120,15 @@ public class ContainsSelector extends BaseExtendSelector {
this.casesensitive = casesensitive;
}
+ /**
+ * Whether to ignore whitespace in the string being searched.
+ *
+ * @param whitespace whether to ignore any whitespace (spaces, tabs, etc.) in the searchstring
+ */
+ public void setIgnorewhitespace(boolean ignorewhitespace) {
+ this.ignorewhitespace = ignorewhitespace;
+ }
+
/**
* When using this as a custom selector, this method will be called.
* It translates each parameter into the appropriate setXXX() call.
@@ -130,6 +147,10 @@ public class ContainsSelector extends BaseExtendSelector {
setCasesensitive(Project.toBoolean(
parameters[i].getValue()));
}
+ else if (WHITESPACE_KEY.equalsIgnoreCase(paramname)) {
+ setIgnorewhitespace(Project.toBoolean(
+ parameters[i].getValue()));
+ }
else {
setError("Invalid parameter " + paramname);
}
@@ -170,6 +191,9 @@ public class ContainsSelector extends BaseExtendSelector {
if (!casesensitive) {
userstr = contains.toLowerCase();
}
+ if (ignorewhitespace) {
+ userstr = SelectorUtils.removeWhitespace(userstr);
+ }
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
@@ -179,6 +203,9 @@ public class ContainsSelector extends BaseExtendSelector {
if (!casesensitive) {
teststr = teststr.toLowerCase();
}
+ if (ignorewhitespace) {
+ teststr = SelectorUtils.removeWhitespace(teststr);
+ }
if (teststr.indexOf(userstr) > -1) {
return true;
}
diff --git a/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java b/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
index 45a2ca4c5..e2861e6f6 100644
--- a/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
+++ b/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
@@ -555,5 +555,24 @@ strLoop:
return false;
}
+ /**
+ * "Flattens" a string by removing all whitespace (space, tab, linefeed,
+ * carriage return, and formfeed). This uses StringTokenizer and the
+ * default set of tokens as documented in the single arguement constructor.
+ *
+ * @param input a String to remove all whitespace.
+ * @return a String that has had all whitespace removed.
+ */
+ public static String removeWhitespace(String input) {
+ StringBuffer result = new StringBuffer();
+ if (input != null) {
+ StringTokenizer st = new StringTokenizer(input);
+ while (st.hasMoreTokens()){
+ result.append(st.nextToken());
+ }
+ }
+ return result.toString();
+ }
+
}
diff --git a/src/testcases/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java b/src/testcases/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java
index e7b670a7c..f10192683 100644
--- a/src/testcases/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java
+++ b/src/testcases/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java
@@ -143,6 +143,18 @@ public class ContainsSelectorTest extends BaseSelectorTest {
results = selectionString(s);
assertEquals("TFFFTFFFFFFT", results);
+ s = (ContainsSelector)getInstance();
+ s.setText("ApacheAnt");
+ s.setIgnorewhitespace(true);
+ results = selectionString(s);
+ assertEquals("TFFFTFFFFFFT", results);
+
+ s = (ContainsSelector)getInstance();
+ s.setText("A p a c h e A n t");
+ s.setIgnorewhitespace(true);
+ results = selectionString(s);
+ assertEquals("TFFFTFFFFFFT", results);
+
}
finally {
cleanupBed();