source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/MatchingTask.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 13.5 KB
Line 
1/*
2 * Copyright 2000-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs;
19
20import java.io.File;
21import java.util.Enumeration;
22import java.util.StringTokenizer;
23import org.apache.tools.ant.DirectoryScanner;
24import org.apache.tools.ant.Project;
25import org.apache.tools.ant.Task;
26import org.apache.tools.ant.types.FileSet;
27import org.apache.tools.ant.types.PatternSet;
28import org.apache.tools.ant.types.selectors.AndSelector;
29import org.apache.tools.ant.types.selectors.ContainsRegexpSelector;
30import org.apache.tools.ant.types.selectors.ContainsSelector;
31import org.apache.tools.ant.types.selectors.DateSelector;
32import org.apache.tools.ant.types.selectors.DependSelector;
33import org.apache.tools.ant.types.selectors.DepthSelector;
34import org.apache.tools.ant.types.selectors.DifferentSelector;
35import org.apache.tools.ant.types.selectors.ExtendSelector;
36import org.apache.tools.ant.types.selectors.FileSelector;
37import org.apache.tools.ant.types.selectors.FilenameSelector;
38import org.apache.tools.ant.types.selectors.MajoritySelector;
39import org.apache.tools.ant.types.selectors.NoneSelector;
40import org.apache.tools.ant.types.selectors.NotSelector;
41import org.apache.tools.ant.types.selectors.OrSelector;
42import org.apache.tools.ant.types.selectors.PresentSelector;
43import org.apache.tools.ant.types.selectors.SelectSelector;
44import org.apache.tools.ant.types.selectors.SelectorContainer;
45import org.apache.tools.ant.types.selectors.SizeSelector;
46import org.apache.tools.ant.types.selectors.TypeSelector;
47import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector;
48
49/**
50 * This is an abstract task that should be used by all those tasks that
51 * require to include or exclude files based on pattern matching.
52 *
53 * @since Ant 1.1
54 */
55
56public abstract class MatchingTask extends Task implements SelectorContainer {
57
58 protected FileSet fileset = new FileSet();
59
60 /**
61 * @see org.apache.tools.ant.ProjectComponent#setProject
62 */
63 public void setProject(Project project) {
64 super.setProject(project);
65 fileset.setProject(project);
66 }
67
68 /**
69 * add a name entry on the include list
70 * @return a NameEntry object to be configured
71 */
72 public PatternSet.NameEntry createInclude() {
73 return fileset.createInclude();
74 }
75
76 /**
77 * add a name entry on the include files list
78 * @return an NameEntry object to be configured
79 */
80 public PatternSet.NameEntry createIncludesFile() {
81 return fileset.createIncludesFile();
82 }
83
84 /**
85 * add a name entry on the exclude list
86 * @return an NameEntry object to be configured
87 */
88 public PatternSet.NameEntry createExclude() {
89 return fileset.createExclude();
90 }
91
92 /**
93 * add a name entry on the include files list
94 * @return an NameEntry object to be configured
95 */
96 public PatternSet.NameEntry createExcludesFile() {
97 return fileset.createExcludesFile();
98 }
99
100 /**
101 * add a set of patterns
102 * @return PatternSet object to be configured
103 */
104 public PatternSet createPatternSet() {
105 return fileset.createPatternSet();
106 }
107
108 /**
109 * Sets the set of include patterns. Patterns may be separated by a comma
110 * or a space.
111 *
112 * @param includes the string containing the include patterns
113 */
114 public void setIncludes(String includes) {
115 fileset.setIncludes(includes);
116 }
117
118 /**
119 * Set this to be the items in the base directory that you want to be
120 * included. You can also specify "*" for the items (ie: items="*")
121 * and it will include all the items in the base directory.
122 *
123 * @param itemString the string containing the files to include.
124 */
125 public void XsetItems(String itemString) {
126 log("The items attribute is deprecated. "
127 + "Please use the includes attribute.", Project.MSG_WARN);
128 if (itemString == null || itemString.equals("*")
129 || itemString.equals(".")) {
130 createInclude().setName("**");
131 } else {
132 StringTokenizer tok = new StringTokenizer(itemString, ", ");
133 while (tok.hasMoreTokens()) {
134 String pattern = tok.nextToken().trim();
135 if (pattern.length() > 0) {
136 createInclude().setName(pattern + "/**");
137 }
138 }
139 }
140 }
141
142 /**
143 * Sets the set of exclude patterns. Patterns may be separated by a comma
144 * or a space.
145 *
146 * @param excludes the string containing the exclude patterns
147 */
148 public void setExcludes(String excludes) {
149 fileset.setExcludes(excludes);
150 }
151
152 /**
153 * List of filenames and directory names to not include. They should be
154 * either , or " " (space) separated. The ignored files will be logged.
155 *
156 * @param ignoreString the string containing the files to ignore.
157 */
158 public void XsetIgnore(String ignoreString) {
159 log("The ignore attribute is deprecated."
160 + "Please use the excludes attribute.", Project.MSG_WARN);
161 if (ignoreString != null && ignoreString.length() > 0) {
162 StringTokenizer tok = new StringTokenizer(ignoreString, ", ",
163 false);
164 while (tok.hasMoreTokens()) {
165 createExclude().setName("**/" + tok.nextToken().trim() + "/**");
166 }
167 }
168 }
169
170 /**
171 * Sets whether default exclusions should be used or not.
172 *
173 * @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
174 * should be used, "false"|"off"|"no" when they
175 * shouldn't be used.
176 */
177 public void setDefaultexcludes(boolean useDefaultExcludes) {
178 fileset.setDefaultexcludes(useDefaultExcludes);
179 }
180
181 /**
182 * Returns the directory scanner needed to access the files to process.
183 */
184 protected DirectoryScanner getDirectoryScanner(File baseDir) {
185 fileset.setDir(baseDir);
186 return fileset.getDirectoryScanner(getProject());
187 }
188
189 /**
190 * Sets the name of the file containing the includes patterns.
191 *
192 * @param includesfile A string containing the filename to fetch
193 * the include patterns from.
194 */
195 public void setIncludesfile(File includesfile) {
196 fileset.setIncludesfile(includesfile);
197 }
198
199 /**
200 * Sets the name of the file containing the includes patterns.
201 *
202 * @param excludesfile A string containing the filename to fetch
203 * the include patterns from.
204 */
205 public void setExcludesfile(File excludesfile) {
206 fileset.setExcludesfile(excludesfile);
207 }
208
209 /**
210 * Sets case sensitivity of the file system
211 *
212 * @param isCaseSensitive "true"|"on"|"yes" if file system is case
213 * sensitive, "false"|"off"|"no" when not.
214 */
215 public void setCaseSensitive(boolean isCaseSensitive) {
216 fileset.setCaseSensitive(isCaseSensitive);
217 }
218
219 /**
220 * Sets whether or not symbolic links should be followed.
221 *
222 * @param followSymlinks whether or not symbolic links should be followed
223 */
224 public void setFollowSymlinks(boolean followSymlinks) {
225 fileset.setFollowSymlinks(followSymlinks);
226 }
227
228 /**
229 * Indicates whether there are any selectors here.
230 *
231 * @return whether any selectors are in this container
232 */
233 public boolean hasSelectors() {
234 return fileset.hasSelectors();
235 }
236
237 /**
238 * Gives the count of the number of selectors in this container
239 *
240 * @return the number of selectors in this container
241 */
242 public int selectorCount() {
243 return fileset.selectorCount();
244 }
245
246 /**
247 * Returns the set of selectors as an array.
248 * @param p the current project
249 * @return an array of selectors in this container
250 */
251 public FileSelector[] getSelectors(Project p) {
252 return fileset.getSelectors(p);
253 }
254
255 /**
256 * Returns an enumerator for accessing the set of selectors.
257 *
258 * @return an enumerator that goes through each of the selectors
259 */
260 public Enumeration selectorElements() {
261 return fileset.selectorElements();
262 }
263
264 /**
265 * Add a new selector into this container.
266 *
267 * @param selector the new selector to add
268 */
269 public void appendSelector(FileSelector selector) {
270 fileset.appendSelector(selector);
271 }
272
273 /* Methods below all add specific selectors */
274
275 /**
276 * add a "Select" selector entry on the selector list
277 * @param selector the selector to add
278 */
279 public void addSelector(SelectSelector selector) {
280 fileset.addSelector(selector);
281 }
282
283 /**
284 * add an "And" selector entry on the selector list
285 * @param selector the selector to add
286 */
287 public void addAnd(AndSelector selector) {
288 fileset.addAnd(selector);
289 }
290
291 /**
292 * add an "Or" selector entry on the selector list
293 * @param selector the selector to add
294 */
295 public void addOr(OrSelector selector) {
296 fileset.addOr(selector);
297 }
298
299 /**
300 * add a "Not" selector entry on the selector list
301 * @param selector the selector to add
302 */
303 public void addNot(NotSelector selector) {
304 fileset.addNot(selector);
305 }
306
307 /**
308 * add a "None" selector entry on the selector list
309 * @param selector the selector to add
310 */
311 public void addNone(NoneSelector selector) {
312 fileset.addNone(selector);
313 }
314
315 /**
316 * add a majority selector entry on the selector list
317 * @param selector the selector to add
318 */
319 public void addMajority(MajoritySelector selector) {
320 fileset.addMajority(selector);
321 }
322
323 /**
324 * add a selector date entry on the selector list
325 * @param selector the selector to add
326 */
327 public void addDate(DateSelector selector) {
328 fileset.addDate(selector);
329 }
330
331 /**
332 * add a selector size entry on the selector list
333 * @param selector the selector to add
334 */
335 public void addSize(SizeSelector selector) {
336 fileset.addSize(selector);
337 }
338
339 /**
340 * add a selector filename entry on the selector list
341 * @param selector the selector to add
342 */
343 public void addFilename(FilenameSelector selector) {
344 fileset.addFilename(selector);
345 }
346
347 /**
348 * add an extended selector entry on the selector list
349 * @param selector the selector to add
350 */
351 public void addCustom(ExtendSelector selector) {
352 fileset.addCustom(selector);
353 }
354
355 /**
356 * add a contains selector entry on the selector list
357 * @param selector the selector to add
358 */
359 public void addContains(ContainsSelector selector) {
360 fileset.addContains(selector);
361 }
362
363 /**
364 * add a present selector entry on the selector list
365 * @param selector the selector to add
366 */
367 public void addPresent(PresentSelector selector) {
368 fileset.addPresent(selector);
369 }
370
371 /**
372 * add a depth selector entry on the selector list
373 * @param selector the selector to add
374 */
375 public void addDepth(DepthSelector selector) {
376 fileset.addDepth(selector);
377 }
378
379 /**
380 * add a depends selector entry on the selector list
381 * @param selector the selector to add
382 */
383 public void addDepend(DependSelector selector) {
384 fileset.addDepend(selector);
385 }
386
387 /**
388 * add a regular expression selector entry on the selector list
389 * @param selector the selector to add
390 */
391 public void addContainsRegexp(ContainsRegexpSelector selector) {
392 fileset.addContainsRegexp(selector);
393 }
394
395 /**
396 * add a type selector entry on the type list
397 * @param selector the selector to add
398 * @since ant 1.6
399 */
400 public void addDifferent(DifferentSelector selector) {
401 fileset.addDifferent(selector);
402 }
403
404 /**
405 * add a type selector entry on the type list
406 * @param selector the selector to add
407 * @since ant 1.6
408 */
409 public void addType(TypeSelector selector) {
410 fileset.addType(selector);
411 }
412
413 /**
414 * add the modified selector
415 * @param selector the selector to add
416 * @since ant 1.6
417 */
418 public void addModified(ModifiedSelector selector) {
419 fileset.addModified(selector);
420 }
421
422 /**
423 * add an arbitary selector
424 * @param selector the selector to add
425 * @since Ant 1.6
426 */
427 public void add(FileSelector selector) {
428 fileset.add(selector);
429 }
430
431 /**
432 * Accessor for the implicit fileset.
433 *
434 * @since Ant 1.5.2
435 */
436 protected final FileSet getImplicitFileSet() {
437 return fileset;
438 }
439}
Note: See TracBrowser for help on using the repository browser.