Author: mbenson
Date: Fri Sep 22 14:52:53 2006
New Revision: 449103

URL: http://svn.apache.org/viewvc?view=rev&rev=449103
Log:
migrate resource selectors tests to antunit.
modify containsselector to function as a resourceselector; add test.
alphabetize resource selectors antlib.

Added:
    ant/core/trunk/src/tests/antunit/types/
    ant/core/trunk/src/tests/antunit/types/resources/
    ant/core/trunk/src/tests/antunit/types/resources/selectors/
    ant/core/trunk/src/tests/antunit/types/resources/selectors/test.xml   (with 
props)
Removed:
    ant/core/trunk/src/etc/testcases/types/resources/selectors/
    
ant/core/trunk/src/tests/junit/org/apache/tools/ant/types/ResourceSelectorsTest.java
Modified:
    ant/core/trunk/docs/manual/CoreTypes/resources.html
    ant/core/trunk/docs/manual/CoreTypes/selectors.html
    
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
    
ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml

Modified: ant/core/trunk/docs/manual/CoreTypes/resources.html
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/resources.html?view=diff&rev=449103&r1=449102&r2=449103
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/resources.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/resources.html Fri Sep 22 14:52:53 2006
@@ -457,6 +457,8 @@
       by a majority of nested resource selectors.</li>
     <li><a href="selectors.html#modified">modified</a> - select resources which
       content has changed.</li>
+    <li><a href="selectors.html#containsselect">contains</a> - select 
resources 
+      containing a particular text string.</li>
   </ul>
 
   <h4><a name="rsel.name">name</a></h4>

Modified: ant/core/trunk/docs/manual/CoreTypes/selectors.html
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/selectors.html?view=diff&rev=449103&r1=449102&r2=449103
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/selectors.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/selectors.html Fri Sep 22 14:52:53 2006
@@ -98,6 +98,10 @@
     the files defined by that fileset to only those which contain the
     string specified by the <code>text</code> attribute.
     .</p>
+    <p>The <code>&lt;contains&gt;</code> selector can be used as a
+      ResourceSelector (see the
+      <a href="resources.html#restrict">&lt;restrict&gt;</a>
+      ResourceCollection).</p>
 
     <table border="1" cellpadding="2" cellspacing="0">
       <tr>
@@ -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.</p>
 
-    <p>The <code>&lt;modified&gt;</code> selector can be used as 
ResourceSelector.
+    <p>The <code>&lt;modified&gt;</code> selector can be used as a
+      ResourceSelector (see the
+      <a href="resources.html#restrict">&lt;restrict&gt;</a>
+      ResourceCollection).
     In that case it maps simple file resources to files and does its job. If 
the
     resource is from another type, the <code>&lt;modified&gt;</code> selector 
tries
     to (<b>attention!</b>) copy the content into a local file for computing the

Modified: 
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java?view=diff&rev=449103&r1=449102&r2=449103
==============================================================================
--- 
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
 (original)
+++ 
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
 Fri Sep 22 14:52:53 2006
@@ -27,14 +27,18 @@
 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 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 @@
      * @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 @@
         }
         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 @@
             }
             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);
         }
     }
 

Modified: 
ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml?view=diff&rev=449103&r1=449102&r2=449103
==============================================================================
--- 
ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
 (original)
+++ 
ant/core/trunk/src/resources/org/apache/tools/ant/types/resources/selectors/antlib.xml
 Fri Sep 22 14:52:53 2006
@@ -1,26 +1,28 @@
 <antlib>
-  <typedef name="name"
-    classname="org.apache.tools.ant.types.resources.selectors.Name" />
-  <typedef name="not"
-    classname="org.apache.tools.ant.types.resources.selectors.Not" />
-  <typedef name="none"
-    classname="org.apache.tools.ant.types.resources.selectors.None" />
   <typedef name="and"
     classname="org.apache.tools.ant.types.resources.selectors.And" />
-  <typedef name="or"
-    classname="org.apache.tools.ant.types.resources.selectors.Or" />
+  <typedef name="contains"
+    classname="org.apache.tools.ant.types.selectors.ContainsSelector" />
+  <typedef name="date"
+    classname="org.apache.tools.ant.types.resources.selectors.Date" />
   <typedef name="exists"
     classname="org.apache.tools.ant.types.resources.selectors.Exists" />
-  <typedef name="type"
-    classname="org.apache.tools.ant.types.resources.selectors.Type" />
-  <typedef name="majority"
-    classname="org.apache.tools.ant.types.resources.selectors.Majority" />
   <typedef name="instanceof"
     classname="org.apache.tools.ant.types.resources.selectors.InstanceOf" />
-  <typedef name="size"
-    classname="org.apache.tools.ant.types.resources.selectors.Size" />
-  <typedef name="date"
-    classname="org.apache.tools.ant.types.resources.selectors.Date" />
+  <typedef name="majority"
+    classname="org.apache.tools.ant.types.resources.selectors.Majority" />
   <typedef name="modified"
     
classname="org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector"
 />
+  <typedef name="name"
+    classname="org.apache.tools.ant.types.resources.selectors.Name" />
+  <typedef name="none"
+    classname="org.apache.tools.ant.types.resources.selectors.None" />
+  <typedef name="not"
+    classname="org.apache.tools.ant.types.resources.selectors.Not" />
+  <typedef name="or"
+    classname="org.apache.tools.ant.types.resources.selectors.Or" />
+  <typedef name="size"
+    classname="org.apache.tools.ant.types.resources.selectors.Size" />
+  <typedef name="type"
+    classname="org.apache.tools.ant.types.resources.selectors.Type" />
 </antlib>

Added: ant/core/trunk/src/tests/antunit/types/resources/selectors/test.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/resources/selectors/test.xml?view=auto&rev=449103
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/resources/selectors/test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/resources/selectors/test.xml Fri Sep 
22 14:52:53 2006
@@ -0,0 +1,362 @@
+<project default="all" xmlns:au="antlib:org.apache.ant.antunit"
+         xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
+
+  <target name="testname1">
+    <au:assertTrue>
+      <resourcecount when="equal" count="2">
+        <restrict>
+          <resources>
+            <resource name="foo" />
+            <resource name="bar" />
+            <resource name="baz" />
+            <resource name="boo" />
+            <resource name="bang" />
+          </resources>
+          <rsel:name name="ba?" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testname2">
+    <au:assertTrue>
+      <resourcecount when="equal" count="3">
+        <restrict>
+          <resources>
+            <file file="foo" />
+            <resource name="foo" />
+            <file file="foo" basedir="${basedir}" />
+          </resources>
+          <rsel:name name="foo" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="name" depends="testname1,testname2" />
+
+  <target name="testexists">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <restrict>
+          <resources>
+            <file file="idonotexist" />
+            <resource name="foo" />
+            <resource name="foo" exists="false" />
+          </resources>
+          <rsel:exists />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testinstanceoftype1">
+    <au:assertTrue>
+      <resourcecount when="equal" count="2">
+        <restrict>
+          <resources>
+            <file file="foo" />
+            <url url="http://ant.apache.org/index.html"; />
+            <resource name="foo" />
+            <string value="foo" />
+            <file file="bar" />
+          </resources>
+          <rsel:instanceof type="file" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testinstanceoftype2">
+    <typedef name="file" uri="test"
+             classname="org.apache.tools.ant.types.resources.FileResource" />
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <restrict>
+          <resources>
+            <url file="foo" />
+            <file file="bar" xmlns="test" />
+          </resources>
+          <rsel:instanceof type="test:file" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testinstanceoftype3">
+    <typedef name="file" uri="test"
+             classname="org.apache.tools.ant.types.resources.FileResource" />
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <restrict>
+          <resources>
+            <url file="foo" />
+            <file file="bar" xmlns="test" />
+          </resources>
+          <rsel:instanceof type="file" uri="test" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testinstanceoftype"
+    depends="testinstanceoftype1,testinstanceoftype2,testinstanceoftype3" />
+
+  <target name="testinstanceofclass">
+    <au:assertTrue>
+      <resourcecount when="equal" count="7">
+        <restrict>
+          <resources>
+            <filelist dir="${basedir}" files="a,b,c,d,e,f,g" />
+          </resources>
+          <rsel:instanceof class="org.apache.tools.ant.types.Resource" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="instanceof" depends="testinstanceoftype,testinstanceofclass" />
+
+  <target name="testtype">
+    <au:assertTrue>
+      <resourcecount when="equal" count="2">
+        <restrict>
+          <resources>
+             <file file="${basedir}" />
+             <file file="${ant.file}" />
+             <resource directory="true" />
+             <resource directory="false" />
+          </resources>
+          <rsel:type type="dir" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testdate">
+    <au:assertTrue>
+      <resourcecount when="equal" count="3">
+        <restrict>
+          <resources>
+             <resource lastmodified="4" />
+             <resource lastmodified="5" />
+             <resource lastmodified="6" />
+             <resource lastmodified="7" />
+             <resource lastmodified="8" />
+          </resources>
+          <rsel:date when="after" millis="5" granularity="0" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testsize">
+    <au:assertTrue>
+      <resourcecount when="equal" count="4">
+        <restrict>
+          <resources>
+             <resource size="4" />
+             <resource size="5" />
+             <resource size="6" />
+             <resource size="7" />
+             <resource size="8" />
+          </resources>
+          <rsel:size when="le" size="7" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testand">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <restrict>
+          <resources>
+            <string value="fee" />
+            <resource name="fi" size="3" />
+            <resource name="fo" />
+            <resource name="fum" />
+          </resources>
+          <and xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
+            <name name="f?" />
+            <size size="3" />
+          </and>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testor">
+    <au:assertTrue>
+      <resourcecount when="equal" count="3">
+        <restrict>
+          <resources>
+            <string value="fee" />
+            <resource name="fi" size="3" />
+            <resource name="fo" />
+            <resource name="fum" />
+          </resources>
+          <or xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
+            <name name="f?" />
+            <size size="3" />
+          </or>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testnot">
+    <au:assertTrue>
+      <resourcecount when="equal" count="2">
+        <restrict>
+          <resources>
+            <string value="fee" />
+            <resource name="fi" size="3" />
+            <resource name="fo" />
+            <resource name="fum" />
+          </resources>
+          <not xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
+            <size size="3" />
+          </not>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testnone">
+    <au:assertTrue>
+      <resourcecount when="equal" count="1">
+        <restrict>
+          <resources>
+            <string value="fee" />
+            <resource name="fi" size="3" />
+            <resource name="fo" />
+            <resource name="fum" />
+          </resources>
+          <none xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
+            <name name="f?" />
+            <size size="3" />
+          </none>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testmajority1">
+    <au:assertTrue>
+      <resourcecount when="equal" count="2">
+        <restrict>
+          <resources>
+            <string value="fee" />
+            <resource name="fi" size="3" />
+            <resource name="fo" />
+            <resource name="fum" />
+          </resources>
+          <majority 
xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
+            <name name="f?" />
+            <size size="3" />
+            <instanceof type="string" />
+          </majority>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testmajority2">
+    <au:assertTrue>
+      <resourcecount when="equal" count="3">
+        <restrict>
+          <resources>
+            <string value="fee" />
+            <resource name="fi" size="3" />
+            <resource name="fo" />
+            <resource name="fum" />
+          </resources>
+          <majority 
xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
+            <name name="f?" />
+            <size size="3" />
+            <instanceof type="resource" />
+          </majority>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testmajority3">
+    <au:assertTrue>
+      <resourcecount when="equal" count="3">
+        <restrict>
+          <resources>
+            <string value="fee" />
+            <resource name="fi" size="3" />
+            <resource name="fo" />
+            <resource name="fum" />
+          </resources>
+          <majority allowtie="true"
+              xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
+            <name name="f?" />
+            <size size="3" />
+            <instanceof type="string" />
+            <exists />
+          </majority>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testmajority4">
+    <au:assertTrue>
+      <resourcecount when="equal" count="2">
+        <restrict>
+          <resources>
+            <string value="fee" />
+            <resource name="fi" size="3" />
+            <resource name="fo" />
+            <resource name="fum" />
+          </resources>
+          <majority allowtie="false"
+              xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
+            <name name="f?" />
+            <size size="3" />
+            <instanceof type="string" />
+            <exists />
+          </majority>
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="testcontains">
+    <au:assertTrue>
+      <resourcecount when="equal" count="2">
+        <restrict>
+          <resources>
+            <string value="foo" />
+            <string value="bar" />
+            <string value="baz" />
+          </resources>
+          <contains text="b"
+              xmlns="antlib:org.apache.tools.ant.types.resources.selectors" />
+        </restrict>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+  <target name="majority"
+          depends="testmajority1,testmajority2,testmajority3,testmajority4" />
+
+  <target name="logical"
+          depends="testand,testor,testnone,testnot,majority" />
+
+  <target name="all"
+    
depends="name,testexists,instanceof,testtype,testdate,testsize,testcontains,logical"
 />
+
+
+
+  <!-- 
+    The tests for oata.types.selectors.ModifiedSelectorTest as 
+    ResourceSelector are in its test-buildfile 
src\etc\testcases\types\selectors.xml. 
+  -->
+
+
+</project>

Propchange: ant/core/trunk/src/tests/antunit/types/resources/selectors/test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/tests/antunit/types/resources/selectors/test.xml
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to