As I posted a couple of days ago based on a comment from Levente Farkas <[EMAIL PROTECTED]>, the documentation for 12 of the 26 tasks which derive from MatchingTask make the claim that they support all the attributes of fileset. With the addition of selectors to fileset, that makes for a huge mismatch between the documentation and the code, which I consider a bug. I asked which needed fixing, the documentation or the code, and got no response so I'm just going to submit this patch for fixing the code. Hopefully that is alright with everyone.

There are some issues to consider. With so many tasks being affected, it was hard to ensure that there are no bugs being introduced. I ran the test suite over them and they all passed, and I also ran selections within several existing tasks, like so:

    <jar destfile="${dest}/test.jar" basedir="${src}">
        <depth min="0" max="1"/>
    </jar>

Everything seems to be working properly. If there are any attribute or element name collisions, I didn't run into them and neither did the test suite.

Another issue is that the documentation for the 26 tasks won't specifically mention selectors for a while. Then again, many of them don't specifically mention anything about the other attributes and elements of MatchingTask, so perhaps it doesn't matter for now. Eventually, I'd like to make the documentation exactly match the output of <antstructure>, but that is a task (no pun intended) for another day. For now I'm still in the middle of writing all the selector test cases, which is taking a lot more time than I expected.

I also suggested another desirable change for MatchingTask might be to add support for a nested fileset element, but it turns out that many of the tasks which inherit from MatchingTask already do that, although many don't. Fixing this is definitely a post 1.5 project.

Finally, I've altered the "Programming Selectors" documentation as I described in my last patch submission. Hopefully it is easier to read now, as well.

Log:
Added support for selectors into MatchingTask, and therefore into all of its Task subclasses. Also added some programming notes concerning selectors to the documentation.
Index: docs/manual/CoreTypes/selectors-program.html
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/docs/manual/CoreTypes/Attic/selectors-program.html,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 selectors-program.html
--- docs/manual/CoreTypes/selectors-program.html        10 May 2002 15:40:31 
-0000      1.1.2.1
+++ docs/manual/CoreTypes/selectors-program.html        29 May 2002 02:52:33 
-0000
@@ -15,8 +15,7 @@
     are three types, and a recipe for each one follows. Chances are
     you'll want to work with the first one, Custom Selectors.</p>
 
-    <ol>
-      <li>Custom Selectors
+    <h4>Custom Selectors</h4>
 
         <p>This is the category that Ant provides specifically for you
to
         define your own Selectors. Anywhere you want to use your selector
@@ -44,7 +43,24 @@
         core selectors demonstrate how to do that because they can
         also be used as custom selectors.</p>
 
-      <li>Core Selectors
+        <p><i>Note: If you don't need to set variables on your selector
+        with the the embedded <code>&lt;param&gt;</code>
+        elements, your custom selector could just implement the
+        <code>org.apache.tools.ant.types.selectors.FileSelector</code>
+        interface rather than the full
+        <code>org.apache.tools.ant.types.selectors.ExtendFileSelector</code>
+        interface. Using the latter will give you the most flexibility,
+        though.</i></p>
+
+        <p><i>Note: If you inherit from
+        <code>org.apache.tools.ant.types.selectors.BaseExtendSelector</code>
+        or
+        <code>org.apache.tools.ant.types.selectors.BaseSelector</code>,
+        any selector container will perform a validation pass before calling
+        the <code>isSelected()</code> method. Make sure that all
+        initialization is performed before the validation is done.</i></p>
+
+      <h4>Core Selectors</h4>
 
         <p>These are the selectors used by Ant itself. To implement one of
         these, you will have to alter some of the classes contained within
@@ -92,7 +108,7 @@
             selectors are appropriate.</p>
         </ul>
 
-      <li>Selector Containers
+      <h4>Selector Containers</h4>
         <p>Got an idea for a new Selector Container? Creating a new one is
         no problem:</p>
         <ul>
@@ -116,8 +132,11 @@
             
<code>org.apache.tools.ant.types.selectors.BaseSelectorContainer</code>.
             </p>
         </ul>
-    </ol>
+
+<hr>
+<p align="center">Copyright &copy; 2002 Apache Software
+Foundation. All rights Reserved.</p>
 
   </body>
-
-</html>
+
+</html>
Index: src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java,v
retrieving revision 1.25
diff -u -r1.25 MatchingTask.java
--- src/main/org/apache/tools/ant/taskdefs/MatchingTask.java    17 Apr 2002 
05:50:10 -0000      1.25
+++ src/main/org/apache/tools/ant/taskdefs/MatchingTask.java    29 May 2002 
02:52:35 -0000
@@ -59,9 +59,11 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.PatternSet;
+import org.apache.tools.ant.types.selectors.*;
 
 import java.io.File;
 import java.util.StringTokenizer;
+import java.util.Enumeration;
 
 /**
  * This is an abstract task that should be used by all those tasks that 
@@ -74,10 +76,11 @@
  * @author Sam Ruby <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
  * @author Jon S. Stevens <a href="mailto:[EMAIL PROTECTED]">[EMAIL 
PROTECTED]</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Bruce Atherton</a>
  * @since Ant 1.1
  */
 
-public abstract class MatchingTask extends Task {
+public abstract class MatchingTask extends Task implements SelectorContainer {
 
     protected boolean useDefaultExcludes = true;
     protected FileSet fileset = new FileSet();
@@ -137,7 +140,7 @@
 
     /**
      * Set this to be the items in the base directory that you want to be
-     * included. You can also specify "*" for the items (ie: items="*") 
+     * included. You can also specify "*" for the items (ie: items="*")
      * and it will include all the items in the base directory.
      *
      * @param itemString the string containing the files to include.
@@ -177,29 +180,29 @@
      * @param ignoreString the string containing the files to ignore.
      */
     public void XsetIgnore(String ignoreString) {
-        log("The ignore attribute is deprecated." + 
+        log("The ignore attribute is deprecated." +
             "Please use the excludes attribute.",
             Project.MSG_WARN);
         if (ignoreString != null && ignoreString.length() > 0) {
-            StringTokenizer tok = new StringTokenizer(ignoreString, ", ", 
+            StringTokenizer tok = new StringTokenizer(ignoreString, ", ",
                                                       false);
             while (tok.hasMoreTokens()) {
                 createExclude().setName("**/" + tok.nextToken().trim() + 
"/**");
             }
         }
     }
-    
+
     /**
      * Sets whether default exclusions should be used or not.
      *
-     * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions 
+     * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
      *                           should be used, "false"|"off"|"no" when they
      *                           shouldn't be used.
      */
     public void setDefaultexcludes(boolean useDefaultExcludes) {
         this.useDefaultExcludes = useDefaultExcludes;
     }
-    
+
     /**
      * Returns the directory scanner needed to access the files to process.
      */
@@ -213,20 +216,165 @@
      * Sets the name of the file containing the includes patterns.
      *
      * @param includesfile A string containing the filename to fetch
-     * the include patterns from.  
+     * the include patterns from.
      */
-     public void setIncludesfile(File includesfile) {
-         fileset.setIncludesfile(includesfile);
-     }
+    public void setIncludesfile(File includesfile) {
+        fileset.setIncludesfile(includesfile);
+    }
 
     /**
      * Sets the name of the file containing the includes patterns.
      *
      * @param excludesfile A string containing the filename to fetch
-     * the include patterns from.  
+     * the include patterns from.
+     */
+    public void setExcludesfile(File excludesfile) {
+        fileset.setExcludesfile(excludesfile);
+    }
+
+    /**
+     * Indicates whether there are any selectors here.
+     *
+     * @return whether any selectors are in this container
+     */
+    public boolean hasSelectors() {
+        return fileset.hasSelectors();
+    }
+
+    /**
+     * Gives the count of the number of selectors in this container
+     *
+     * @return the number of selectors in this container
+     */
+    public int selectorCount() {
+        return fileset.selectorCount();
+    }
+
+    /**
+     * Returns the set of selectors as an array.
+     *
+     * @return an array of selectors in this container
+     */
+    public FileSelector[] getSelectors(Project p) {
+        return fileset.getSelectors(p);
+    }
+
+    /**
+     * Returns an enumerator for accessing the set of selectors.
+     *
+     * @return an enumerator that goes through each of the selectors
+     */
+    public Enumeration selectorElements() {
+        return fileset.selectorElements();
+    }
+
+    /**
+     * Add a new selector into this container.
+     *
+     * @param selector the new selector to add
+     * @return the selector that was added
+     */
+    public void appendSelector(FileSelector selector) {
+        fileset.appendSelector(selector);
+    }
+
+    /* Methods below all add specific selectors */
+
+    /**
+     * add a "Select" selector entry on the selector list
+     */
+    public void addSelector(SelectSelector selector) {
+        fileset.addSelector(selector);
+    }
+
+    /**
+     * add an "And" selector entry on the selector list
      */
-     public void setExcludesfile(File excludesfile) {
-         fileset.setExcludesfile(excludesfile);
-     }
+    public void addAnd(AndSelector selector) {
+        fileset.addAnd(selector);
+    }
+
+    /**
+     * add an "Or" selector entry on the selector list
+     */
+    public void addOr(OrSelector selector) {
+        fileset.addOr(selector);
+    }
 
+    /**
+     * add a "Not" selector entry on the selector list
+     */
+    public void addNot(NotSelector selector) {
+        fileset.addNot(selector);
+    }
+
+    /**
+     * add a "None" selector entry on the selector list
+     */
+    public void addNone(NoneSelector selector) {
+        fileset.addNone(selector);
+    }
+
+    /**
+     * add a majority selector entry on the selector list
+     */
+    public void addMajority(MajoritySelector selector) {
+        fileset.addMajority(selector);
+    }
+
+    /**
+     * add a selector date entry on the selector list
+     */
+    public void addDate(DateSelector selector) {
+        fileset.addDate(selector);
+    }
+
+    /**
+     * add a selector size entry on the selector list
+     */
+    public void addSize(SizeSelector selector) {
+        fileset.addSize(selector);
+    }
+
+    /**
+     * add a selector filename entry on the selector list
+     */
+    public void addFilename(FilenameSelector selector) {
+        fileset.addFilename(selector);
+    }
+
+    /**
+     * add an extended selector entry on the selector list
+     */
+    public void addCustom(ExtendSelector selector) {
+        fileset.addCustom(selector);
+    }
+
+    /**
+     * add a contains selector entry on the selector list
+     */
+    public void addContains(ContainsSelector selector) {
+        fileset.addContains(selector);
+    }
+
+    /**
+     * add a present selector entry on the selector list
+     */
+    public void addPresent(PresentSelector selector) {
+        fileset.addPresent(selector);
+    }
+
+    /**
+     * add a depth selector entry on the selector list
+     */
+    public void addDepth(DepthSelector selector) {
+        fileset.addDepth(selector);
+    }
+
+    /**
+     * add a depends selector entry on the selector list
+     */
+    public void addDepend(DependSelector selector) {
+        fileset.addDepend(selector);
+    }
 }
Index: src/main/org/apache/tools/ant/types/AbstractFileSet.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java,v
retrieving revision 1.5.2.4
diff -u -r1.5.2.4 AbstractFileSet.java
--- src/main/org/apache/tools/ant/types/AbstractFileSet.java    24 May 2002 
14:24:16 -0000      1.5.2.4
+++ src/main/org/apache/tools/ant/types/AbstractFileSet.java    29 May 2002 
02:52:36 -0000
@@ -118,6 +118,9 @@
         if (!additionalPatterns.isEmpty()) {
             throw noChildrenAllowed();
         }
+        if (!selectors.isEmpty()) {
+            throw noChildrenAllowed();
+        }
         super.setRefid(r);
     }
 
@@ -418,7 +421,7 @@
                 return true;
             }
         }
-        
+
         return false;
     }
 

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

Reply via email to