001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import java.io.File;
022: import java.util.Enumeration;
023: import java.util.StringTokenizer;
024: import org.apache.tools.ant.DirectoryScanner;
025: import org.apache.tools.ant.Project;
026: import org.apache.tools.ant.Task;
027: import org.apache.tools.ant.types.FileSet;
028: import org.apache.tools.ant.types.PatternSet;
029: import org.apache.tools.ant.types.selectors.AndSelector;
030: import org.apache.tools.ant.types.selectors.ContainsRegexpSelector;
031: import org.apache.tools.ant.types.selectors.ContainsSelector;
032: import org.apache.tools.ant.types.selectors.DateSelector;
033: import org.apache.tools.ant.types.selectors.DependSelector;
034: import org.apache.tools.ant.types.selectors.DepthSelector;
035: import org.apache.tools.ant.types.selectors.DifferentSelector;
036: import org.apache.tools.ant.types.selectors.ExtendSelector;
037: import org.apache.tools.ant.types.selectors.FileSelector;
038: import org.apache.tools.ant.types.selectors.FilenameSelector;
039: import org.apache.tools.ant.types.selectors.MajoritySelector;
040: import org.apache.tools.ant.types.selectors.NoneSelector;
041: import org.apache.tools.ant.types.selectors.NotSelector;
042: import org.apache.tools.ant.types.selectors.OrSelector;
043: import org.apache.tools.ant.types.selectors.PresentSelector;
044: import org.apache.tools.ant.types.selectors.SelectSelector;
045: import org.apache.tools.ant.types.selectors.SelectorContainer;
046: import org.apache.tools.ant.types.selectors.SizeSelector;
047: import org.apache.tools.ant.types.selectors.TypeSelector;
048: import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
049:
050: /**
051: * This is an abstract task that should be used by all those tasks that
052: * require to include or exclude files based on pattern matching.
053: *
054: * @since Ant 1.1
055: */
056:
057: public abstract class MatchingTask extends Task implements
058: SelectorContainer {
059:
060: // CheckStyle:VisibilityModifier OFF - bc
061: protected FileSet fileset = new FileSet();
062:
063: // CheckStyle:VisibilityModifier ON
064:
065: /** {@inheritDoc}. */
066: public void setProject(Project project) {
067: super .setProject(project);
068: fileset.setProject(project);
069: }
070:
071: /**
072: * add a name entry on the include list
073: * @return a NameEntry object to be configured
074: */
075: public PatternSet.NameEntry createInclude() {
076: return fileset.createInclude();
077: }
078:
079: /**
080: * add a name entry on the include files list
081: * @return an NameEntry object to be configured
082: */
083: public PatternSet.NameEntry createIncludesFile() {
084: return fileset.createIncludesFile();
085: }
086:
087: /**
088: * add a name entry on the exclude list
089: * @return an NameEntry object to be configured
090: */
091: public PatternSet.NameEntry createExclude() {
092: return fileset.createExclude();
093: }
094:
095: /**
096: * add a name entry on the include files list
097: * @return an NameEntry object to be configured
098: */
099: public PatternSet.NameEntry createExcludesFile() {
100: return fileset.createExcludesFile();
101: }
102:
103: /**
104: * add a set of patterns
105: * @return PatternSet object to be configured
106: */
107: public PatternSet createPatternSet() {
108: return fileset.createPatternSet();
109: }
110:
111: /**
112: * Sets the set of include patterns. Patterns may be separated by a comma
113: * or a space.
114: *
115: * @param includes the string containing the include patterns
116: */
117: public void setIncludes(String includes) {
118: fileset.setIncludes(includes);
119: }
120:
121: // CheckStyle:MethodNameCheck OFF - bc
122: /**
123: * Set this to be the items in the base directory that you want to be
124: * included. You can also specify "*" for the items (ie: items="*")
125: * and it will include all the items in the base directory.
126: *
127: * @param itemString the string containing the files to include.
128: */
129: public void XsetItems(String itemString) {
130: log("The items attribute is deprecated. "
131: + "Please use the includes attribute.",
132: Project.MSG_WARN);
133: if (itemString == null || itemString.equals("*")
134: || itemString.equals(".")) {
135: createInclude().setName("**");
136: } else {
137: StringTokenizer tok = new StringTokenizer(itemString, ", ");
138: while (tok.hasMoreTokens()) {
139: String pattern = tok.nextToken().trim();
140: if (pattern.length() > 0) {
141: createInclude().setName(pattern + "/**");
142: }
143: }
144: }
145: }
146:
147: /**
148: * Sets the set of exclude patterns. Patterns may be separated by a comma
149: * or a space.
150: *
151: * @param excludes the string containing the exclude patterns
152: */
153: public void setExcludes(String excludes) {
154: fileset.setExcludes(excludes);
155: }
156:
157: /**
158: * List of filenames and directory names to not include. They should be
159: * either , or " " (space) separated. The ignored files will be logged.
160: *
161: * @param ignoreString the string containing the files to ignore.
162: */
163: public void XsetIgnore(String ignoreString) {
164: log("The ignore attribute is deprecated."
165: + "Please use the excludes attribute.",
166: Project.MSG_WARN);
167: if (ignoreString != null && ignoreString.length() > 0) {
168: StringTokenizer tok = new StringTokenizer(ignoreString,
169: ", ", false);
170: while (tok.hasMoreTokens()) {
171: createExclude().setName(
172: "**/" + tok.nextToken().trim() + "/**");
173: }
174: }
175: }
176:
177: // CheckStyle:VisibilityModifier ON
178:
179: /**
180: * Sets whether default exclusions should be used or not.
181: *
182: * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
183: * should be used, "false"|"off"|"no" when they
184: * shouldn't be used.
185: */
186: public void setDefaultexcludes(boolean useDefaultExcludes) {
187: fileset.setDefaultexcludes(useDefaultExcludes);
188: }
189:
190: /**
191: * Returns the directory scanner needed to access the files to process.
192: * @param baseDir the base directory to use with the fileset
193: * @return a directory scanner
194: */
195: protected DirectoryScanner getDirectoryScanner(File baseDir) {
196: fileset.setDir(baseDir);
197: return fileset.getDirectoryScanner(getProject());
198: }
199:
200: /**
201: * Sets the name of the file containing the includes patterns.
202: *
203: * @param includesfile A string containing the filename to fetch
204: * the include patterns from.
205: */
206: public void setIncludesfile(File includesfile) {
207: fileset.setIncludesfile(includesfile);
208: }
209:
210: /**
211: * Sets the name of the file containing the includes patterns.
212: *
213: * @param excludesfile A string containing the filename to fetch
214: * the include patterns from.
215: */
216: public void setExcludesfile(File excludesfile) {
217: fileset.setExcludesfile(excludesfile);
218: }
219:
220: /**
221: * Sets case sensitivity of the file system
222: *
223: * @param isCaseSensitive "true"|"on"|"yes" if file system is case
224: * sensitive, "false"|"off"|"no" when not.
225: */
226: public void setCaseSensitive(boolean isCaseSensitive) {
227: fileset.setCaseSensitive(isCaseSensitive);
228: }
229:
230: /**
231: * Sets whether or not symbolic links should be followed.
232: *
233: * @param followSymlinks whether or not symbolic links should be followed
234: */
235: public void setFollowSymlinks(boolean followSymlinks) {
236: fileset.setFollowSymlinks(followSymlinks);
237: }
238:
239: /**
240: * Indicates whether there are any selectors here.
241: *
242: * @return whether any selectors are in this container
243: */
244: public boolean hasSelectors() {
245: return fileset.hasSelectors();
246: }
247:
248: /**
249: * Gives the count of the number of selectors in this container
250: *
251: * @return the number of selectors in this container
252: */
253: public int selectorCount() {
254: return fileset.selectorCount();
255: }
256:
257: /**
258: * Returns the set of selectors as an array.
259: * @param p the current project
260: * @return an array of selectors in this container
261: */
262: public FileSelector[] getSelectors(Project p) {
263: return fileset.getSelectors(p);
264: }
265:
266: /**
267: * Returns an enumerator for accessing the set of selectors.
268: *
269: * @return an enumerator that goes through each of the selectors
270: */
271: public Enumeration selectorElements() {
272: return fileset.selectorElements();
273: }
274:
275: /**
276: * Add a new selector into this container.
277: *
278: * @param selector the new selector to add
279: */
280: public void appendSelector(FileSelector selector) {
281: fileset.appendSelector(selector);
282: }
283:
284: /* Methods below all add specific selectors */
285:
286: /**
287: * add a "Select" selector entry on the selector list
288: * @param selector the selector to add
289: */
290: public void addSelector(SelectSelector selector) {
291: fileset.addSelector(selector);
292: }
293:
294: /**
295: * add an "And" selector entry on the selector list
296: * @param selector the selector to add
297: */
298: public void addAnd(AndSelector selector) {
299: fileset.addAnd(selector);
300: }
301:
302: /**
303: * add an "Or" selector entry on the selector list
304: * @param selector the selector to add
305: */
306: public void addOr(OrSelector selector) {
307: fileset.addOr(selector);
308: }
309:
310: /**
311: * add a "Not" selector entry on the selector list
312: * @param selector the selector to add
313: */
314: public void addNot(NotSelector selector) {
315: fileset.addNot(selector);
316: }
317:
318: /**
319: * add a "None" selector entry on the selector list
320: * @param selector the selector to add
321: */
322: public void addNone(NoneSelector selector) {
323: fileset.addNone(selector);
324: }
325:
326: /**
327: * add a majority selector entry on the selector list
328: * @param selector the selector to add
329: */
330: public void addMajority(MajoritySelector selector) {
331: fileset.addMajority(selector);
332: }
333:
334: /**
335: * add a selector date entry on the selector list
336: * @param selector the selector to add
337: */
338: public void addDate(DateSelector selector) {
339: fileset.addDate(selector);
340: }
341:
342: /**
343: * add a selector size entry on the selector list
344: * @param selector the selector to add
345: */
346: public void addSize(SizeSelector selector) {
347: fileset.addSize(selector);
348: }
349:
350: /**
351: * add a selector filename entry on the selector list
352: * @param selector the selector to add
353: */
354: public void addFilename(FilenameSelector selector) {
355: fileset.addFilename(selector);
356: }
357:
358: /**
359: * add an extended selector entry on the selector list
360: * @param selector the selector to add
361: */
362: public void addCustom(ExtendSelector selector) {
363: fileset.addCustom(selector);
364: }
365:
366: /**
367: * add a contains selector entry on the selector list
368: * @param selector the selector to add
369: */
370: public void addContains(ContainsSelector selector) {
371: fileset.addContains(selector);
372: }
373:
374: /**
375: * add a present selector entry on the selector list
376: * @param selector the selector to add
377: */
378: public void addPresent(PresentSelector selector) {
379: fileset.addPresent(selector);
380: }
381:
382: /**
383: * add a depth selector entry on the selector list
384: * @param selector the selector to add
385: */
386: public void addDepth(DepthSelector selector) {
387: fileset.addDepth(selector);
388: }
389:
390: /**
391: * add a depends selector entry on the selector list
392: * @param selector the selector to add
393: */
394: public void addDepend(DependSelector selector) {
395: fileset.addDepend(selector);
396: }
397:
398: /**
399: * add a regular expression selector entry on the selector list
400: * @param selector the selector to add
401: */
402: public void addContainsRegexp(ContainsRegexpSelector selector) {
403: fileset.addContainsRegexp(selector);
404: }
405:
406: /**
407: * add a type selector entry on the type list
408: * @param selector the selector to add
409: * @since ant 1.6
410: */
411: public void addDifferent(DifferentSelector selector) {
412: fileset.addDifferent(selector);
413: }
414:
415: /**
416: * add a type selector entry on the type list
417: * @param selector the selector to add
418: * @since ant 1.6
419: */
420: public void addType(TypeSelector selector) {
421: fileset.addType(selector);
422: }
423:
424: /**
425: * add the modified selector
426: * @param selector the selector to add
427: * @since ant 1.6
428: */
429: public void addModified(ModifiedSelector selector) {
430: fileset.addModified(selector);
431: }
432:
433: /**
434: * add an arbitary selector
435: * @param selector the selector to add
436: * @since Ant 1.6
437: */
438: public void add(FileSelector selector) {
439: fileset.add(selector);
440: }
441:
442: /**
443: * Accessor for the implicit fileset.
444: * @return the implicit fileset
445: * @since Ant 1.5.2
446: */
447: protected final FileSet getImplicitFileSet() {
448: return fileset;
449: }
450: }
|