bodewig 02/05/29 07:46:05
Modified: docs/manual/CoreTypes Tag: ANT_15_BRANCH
selectors-program.html
src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
MatchingTask.java
src/main/org/apache/tools/ant/types Tag: ANT_15_BRANCH
AbstractFileSet.java
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
Submitted by: Bruce Atherton <[EMAIL PROTECTED]>
Revision Changes Path
No revision
No revision
1.1.2.2 +35 -16
jakarta-ant/docs/manual/CoreTypes/Attic/selectors-program.html
Index: selectors-program.html
===================================================================
RCS file:
/home/cvs/jakarta-ant/docs/manual/CoreTypes/Attic/selectors-program.html,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- selectors-program.html 10 May 2002 15:40:31 -0000 1.1.2.1
+++ selectors-program.html 29 May 2002 14:46:05 -0000 1.1.2.2
@@ -1,24 +1,23 @@
<html>
<head>
- <meta http-equiv="Content-Language" content="en-us">
- <title>Programming Selectors in Ant</title>
- </head>
-
+ <meta http-equiv="Content-Language" content="en-us">
+ <title>Programming Selectors in Ant</title>
+ </head>
+
<body>
<h2>Programming your own Selectors</h2>
- <h3>Selector Programming API</h3>
-
- <p>Want to define your own selectors? It's easy!</p>
+ <h3>Selector Programming API</h3>
+
+ <p>Want to define your own selectors? It's easy!</p>
- <p>First, pick the type of selector that you want to define. There
+ <p>First, pick the type of selector that you want to define. There
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
+ <p>This is the category that Ant provides specifically for youto
define your own Selectors. Anywhere you want to use your selector
you use the <code><custom></code> element and specify
the class name of your selector within it. See the
@@ -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><param></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 © 2002 Apache Software
+Foundation. All rights Reserved.</p>
</body>
-
-</html>
+
+</html>
No revision
No revision
1.25.2.1 +163 -15
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java
Index: MatchingTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java,v
retrieving revision 1.25
retrieving revision 1.25.2.1
diff -u -r1.25 -r1.25.2.1
--- MatchingTask.java 17 Apr 2002 05:50:10 -0000 1.25
+++ MatchingTask.java 29 May 2002 14:46:05 -0000 1.25.2.1
@@ -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);
+ }
}
No revision
No revision
1.5.2.5 +4 -1
jakarta-ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java
Index: AbstractFileSet.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java,v
retrieving revision 1.5.2.4
retrieving revision 1.5.2.5
diff -u -r1.5.2.4 -r1.5.2.5
--- AbstractFileSet.java 24 May 2002 14:24:16 -0000 1.5.2.4
+++ AbstractFileSet.java 29 May 2002 14:46:05 -0000 1.5.2.5
@@ -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]>