@@ -676,7 +680,10 @@
The comparison, computing of the hashvalue and the store is done by implementation
of special interfaces. Therefore they may provide additional parameters.
- The <modified>
selector can be used as ResourceSelector.
+
The <modified>
selector can be used as a
+ ResourceSelector (see the
+ <restrict>
+ ResourceCollection).
In that case it maps simple file resources to files and does its job. If the
resource is from another type, the <modified>
selector tries
to (attention!) copy the content into a local file for computing the
diff --git a/src/etc/testcases/types/resources/selectors/build.xml b/src/etc/testcases/types/resources/selectors/build.xml
deleted file mode 100755
index d28c7317d..000000000
--- a/src/etc/testcases/types/resources/selectors/build.xml
+++ /dev/null
@@ -1,418 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
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 b66e6a561..218acd15c 100644
--- a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
@@ -27,14 +27,18 @@ import java.io.InputStreamReader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Parameter;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.resources.FileResource;
+import org.apache.tools.ant.types.resources.selectors.ResourceSelector;
+import org.apache.tools.ant.util.FileUtils;
/**
- * Selector that filters files based on whether they contain a
+ * Selector that filters files/resources based on whether they contain a
* particular string.
*
* @since 1.5
*/
-public class ContainsSelector extends BaseExtendSelector {
+public class ContainsSelector extends BaseExtendSelector implements ResourceSelector {
private String contains = null;
private boolean casesensitive = true;
@@ -61,19 +65,11 @@ public class ContainsSelector extends BaseExtendSelector {
*/
public String toString() {
StringBuffer buf = new StringBuffer("{containsselector text: ");
- buf.append(contains);
+ buf.append('"').append(contains).append('"');
buf.append(" casesensitive: ");
- if (casesensitive) {
- buf.append("true");
- } else {
- buf.append("false");
- }
+ buf.append(casesensitive ? "true" : "false");
buf.append(" ignorewhitespace: ");
- if (ignorewhitespace) {
- buf.append("true");
- } else {
- buf.append("false");
- }
+ buf.append(ignorewhitespace ? "true" : "false");
buf.append("}");
return buf.toString();
}
@@ -153,11 +149,22 @@ public class ContainsSelector extends BaseExtendSelector {
* @return whether the file should be selected or not
*/
public boolean isSelected(File basedir, String filename, File file) {
+ return isSelected(new FileResource(file));
+ }
+
+ /**
+ * The heart of the matter. This is where the selector gets to decide
+ * on the inclusion of a Resource.
+ *
+ * @param r the Resource to check.
+ * @return whether the Resource is selected.
+ */
+ public boolean isSelected(Resource r) {
// throw BuildException on error
validate();
- if (file.isDirectory()) {
+ if (r.isDirectory()) {
return true;
}
@@ -170,8 +177,12 @@ public class ContainsSelector extends BaseExtendSelector {
}
BufferedReader in = null;
try {
- in = new BufferedReader(new InputStreamReader(
- new FileInputStream(file)));
+ in = new BufferedReader(new InputStreamReader(r.getInputStream()));
+ } catch (Exception e) {
+ throw new BuildException("Could not get InputStream from "
+ + r.toLongString(), e);
+ }
+ try {
String teststr = in.readLine();
while (teststr != null) {
if (!casesensitive) {
@@ -187,16 +198,9 @@ public class ContainsSelector extends BaseExtendSelector {
}
return false;
} catch (IOException ioe) {
- throw new BuildException("Could not read file " + filename);
+ throw new BuildException("Could not read " + r.toLongString());
} finally {
- if (in != null) {
- try {
- in.close();
- } catch (Exception e) {
- throw new BuildException("Could not close file "
- + filename);
- }
- }
+ FileUtils.close(in);
}
}
diff --git a/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml b/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
index 05aeb89e6..56df8e8ea 100755
--- a/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
+++ b/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
@@ -1,26 +1,28 @@
-
-
-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
diff --git a/src/tests/antunit/types/resources/selectors/test.xml b/src/tests/antunit/types/resources/selectors/test.xml
new file mode 100755
index 000000000..ec7dfc09d
--- /dev/null
+++ b/src/tests/antunit/types/resources/selectors/test.xml
@@ -0,0 +1,362 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/tests/junit/org/apache/tools/ant/types/ResourceSelectorsTest.java b/src/tests/junit/org/apache/tools/ant/types/ResourceSelectorsTest.java
deleted file mode 100755
index 6c129c889..000000000
--- a/src/tests/junit/org/apache/tools/ant/types/ResourceSelectorsTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.BuildFileTest;
-
-public class ResourceSelectorsTest extends BuildFileTest {
-
- public ResourceSelectorsTest(String name) {
- super(name);
- }
-
- public void setUp() {
- configureProject("src/etc/testcases/types/resources/selectors/build.xml");
- }
-
- public void testname1() {
- executeTarget("testname1");
- }
-
- public void testname2() {
- executeTarget("testname2");
- }
-
- public void testexists() {
- executeTarget("testexists");
- }
-
- public void testinstanceoftype1() {
- executeTarget("testinstanceoftype1");
- }
-
- public void testinstanceoftype2() {
- executeTarget("testinstanceoftype2");
- }
-
- public void testinstanceofclass() {
- executeTarget("testinstanceofclass");
- }
-
- public void testtype() {
- executeTarget("testtype");
- }
-
- public void testdate() {
- executeTarget("testdate");
- }
-
- public void testsize() {
- executeTarget("testsize");
- }
-
- public void testand() {
- executeTarget("testand");
- }
-
- public void testor() {
- executeTarget("testor");
- }
-
- public void testnot() {
- executeTarget("testnot");
- }
-
- public void testnone() {
- executeTarget("testnone");
- }
-
- public void testmajority1() {
- executeTarget("testmajority1");
- }
-
- public void testmajority2() {
- executeTarget("testmajority2");
- }
-
- public void testmajority3() {
- executeTarget("testmajority3");
- }
-
- public void testmajority4() {
- executeTarget("testmajority4");
- }
-
-}