1
|
|
/*
|
2
|
|
* The Apache Software License, Version 1.1
|
3
|
|
*
|
4
|
|
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
|
5
|
|
* reserved.
|
6
|
|
*
|
7
|
|
* Redistribution and use in source and binary forms, with or without
|
8
|
|
* modification, are permitted provided that the following conditions
|
9
|
|
* are met:
|
10
|
|
*
|
11
|
|
* 1. Redistributions of source code must retain the above copyright
|
12
|
|
* notice, this list of conditions and the following disclaimer.
|
13
|
|
*
|
14
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
15
|
|
* notice, this list of conditions and the following disclaimer in
|
16
|
|
* the documentation and/or other materials provided with the
|
17
|
|
* distribution.
|
18
|
|
*
|
19
|
|
* 3. The end-user documentation included with the redistribution, if
|
20
|
|
* any, must include the following acknowlegement:
|
21
|
|
* "This product includes software developed by the
|
22
|
|
* Apache Software Foundation (http://www.apache.org/)."
|
23
|
|
* Alternately, this acknowlegement may appear in the software itself,
|
24
|
|
* if and wherever such third-party acknowlegements normally appear.
|
25
|
|
*
|
26
|
|
* 4. The names "Ant" and "Apache Software
|
27
|
|
* Foundation" must not be used to endorse or promote products derived
|
28
|
|
* from this software without prior written permission. For written
|
29
|
|
* permission, please contact apache@apache.org.
|
30
|
|
*
|
31
|
|
* 5. Products derived from this software may not be called "Apache"
|
32
|
|
* nor may "Apache" appear in their names without prior written
|
33
|
|
* permission of the Apache Group.
|
34
|
|
*
|
35
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
36
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
37
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
38
|
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
39
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
40
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
41
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
42
|
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
43
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
44
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
45
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
46
|
|
* SUCH DAMAGE.
|
47
|
|
* ====================================================================
|
48
|
|
*
|
49
|
|
* This software consists of voluntary contributions made by many
|
50
|
|
* individuals on behalf of the Apache Software Foundation. For more
|
51
|
|
* information on the Apache Software Foundation, please see
|
52
|
|
* <http://www.apache.org/>.
|
53
|
|
*/
|
54
|
|
|
55
|
|
package org.apache.tools.ant.taskdefs;
|
56
|
|
|
57
|
|
import java.io.File;
|
58
|
|
import java.util.Enumeration;
|
59
|
|
import java.util.StringTokenizer;
|
60
|
|
import org.apache.tools.ant.DirectoryScanner;
|
61
|
|
import org.apache.tools.ant.Project;
|
62
|
|
import org.apache.tools.ant.Task;
|
63
|
|
import org.apache.tools.ant.types.FileSet;
|
64
|
|
import org.apache.tools.ant.types.PatternSet;
|
65
|
|
import org.apache.tools.ant.types.selectors.AndSelector;
|
66
|
|
import org.apache.tools.ant.types.selectors.ContainsSelector;
|
67
|
|
import org.apache.tools.ant.types.selectors.DateSelector;
|
68
|
|
import org.apache.tools.ant.types.selectors.DependSelector;
|
69
|
|
import org.apache.tools.ant.types.selectors.DepthSelector;
|
70
|
|
import org.apache.tools.ant.types.selectors.ExtendSelector;
|
71
|
|
import org.apache.tools.ant.types.selectors.FileSelector;
|
72
|
|
import org.apache.tools.ant.types.selectors.FilenameSelector;
|
73
|
|
import org.apache.tools.ant.types.selectors.MajoritySelector;
|
74
|
|
import org.apache.tools.ant.types.selectors.NoneSelector;
|
75
|
|
import org.apache.tools.ant.types.selectors.NotSelector;
|
76
|
|
import org.apache.tools.ant.types.selectors.OrSelector;
|
77
|
|
import org.apache.tools.ant.types.selectors.PresentSelector;
|
78
|
|
import org.apache.tools.ant.types.selectors.SelectSelector;
|
79
|
|
import org.apache.tools.ant.types.selectors.SelectorContainer;
|
80
|
|
import org.apache.tools.ant.types.selectors.SizeSelector;
|
81
|
|
|
82
|
|
/**
|
83
|
|
* This is an abstract task that should be used by all those tasks that
|
84
|
|
* require to include or exclude files based on pattern matching.
|
85
|
|
*
|
86
|
|
* @author Arnout J. Kuiper
|
87
|
|
* <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>
|
88
|
|
* @author Stefano Mazzocchi
|
89
|
|
* <a href="mailto:stefano@apache.org">stefano@apache.org</a>
|
90
|
|
* @author Sam Ruby <a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>
|
91
|
|
* @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
|
92
|
|
* @author Stefan Bodewig
|
93
|
|
* @author <a href="mailto:bruce@callenish.com">Bruce Atherton</a>
|
94
|
|
* @since Ant 1.1
|
95
|
|
*/
|
96
|
|
|
97
|
|
public abstract class MatchingTask extends Task implements SelectorContainer {
|
98
|
|
|
99
|
|
protected boolean useDefaultExcludes = true;
|
100
|
|
protected FileSet fileset = new FileSet();
|
101
|
|
|
102
|
|
/**
|
103
|
|
* @see org.apache.tools.ant.ProjectComponent#setProject
|
104
|
|
*/
|
105
|
1461
|
public void setProject(Project project) {
|
106
|
1461
|
super.setProject(project);
|
107
|
1461
|
fileset.setProject(project);
|
108
|
|
}
|
109
|
|
|
110
|
|
/**
|
111
|
|
* add a name entry on the include list
|
112
|
|
*/
|
113
|
10
|
public PatternSet.NameEntry createInclude() {
|
114
|
10
|
return fileset.createInclude();
|
115
|
|
}
|
116
|
|
|
117
|
|
/**
|
118
|
|
* add a name entry on the include files list
|
119
|
|
*/
|
120
|
0
|
public PatternSet.NameEntry createIncludesFile() {
|
121
|
0
|
return fileset.createIncludesFile();
|
122
|
|
}
|
123
|
|
|
124
|
|
/**
|
125
|
|
* add a name entry on the exclude list
|
126
|
|
*/
|
127
|
5
|
public PatternSet.NameEntry createExclude() {
|
128
|
5
|
return fileset.createExclude();
|
129
|
|
}
|
130
|
|
|
131
|
|
/**
|
132
|
|
* add a name entry on the include files list
|
133
|
|
*/
|
134
|
0
|
public PatternSet.NameEntry createExcludesFile() {
|
135
|
0
|
return fileset.createExcludesFile();
|
136
|
|
}
|
137
|
|
|
138
|
|
/**
|
139
|
|
* add a set of patterns
|
140
|
|
*/
|
141
|
0
|
public PatternSet createPatternSet() {
|
142
|
0
|
return fileset.createPatternSet();
|
143
|
|
}
|
144
|
|
|
145
|
|
/**
|
146
|
|
* Sets the set of include patterns. Patterns may be separated by a comma
|
147
|
|
* or a space.
|
148
|
|
*
|
149
|
|
* @param includes the string containing the include patterns
|
150
|
|
*/
|
151
|
79
|
public void setIncludes(String includes) {
|
152
|
79
|
fileset.setIncludes(includes);
|
153
|
|
}
|
154
|
|
|
155
|
|
/**
|
156
|
|
* Set this to be the items in the base directory that you want to be
|
157
|
|
* included. You can also specify "*" for the items (ie: items="*")
|
158
|
|
* and it will include all the items in the base directory.
|
159
|
|
*
|
160
|
|
* @param itemString the string containing the files to include.
|
161
|
|
*/
|
162
|
0
|
public void XsetItems(String itemString) {
|
163
|
0
|
log("The items attribute is deprecated. " +
|
164
|
|
"Please use the includes attribute.",
|
165
|
|
Project.MSG_WARN);
|
166
|
0
|
if (itemString == null || itemString.equals("*")
|
167
|
|
|| itemString.equals(".")) {
|
168
|
0
|
createInclude().setName("**");
|
169
|
|
} else {
|
170
|
0
|
StringTokenizer tok = new StringTokenizer(itemString, ", ");
|
171
|
0
|
while (tok.hasMoreTokens()) {
|
172
|
0
|
String pattern = tok.nextToken().trim();
|
173
|
0
|
if (pattern.length() > 0) {
|
174
|
0
|
createInclude().setName(pattern + "/**");
|
175
|
|
}
|
176
|
|
}
|
177
|
|
}
|
178
|
|
}
|
179
|
|
|
180
|
|
/**
|
181
|
|
* Sets the set of exclude patterns. Patterns may be separated by a comma
|
182
|
|
* or a space.
|
183
|
|
*
|
184
|
|
* @param excludes the string containing the exclude patterns
|
185
|
|
*/
|
186
|
2
|
public void setExcludes(String excludes) {
|
187
|
2
|
fileset.setExcludes(excludes);
|
188
|
|
}
|
189
|
|
|
190
|
|
/**
|
191
|
|
* List of filenames and directory names to not include. They should be
|
192
|
|
* either , or " " (space) separated. The ignored files will be logged.
|
193
|
|
*
|
194
|
|
* @param ignoreString the string containing the files to ignore.
|
195
|
|
*/
|
196
|
0
|
public void XsetIgnore(String ignoreString) {
|
197
|
0
|
log("The ignore attribute is deprecated." +
|
198
|
|
"Please use the excludes attribute.",
|
199
|
|
Project.MSG_WARN);
|
200
|
0
|
if (ignoreString != null && ignoreString.length() > 0) {
|
201
|
0
|
StringTokenizer tok = new StringTokenizer(ignoreString, ", ",
|
202
|
|
false);
|
203
|
0
|
while (tok.hasMoreTokens()) {
|
204
|
0
|
createExclude().setName("**/" + tok.nextToken().trim() + "/**");
|
205
|
|
}
|
206
|
|
}
|
207
|
|
}
|
208
|
|
|
209
|
|
/**
|
210
|
|
* Sets whether default exclusions should be used or not.
|
211
|
|
*
|
212
|
|
* @param useDefaultExcludes "true"|"on"|"yes" when default exclusions
|
213
|
|
* should be used, "false"|"off"|"no" when they
|
214
|
|
* shouldn't be used.
|
215
|
|
*/
|
216
|
0
|
public void setDefaultexcludes(boolean useDefaultExcludes) {
|
217
|
0
|
this.useDefaultExcludes = useDefaultExcludes;
|
218
|
|
}
|
219
|
|
|
220
|
|
/**
|
221
|
|
* Returns the directory scanner needed to access the files to process.
|
222
|
|
*/
|
223
|
66
|
protected DirectoryScanner getDirectoryScanner(File baseDir) {
|
224
|
66
|
fileset.setDir(baseDir);
|
225
|
66
|
fileset.setDefaultexcludes(useDefaultExcludes);
|
226
|
66
|
return fileset.getDirectoryScanner(getProject());
|
227
|
|
}
|
228
|
|
|
229
|
|
/**
|
230
|
|
* Sets the name of the file containing the includes patterns.
|
231
|
|
*
|
232
|
|
* @param includesfile A string containing the filename to fetch
|
233
|
|
* the include patterns from.
|
234
|
|
*/
|
235
|
0
|
public void setIncludesfile(File includesfile) {
|
236
|
0
|
fileset.setIncludesfile(includesfile);
|
237
|
|
}
|
238
|
|
|
239
|
|
/**
|
240
|
|
* Sets the name of the file containing the includes patterns.
|
241
|
|
*
|
242
|
|
* @param excludesfile A string containing the filename to fetch
|
243
|
|
* the include patterns from.
|
244
|
|
*/
|
245
|
0
|
public void setExcludesfile(File excludesfile) {
|
246
|
0
|
fileset.setExcludesfile(excludesfile);
|
247
|
|
}
|
248
|
|
|
249
|
|
/**
|
250
|
|
* Sets case sensitivity of the file system
|
251
|
|
*
|
252
|
|
* @param isCaseSensitive "true"|"on"|"yes" if file system is case
|
253
|
|
* sensitive, "false"|"off"|"no" when not.
|
254
|
|
*/
|
255
|
0
|
public void setCaseSensitive(boolean isCaseSensitive) {
|
256
|
0
|
fileset.setCaseSensitive(isCaseSensitive);
|
257
|
|
}
|
258
|
|
|
259
|
|
/**
|
260
|
|
* Sets whether or not symbolic links should be followed.
|
261
|
|
*
|
262
|
|
* @param followSymlinks whether or not symbolic links should be followed
|
263
|
|
*/
|
264
|
0
|
public void setFollowSymlinks(boolean followSymlinks) {
|
265
|
0
|
fileset.setFollowSymlinks(followSymlinks);
|
266
|
|
}
|
267
|
|
|
268
|
|
/**
|
269
|
|
* Indicates whether there are any selectors here.
|
270
|
|
*
|
271
|
|
* @return whether any selectors are in this container
|
272
|
|
*/
|
273
|
0
|
public boolean hasSelectors() {
|
274
|
0
|
return fileset.hasSelectors();
|
275
|
|
}
|
276
|
|
|
277
|
|
/**
|
278
|
|
* Gives the count of the number of selectors in this container
|
279
|
|
*
|
280
|
|
* @return the number of selectors in this container
|
281
|
|
*/
|
282
|
0
|
public int selectorCount() {
|
283
|
0
|
return fileset.selectorCount();
|
284
|
|
}
|
285
|
|
|
286
|
|
/**
|
287
|
|
* Returns the set of selectors as an array.
|
288
|
|
*
|
289
|
|
* @return an array of selectors in this container
|
290
|
|
*/
|
291
|
0
|
public FileSelector[] getSelectors(Project p) {
|
292
|
0
|
return fileset.getSelectors(p);
|
293
|
|
}
|
294
|
|
|
295
|
|
/**
|
296
|
|
* Returns an enumerator for accessing the set of selectors.
|
297
|
|
*
|
298
|
|
* @return an enumerator that goes through each of the selectors
|
299
|
|
*/
|
300
|
0
|
public Enumeration selectorElements() {
|
301
|
0
|
return fileset.selectorElements();
|
302
|
|
}
|
303
|
|
|
304
|
|
/**
|
305
|
|
* Add a new selector into this container.
|
306
|
|
*
|
307
|
|
* @param selector the new selector to add
|
308
|
|
*/
|
309
|
0
|
public void appendSelector(FileSelector selector) {
|
310
|
0
|
fileset.appendSelector(selector);
|
311
|
|
}
|
312
|
|
|
313
|
|
/* Methods below all add specific selectors */
|
314
|
|
|
315
|
|
/**
|
316
|
|
* add a "Select" selector entry on the selector list
|
317
|
|
*/
|
318
|
2
|
public void addSelector(SelectSelector selector) {
|
319
|
2
|
fileset.addSelector(selector);
|
320
|
|
}
|
321
|
|
|
322
|
|
/**
|
323
|
|
* add an "And" selector entry on the selector list
|
324
|
|
*/
|
325
|
0
|
public void addAnd(AndSelector selector) {
|
326
|
0
|
fileset.addAnd(selector);
|
327
|
|
}
|
328
|
|
|
329
|
|
/**
|
330
|
|
* add an "Or" selector entry on the selector list
|
331
|
|
*/
|
332
|
0
|
public void addOr(OrSelector selector) {
|
333
|
0
|
fileset.addOr(selector);
|
334
|
|
}
|
335
|
|
|
336
|
|
/**
|
337
|
|
* add a "Not" selector entry on the selector list
|
338
|
|
*/
|
339
|
0
|
public void addNot(NotSelector selector) {
|
340
|
0
|
fileset.addNot(selector);
|
341
|
|
}
|
342
|
|
|
343
|
|
/**
|
344
|
|
* add a "None" selector entry on the selector list
|
345
|
|
*/
|
346
|
0
|
public void addNone(NoneSelector selector) {
|
347
|
0
|
fileset.addNone(selector);
|
348
|
|
}
|
349
|
|
|
350
|
|
/**
|
351
|
|
* add a majority selector entry on the selector list
|
352
|
|
*/
|
353
|
0
|
public void addMajority(MajoritySelector selector) {
|
354
|
0
|
fileset.addMajority(selector);
|
355
|
|
}
|
356
|
|
|
357
|
|
/**
|
358
|
|
* add a selector date entry on the selector list
|
359
|
|
*/
|
360
|
0
|
public void addDate(DateSelector selector) {
|
361
|
0
|
fileset.addDate(selector);
|
362
|
|
}
|
363
|
|
|
364
|
|
/**
|
365
|
|
* add a selector size entry on the selector list
|
366
|
|
*/
|
367
|
0
|
public void addSize(SizeSelector selector) {
|
368
|
0
|
fileset.addSize(selector);
|
369
|
|
}
|
370
|
|
|
371
|
|
/**
|
372
|
|
* add a selector filename entry on the selector list
|
373
|
|
*/
|
374
|
0
|
public void addFilename(FilenameSelector selector) {
|
375
|
0
|
fileset.addFilename(selector);
|
376
|
|
}
|
377
|
|
|
378
|
|
/**
|
379
|
|
* add an extended selector entry on the selector list
|
380
|
|
*/
|
381
|
0
|
public void addCustom(ExtendSelector selector) {
|
382
|
0
|
fileset.addCustom(selector);
|
383
|
|
}
|
384
|
|
|
385
|
|
/**
|
386
|
|
* add a contains selector entry on the selector list
|
387
|
|
*/
|
388
|
0
|
public void addContains(ContainsSelector selector) {
|
389
|
0
|
fileset.addContains(selector);
|
390
|
|
}
|
391
|
|
|
392
|
|
/**
|
393
|
|
* add a present selector entry on the selector list
|
394
|
|
*/
|
395
|
0
|
public void addPresent(PresentSelector selector) {
|
396
|
0
|
fileset.addPresent(selector);
|
397
|
|
}
|
398
|
|
|
399
|
|
/**
|
400
|
|
* add a depth selector entry on the selector list
|
401
|
|
*/
|
402
|
0
|
public void addDepth(DepthSelector selector) {
|
403
|
0
|
fileset.addDepth(selector);
|
404
|
|
}
|
405
|
|
|
406
|
|
/**
|
407
|
|
* add a depends selector entry on the selector list
|
408
|
|
*/
|
409
|
0
|
public void addDepend(DependSelector selector) {
|
410
|
0
|
fileset.addDepend(selector);
|
411
|
|
}
|
412
|
|
|
413
|
|
/**
|
414
|
|
* Accessor for the implict fileset.
|
415
|
|
*
|
416
|
|
* @since Ant 1.5.2
|
417
|
|
*/
|
418
|
55
|
protected final FileSet getImplicitFileSet() {
|
419
|
55
|
return fileset;
|
420
|
|
}
|
421
|
|
}
|
422
|
|
|