You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by br...@apache.org on 2003/02/04 00:03:03 UTC
cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/types/selectors ContainsSelectorTest.java
bruce 2003/02/03 15:03:03
Modified: docs/manual/CoreTypes selectors.html
src/main/org/apache/tools/ant/types/selectors
ContainsSelector.java SelectorUtils.java
src/testcases/org/apache/tools/ant/types/selectors
ContainsSelectorTest.java
Log:
Added an option to the ContainsSelector to ignore whitespace.
Submitted by Elizabeth Cooper (with some modifications)
Revision Changes Path
1.8 +34 -26 jakarta-ant/docs/manual/CoreTypes/selectors.html
Index: selectors.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTypes/selectors.html,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- selectors.html 20 Jan 2003 08:09:01 -0000 1.7
+++ selectors.html 3 Feb 2003 23:03:02 -0000 1.8
@@ -14,18 +14,18 @@
<h3>How to use a Selector</h3>
- <p>A selector is an element of FileSet, and appears within it. It can
+ <p>A selector is an element of FileSet, and appears within it. It can
also be defined outside of any target by using the <selector> tag
and then using it as a reference.
</p>
<p>Different selectors have different attributes. Some selectors can
- contain other selectors, and these are called
- <a href="#selectcontainers"><code>Selector Containers</code></a>.
+ contain other selectors, and these are called
+ <a href="#selectcontainers"><code>Selector Containers</code></a>.
There is also a category of selectors that allow
user-defined extensions, called
<a href="#customselect"><code>Custom Selectors</code></a>.
- The ones built in to Ant are called
+ The ones built in to Ant are called
<a href="#coreselect"><code>Core Selectors</code></a>.
</p>
@@ -88,6 +88,14 @@
</td>
<td valign="top" align="center">No</td>
</tr>
+ <tr>
+ <td valign="top">ignorewhitespace</td>
+ <td valign="top">Whether to eliminate whitespace before checking
+ for the string in the <code>text</code> attribute. Default is
+ false.
+ </td>
+ <td valign="top" align="center">No</td>
+ </tr>
</table>
<p>Here is an example of how to use the Contains Selector:</p>
@@ -164,11 +172,11 @@
<p>The <code><depend></code> tag selects files
whose last modified date is later than another, equivalent file in
another location.</p>
-
+
<p>The <code><depend></code> tag supports the use of a
- contained <a href="mapper.html"><code><mapper></code></a> element
- to define the location of the file to be compared against. If no
- <code><mapper></code> element is specified, the
+ contained <a href="mapper.html"><code><mapper></code></a> element
+ to define the location of the file to be compared against. If no
+ <code><mapper></code> element is specified, the
<code>identity</code> type mapper is used.</p>
<table border="1" cellpadding="2" cellspacing="0">
@@ -204,7 +212,7 @@
</fileset>
</pre></blockquote>
- <p>Selects all the Java source files which were modified in the
+ <p>Selects all the Java source files which were modified in the
1.5 release.
</p>
@@ -385,11 +393,11 @@
<p>The <code><present></code> tag selects files
that have an equivalent file in another directory tree.</p>
-
+
<p>The <code><present></code> tag supports the use of a
- contained <a href="mapper.html"><code><mapper></code></a> element
- to define the location of the file to be tested against. If no
- <code><mapper></code> element is specified, the
+ contained <a href="mapper.html"><code><mapper></code></a> element
+ to define the location of the file to be tested against. If no
+ <code><mapper></code> element is specified, the
<code>identity</code> type mapper is used.</p>
<table border="1" cellpadding="2" cellspacing="0">
@@ -408,18 +416,18 @@
</tr>
<tr>
<td valign="top">present</td>
- <td valign="top">Whether we are requiring that a file is present in
+ <td valign="top">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:
<ul>
- <li>srconly - select files only if they are in the src
+ <li>srconly - select files only if they are in the src
directory tree but not in the target directory tree
<li>both - select files only if they are present both in the
src and target directory trees
</ul>
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.
</td>
<td valign="top" align="center">No</td>
</tr>
@@ -433,7 +441,7 @@
</fileset>
</pre></blockquote>
- <p>Selects all the Java source files which are new in the
+ <p>Selects all the Java source files which are new in the
1.5 release.
</p>
@@ -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.
</p>
-
+
<p>Here is an example of how to use the And Selector:</p>
<blockquote><pre>
@@ -614,8 +622,8 @@
</fileset>
</pre></blockquote>
- <p>Selects all the HTML files which contain at least two of the three
- phrases "project", "taskdef", and "IntrospectionHelper" (this last phrase must
+ <p>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).
</p>
@@ -628,7 +636,7 @@
soon as it finds a selector that selects the file,
so it is not guaranteed to check every selector.
</p>
-
+
<p>Here is an example of how to use the None Selector:</p>
<blockquote><pre>
@@ -642,7 +650,7 @@
</fileset>
</pre></blockquote>
- <p>Selects only Java files which do not have equivalent java or
+ <p>Selects only Java files which do not have equivalent java or
class files in the dest directory.
</p>
@@ -653,7 +661,7 @@
<p>The <code><not></code> tag reverses the meaning of the
single selector it contains.
</p>
-
+
<p>Here is an example of how to use the Not Selector:</p>
<blockquote><pre>
@@ -677,7 +685,7 @@
soon as it finds a selector that selects the file,
so it is not guaranteed to check every selector.
</p>
-
+
<p>Here is an example of how to use the Or Selector:</p>
<blockquote><pre>
@@ -691,7 +699,7 @@
</fileset>
</pre></blockquote>
- <p>Selects all the files in the top directory along with all the
+ <p>Selects all the files in the top directory along with all the
image files below it.
</p>
1.4 +27 -0 jakarta-ant/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
Index: ContainsSelector.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContainsSelector.java 25 Jul 2002 15:21:22 -0000 1.3
+++ ContainsSelector.java 3 Feb 2003 23:03:02 -0000 1.4
@@ -74,8 +74,10 @@
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 @@
} else {
buf.append("false");
}
+ buf.append(" ignorewhitespace: ");
+ if (ignorewhitespace) {
+ buf.append("true");
+ } else {
+ buf.append("false");
+ }
buf.append("}");
return buf.toString();
}
@@ -113,6 +121,15 @@
}
/**
+ * 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 @@
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 @@
if (!casesensitive) {
userstr = contains.toLowerCase();
}
+ if (ignorewhitespace) {
+ userstr = SelectorUtils.removeWhitespace(userstr);
+ }
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
@@ -178,6 +202,9 @@
while (teststr != null) {
if (!casesensitive) {
teststr = teststr.toLowerCase();
+ }
+ if (ignorewhitespace) {
+ teststr = SelectorUtils.removeWhitespace(teststr);
}
if (teststr.indexOf(userstr) > -1) {
return true;
1.6 +19 -0 jakarta-ant/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
Index: SelectorUtils.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SelectorUtils.java 4 Dec 2002 16:42:34 -0000 1.5
+++ SelectorUtils.java 3 Feb 2003 23:03:02 -0000 1.6
@@ -555,5 +555,24 @@
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();
+ }
+
}
1.3 +12 -0 jakarta-ant/src/testcases/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java
Index: ContainsSelectorTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContainsSelectorTest.java 1 Jun 2002 12:26:43 -0000 1.2
+++ ContainsSelectorTest.java 3 Feb 2003 23:03:03 -0000 1.3
@@ -143,6 +143,18 @@
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();