source: release-kits/lirk3/resources/gs3-release-maker/ant/docs/manual/CoreTypes/selectors.html@ 14982

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

initial import of LiRK3

File size: 46.2 KB
Line 
1<html>
2 <head>
3 <meta http-equiv="Content-Language" content="en-us">
4 <title>Selectors in Ant</title>
5<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
6 </head>
7
8 <body>
9 <h2>Selectors</h2>
10
11 <p>Selectors are a mechanism whereby the files that make up a fileset&lt;depend&gt;<code>
12 can be selected based on criteria other than filename as provided
13 by the <code>&lt;include&gt;</code> and <code>&lt;exclude&gt;</code>
14 tags.</p>
15
16 <h3>How to use a Selector</h3>
17
18 <p>A selector is an element of FileSet, and appears within it. It can
19 also be defined outside of any target by using the <code>&lt;selector&gt;</code> tag
20 and then using it as a reference.
21 </p>
22
23 <p>Different selectors have different attributes. Some selectors can
24 contain other selectors, and these are called
25 <a href="#selectcontainers"><code>Selector Containers</code></a>.
26 There is also a category of selectors that allow
27 user-defined extensions, called
28 <a href="#customselect"><code>Custom Selectors</code></a>.
29 The ones built in to Ant are called
30 <a href="#coreselect"><code>Core Selectors</code></a>.
31 </p>
32
33 <a name="coreselect"></a>
34 <h3>Core Selectors</h3>
35
36 <p>Core selectors are the ones that come standard
37 with Ant. They can be used within a fileset and can be contained
38 within Selector Containers.</p>
39
40 <p>The core selectors are:</p>
41
42 <ul>
43 <li><a href="#containsselect"><code>&lt;contains&gt;</code></a> - Select
44 files that contain a particular text string</li>
45 <li><a href="#dateselect"><code>&lt;date&gt;</code></a> - Select files
46 that have been modified either before or after a particular date
47 and time</li>
48 <li><a href="#dependselect"><code>&lt;depend&gt;</code></a> - Select files
49 that have been modified more recently than equivalent files
50 elsewhere</li>
51 <li><a href="#depthselect"><code>&lt;depth&gt;</code></a> - Select files
52 that appear so many directories down in a directory tree</li>
53 <li><a href="#differentselect"><code>&lt;different&gt;</code></a> - Select files
54 that are different from those elsewhere</li>
55 <li><a href="#filenameselect"><code>&lt;filename&gt;</code></a> - Select
56 files whose name matches a particular pattern. Equivalent to
57 the include and exclude elements of a patternset.</li>
58 <li><a href="#presentselect"><code>&lt;present&gt;</code></a> - Select
59 files that either do or do not exist in some other location</li>
60 <li><a href="#regexpselect"><code>&lt;containsregexp&gt;</code></a> - Select
61 files that match a regular expression</li>
62 <li><a href="#sizeselect"><code>&lt;size&gt;</code></a> - Select files
63 that are larger or smaller than a particular number of bytes.</li>
64 <li><a href="#typeselect"><code>&lt;type&gt;</code></a> - Select files
65 that are either regular files or directories.</li>
66 <li><a href="#modified"><code>&lt;modified&gt;</code></a> - Select files if
67 the return value of the configured algorithm is different from that
68 stored in a cache.</li>
69 </ul>
70
71 <a name="containsselect"></a>
72 <h4>Contains Selector</h4>
73
74 <p>The <code>&lt;contains&gt;</code> tag in a FileSet limits
75 the files defined by that fileset to only those which contain the
76 string specified by the <code>text</code> attribute.
77 .</p>
78
79 <table border="1" cellpadding="2" cellspacing="0">
80 <tr>
81 <td valign="top"><b>Attribute</b></td>
82 <td valign="top"><b>Description</b></td>
83 <td align="center" valign="top"><b>Required</b></td>
84 </tr>
85 <tr>
86 <td valign="top">text</td>
87 <td valign="top">Specifies the text that every file must contain
88 </td>
89 <td valign="top" align="center">Yes</td>
90 </tr>
91 <tr>
92 <td valign="top">casesensitive</td>
93 <td valign="top">Whether to pay attention to case when looking
94 for the string in the <code>text</code> attribute. Default is
95 true.
96 </td>
97 <td valign="top" align="center">No</td>
98 </tr>
99 <tr>
100 <td valign="top">ignorewhitespace</td>
101 <td valign="top">Whether to eliminate whitespace before checking
102 for the string in the <code>text</code> attribute. Default is
103 false.
104 </td>
105 <td valign="top" align="center">No</td>
106 </tr>
107 </table>
108
109 <p>Here is an example of how to use the Contains Selector:</p>
110
111 <blockquote><pre>
112&lt;fileset dir=&quot;${doc.path}&quot; includes=&quot;**/*.html&quot;&gt;
113 &lt;contains text=&quot;script&quot; casesensitive=&quot;no&quot;/&gt;
114&lt;/fileset&gt;
115</pre></blockquote>
116
117 <p>Selects all the HTML files that contain the string
118 <code>script</code>.</p>
119
120
121 <a name="dateselect"></a>
122 <h4>Date Selector</h4>
123
124 <p>The <code>&lt;date&gt;</code> tag in a FileSet will put
125 a limit on the files specified by the include tag, so that tags
126 whose last modified date does not meet the date limits specified
127 by the selector will not end up being selected.</p>
128
129 <table border="1" cellpadding="2" cellspacing="0">
130 <tr>
131 <td valign="top"><b>Attribute</b></td>
132 <td valign="top"><b>Description</b></td>
133 <td align="center" valign="top"><b>Required</b></td>
134 </tr>
135 <tr>
136 <td valign="top">datetime</td>
137 <td valign="top">Specifies the date and time to test for.
138 Should be in the format MM/DD/YYYY HH:MM AM_or_PM, or
139 an alternative pattern specified via the <i>pattern</i>
140 attribute.
141 </td>
142 <td valign="top" align="center" rowspan="2">At least one of the two.</td>
143 </tr>
144 <tr>
145 <td valign="top">millis</td>
146 <td valign="top">The number of milliseconds since 1970 that should
147 be tested for. It is usually much easier to use the datetime
148 attribute.
149 </td>
150 </tr>
151 <tr>
152 <td valign="top">when</td>
153 <td valign="top">Indicates how to interpret the date, whether
154 the files to be selected are those whose last modified times should
155 be before, after, or equal to the specified value. Acceptable
156 values for this attribute are:
157 <ul>
158 <li>before - select files whose last modified date is before the indicated date
159 <li>after - select files whose last modified date is after the indicated date
160 <li>equal - select files whose last modified date is this exact date
161 </ul>
162 The default is equal.
163 <td valign="top" align="center">No</td>
164 </tr>
165 <tr>
166 <td valign="top">granularity</td>
167 <td valign="top">The number of milliseconds leeway to use when
168 comparing file modification times. This is needed because not every
169 file system supports tracking the last modified time to the
170 millisecond level. Default is 0 milliseconds, or 2 seconds on DOS systems.
171 </td>
172 <td valign="top" align="center">No</td>
173 </tr>
174 <tr>
175 <td valign="top">pattern</td>
176 <td valign="top">The <CODE>SimpleDateFormat</CODE>-compatible pattern
177 to use when interpreting the <i>datetime</i> attribute.
178 <i>Since Ant 1.6.2</i>
179 </td>
180 <td valign="top" align="center">No</td>
181 </tr>
182 <tr>
183 <td valign="top">checkdirs</td>
184 <td valign="top">
185 Indicates whether or not to check dates on directories.
186 </td>
187 <td valign="top" align="center">No, defaults to <i>false</i></td>
188 </tr>
189 </table>
190
191 <p>Here is an example of how to use the Date Selector:</p>
192
193 <blockquote><pre>
194&lt;fileset dir=&quot;${jar.path}&quot; includes=&quot;**/*.jar&quot;&gt;
195 &lt;date datetime=&quot;01/01/2001 12:00 AM&quot; when=&quot;before&quot;/&gt;
196&lt;/fileset&gt;
197</pre></blockquote>
198
199 <p>Selects all JAR files which were last modified before midnight
200 January 1, 2001.</p>
201
202
203 <a name="dependselect"></a>
204 <h4>Depend Selector</h4>
205
206 <p>The <code>&lt;depend&gt;</code> tag selects files
207 whose last modified date is later than another, equivalent file in
208 another location.</p>
209
210 <p>The <code>&lt;depend&gt;</code> tag supports the use of a
211 contained <a href="mapper.html"><code>&lt;mapper&gt;</code></a> element
212 to define the location of the file to be compared against. If no
213 <code>&lt;mapper&gt;</code> element is specified, the
214 <code>identity</code> type mapper is used.</p>
215
216 <p>The <code>&lt;depend&gt;</code> selector is case-sensitive.</p>
217
218 <table border="1" cellpadding="2" cellspacing="0">
219 <tr>
220 <td valign="top"><b>Attribute</b></td>
221 <td valign="top"><b>Description</b></td>
222 <td align="center" valign="top"><b>Required</b></td>
223 </tr>
224 <tr>
225 <td valign="top">targetdir</td>
226 <td valign="top">The base directory to look for the files to compare
227 against. The precise location depends on a combination of this
228 attribute and the <code>&lt;mapper&gt;</code> element, if any.
229 </td>
230 <td valign="top" align="center">Yes</td>
231 </tr>
232 <tr>
233 <td valign="top">granularity</td>
234 <td valign="top">The number of milliseconds leeway to give before
235 deciding a file is out of date. This is needed because not every
236 file system supports tracking the last modified time to the
237 millisecond level. Default is 0 milliseconds, or 2 seconds on DOS systems.
238 </td>
239 <td valign="top" align="center">No</td>
240 </tr>
241 </table>
242
243 <p>Here is an example of how to use the Depend Selector:</p>
244
245 <blockquote><pre>
246&lt;fileset dir=&quot;${ant.1.5}/src/main&quot; includes=&quot;**/*.java&quot;&gt;
247 &lt;depend targetdir=&quot;${ant.1.4.1}/src/main&quot;/&gt;
248&lt;/fileset&gt;
249</pre></blockquote>
250
251 <p>Selects all the Java source files which were modified in the
252 1.5 release.
253 </p>
254
255
256 <a name="depthselect"></a>
257 <h4>Depth Selector</h4>
258
259 <p>The <code>&lt;depth&gt;</code> tag selects files based on
260 how many directy levels deep they are in relation to the base
261 directory of the fileset.
262 </p>
263
264 <table border="1" cellpadding="2" cellspacing="0">
265 <tr>
266 <td valign="top"><b>Attribute</b></td>
267 <td valign="top"><b>Description</b></td>
268 <td align="center" valign="top"><b>Required</b></td>
269 </tr>
270 <tr>
271 <td valign="top">min</td>
272 <td valign="top">The minimum number of directory levels below
273 the base directory that a file must be in order to be selected.
274 Default is no limit.
275 </td>
276 <td valign="top" align="center" rowspan="2">At least one of the two.</td>
277 </tr>
278 <tr>
279 <td valign="top">max</td>
280 <td valign="top">The maximum number of directory levels below
281 the base directory that a file can be and still be selected.
282 Default is no limit.
283 </td>
284 </tr>
285 </table>
286
287 <p>Here is an example of how to use the Depth Selector:</p>
288
289 <blockquote><pre>
290&lt;fileset dir=&quot;${doc.path}&quot; includes=&quot;**/*&quot;&gt;
291 &lt;depth max=&quot;1&quot;/&gt;
292&lt;/fileset&gt;
293</pre></blockquote>
294
295 <p>Selects all files in the base directory and one directory below
296 that.</p>
297
298 <a name="differentselect">
299 <h4>Different Selector</h4>
300
301 <p>The <code>&lt;different&gt;</code> tag selects files
302 who are deemed to be 'different' from another, equivalent file in
303 another location. The rules for determining difference between two
304 files are as follows:
305 <ol>
306 <li> If there is no 'other' file, it's different.
307 <li> Files with different lengths are different.
308 <li> If <tt>ignoreFileTimes</tt> is turned off, then differing file
309 timestamps will cause files to be regarded as different.
310 <li> Unless<tt>ignoreContents</tt> is set to true, a byte-for-byte check is run
311 against the two files
312 </ol>
313
314 This is a useful selector to work with programs and tasks that don't handle
315 dependency checking properly; Even if a predecessor task always creates its
316 output files, followup tasks can be driven off copies made with a different selector,
317 so their dependencies are driven on the absolute state of the files, not just
318 a timestamp. For example: anything fetched from a web site, or the output of
319 some program. To reduce the amount of checking, when using this task inside
320 a <code>&lt;copy&gt;</code> task, set the <tt>preservelastmodified</tt> to propagate the timestamp
321 from source file to destintaion file.
322
323
324 <p>
325
326 The <code>&lt;different&gt;</code> tag supports the use of a
327 contained <a href="mapper.html"><code>&lt;mapper&gt;</code></a> element
328 to define the location of the file to be compared against. If no
329 <code>&lt;mapper&gt;</code> element is specified, the
330 <code>identity</code> type mapper is used.</p>
331
332 <table border="1" cellpadding="2" cellspacing="0">
333 <tr>
334 <td valign="top"><b>Attribute</b></td>
335 <td valign="top"><b>Description</b></td>
336 <td align="center" valign="top"><b>Required</b></td>
337 </tr>
338 <tr>
339 <td valign="top">targetdir</td>
340 <td valign="top">The base directory to look for the files to compare
341 against. The precise location depends on a combination of this
342 attribute and the <code>&lt;mapper&gt;</code> element, if any.
343 </td>
344 <td valign="top" align="center">Yes</td>
345 </tr>
346 <tr>
347 <td valign="top">ignoreFileTimes</td>
348 <td valign="top">Whether to use file times in the comparison or not.
349 Default is true (time differences are ignored).
350 </td>
351 <td valign="top" align="center">No</td>
352 </tr>
353 <tr>
354 <td valign="top">ignoreContents</td>
355 <td valign="top">Whether to do a byte per byte compare.
356 Default is false (contents are compared).
357 Since ant 1.6.3
358 </td>
359 <td valign="top" align="center">No</td>
360 </tr>
361 <tr>
362 <td valign="top">granularity</td>
363 <td valign="top">The number of milliseconds leeway to give before
364 deciding a file is out of date. This is needed because not every
365 file system supports tracking the last modified time to the
366 millisecond level. Default is 0 milliseconds, or 2 seconds on DOS systems.
367 </td>
368 <td valign="top" align="center">No</td>
369 </tr>
370 </table>
371
372 <p>Here is an example of how to use the Different Selector:</p>
373
374 <blockquote><pre>
375&lt;fileset dir=&quot;${ant.1.5}/src/main&quot; includes=&quot;**/*.java&quot;&gt;
376 &lt;different targetdir=&quot;${ant.1.4.1}/src/main&quot;
377 ignoreFileTimes="true"/&gt;
378&lt;/fileset&gt;
379</pre></blockquote>
380
381 <p>Compares all the Java source files between the 1.4.1 and the 1.5 release
382 and selects those who are different, disregarding file times.
383 </p>
384
385 <a name="filenameselect"></a>
386 <h4>Filename Selector</h4>
387
388 <p>The <code>&lt;filename&gt;</code> tag acts like the
389 <code>&lt;include&gt;</code> and <code>&lt;exclude&gt;</code>
390 tags within a fileset. By using a selector instead, however,
391 one can combine it with all the other selectors using whatever
392 <a href="#selectcontainers">selector container</a> is desired.
393 </p>
394
395 <p>The <code>&lt;filename&gt;</code> selector is
396 case-sensitive.</p>
397
398 <table border="1" cellpadding="2" cellspacing="0">
399 <tr>
400 <td valign="top"><b>Attribute</b></td>
401 <td valign="top"><b>Description</b></td>
402 <td align="center" valign="top"><b>Required</b></td>
403 </tr>
404 <tr>
405 <td valign="top">name</td>
406 <td valign="top">The name of files to select. The name parameter
407 can contain the standard Ant wildcard characters.
408 </td>
409 <td valign="top" align="center">Yes</td>
410 </tr>
411 <tr>
412 <td valign="top">casesensitive</td>
413 <td valign="top">Whether to pay attention to case when looking
414 at file names. Default is "true".
415 </td>
416 <td valign="top" align="center">No</td>
417 </tr>
418 <tr>
419 <td valign="top">negate</td>
420 <td valign="top">Whether to reverse the effects of this filename
421 selection, therefore emulating an exclude rather than include
422 tag. Default is "false".
423 </td>
424 <td valign="top" align="center">No</td>
425 </tr>
426 </table>
427
428 <p>Here is an example of how to use the Filename Selector:</p>
429
430 <blockquote><pre>
431&lt;fileset dir=&quot;${doc.path}&quot; includes=&quot;**/*&quot;&gt;
432 &lt;filename name=&quot;**/*.css&quot;/&gt;
433&lt;/fileset&gt;
434</pre></blockquote>
435
436 <p>Selects all the cascading style sheet files.</p>
437
438
439 <a name="presentselect"></a>
440 <h4>Present Selector</h4>
441
442 <p>The <code>&lt;present&gt;</code> tag selects files
443 that have an equivalent file in another directory tree.</p>
444
445 <p>The <code>&lt;present&gt;</code> tag supports the use of a
446 contained <a href="mapper.html"><code>&lt;mapper&gt;</code></a> element
447 to define the location of the file to be tested against. If no
448 <code>&lt;mapper&gt;</code> element is specified, the
449 <code>identity</code> type mapper is used.</p>
450
451 <p>The <code>&lt;present&gt;</code> selector is case-sensitive.</p>
452
453 <table border="1" cellpadding="2" cellspacing="0">
454 <tr>
455 <td valign="top"><b>Attribute</b></td>
456 <td valign="top"><b>Description</b></td>
457 <td align="center" valign="top"><b>Required</b></td>
458 </tr>
459 <tr>
460 <td valign="top">targetdir</td>
461 <td valign="top">The base directory to look for the files to compare
462 against. The precise location depends on a combination of this
463 attribute and the <code>&lt;mapper&gt;</code> element, if any.
464 </td>
465 <td valign="top" align="center">Yes</td>
466 </tr>
467 <tr>
468 <td valign="top">present</td>
469 <td valign="top">Whether we are requiring that a file is present in
470 the src directory tree only, or in both the src and the target
471 directory tree. Valid values are:
472 <ul>
473 <li>srconly - select files only if they are in the src
474 directory tree but not in the target directory tree
475 <li>both - select files only if they are present both in the
476 src and target directory trees
477 </ul>
478 Default is both. Setting this attribute to &quot;srconly&quot;
479 is equivalent to wrapping the selector in the <code>&lt;not&gt;</code>
480 selector container.
481 </td>
482 <td valign="top" align="center">No</td>
483 </tr>
484 </table>
485
486 <p>Here is an example of how to use the Present Selector:</p>
487
488 <blockquote><pre>
489&lt;fileset dir=&quot;${ant.1.5}/src/main&quot; includes=&quot;**/*.java&quot;&gt;
490 &lt;present present=&quot;srconly&quot; targetdir=&quot;${ant.1.4.1}/src/main&quot;/&gt;
491&lt;/fileset&gt;
492</pre></blockquote>
493
494 <p>Selects all the Java source files which are new in the
495 1.5 release.
496 </p>
497
498 <a name="regexpselect"></a>
499 <h4>Regular Expression Selector</h4>
500
501 <p>The <code>&lt;containsregexp&gt;</code> tag in a FileSet limits
502 the files defined by that fileset to only those which contain a
503 match to the regular expression specified by the <code>expression</code> attribute.
504 </p>
505
506 <table border="1" cellpadding="2" cellspacing="0">
507 <tr>
508 <td valign="top"><b>Attribute</b></td>
509 <td valign="top"><b>Description</b></td>
510 <td align="center" valign="top"><b>Required</b></td>
511 </tr>
512 <tr>
513 <td valign="top">expression</td>
514 <td valign="top">Specifies the regular expression that must
515 match true in every file</td>
516 <td valign="top" align="center">Yes</td>
517 </tr>
518 </table>
519
520 <p>Here is an example of how to use the regular expression Selector:</p>
521
522 <blockquote><pre>
523&lt;fileset dir=&quot;${doc.path}&quot; includes=&quot;*.txt&quot;&gt;
524 &lt;containsregexp expression=&quot;[4-6]\.[0-9]&quot;/&gt;
525&lt;/fileset&gt;
526</pre></blockquote>
527
528 <p>Selects all the text files that match the regular expression
529 (have a 4,5 or 6 followed by a period and a number from 0 to 9).
530
531
532 <a name="sizeselect"></a>
533 <h4>Size Selector</h4>
534
535 <p>The <code>&lt;size&gt;</code> tag in a FileSet will put
536 a limit on the files specified by the include tag, so that tags
537 which do not meet the size limits specified by the selector will not
538 end up being selected.</p>
539
540 <table border="1" cellpadding="2" cellspacing="0">
541 <tr>
542 <td valign="top"><b>Attribute</b></td>
543 <td valign="top"><b>Description</b></td>
544 <td align="center" valign="top"><b>Required</b></td>
545 </tr>
546 <tr>
547 <td valign="top">value</td>
548 <td valign="top">The size of the file which should be tested for.
549 </td>
550 <td valign="top" align="center">Yes</td>
551 </tr>
552 <tr>
553 <td valign="top">units</td>
554 <td valign="top">The units that the <code>value</code> attribute
555 is expressed in. When using the standard single letter SI
556 designations, such as &quot;k&quot;,&quot;M&quot;, or
557 &quot;G&quot;, multiples of 1000 are used. If you want to use
558 power of 2 units, use the IEC standard: &quot;Ki&quot; for 1024,
559 &quot;Mi&quot; for 1048576, and so on. The default is no units,
560 which means the <code>value</code> attribute expresses the exact
561 number of bytes.
562 </td>
563 <td valign="top" align="center">No</td>
564 </tr>
565 <tr>
566 <td valign="top">when</td>
567 <td valign="top">Indicates how to interpret the size, whether
568 the files to be selected should be larger, smaller, or equal to
569 that value. Acceptable values for this attribute are:
570 <ul>
571 <li>less - select files less than the indicated size
572 <li>more - select files greater than the indicated size
573 <li>equal - select files this exact size
574 </ul>
575 The default is less.
576 <td valign="top" align="center">No</td>
577 </tr>
578 </table>
579
580 <p>Here is an example of how to use the Size Selector:</p>
581
582 <blockquote><pre>
583&lt;fileset dir=&quot;${jar.path}&quot;&gt;
584 &lt;patternset&gt;
585 &lt;include name=&quot;**/*.jar&quot;/&gt;
586 &lt;/patternset&gt;
587 &lt;size value=&quot;4&quot; units=&quot;Ki&quot; when=&quot;more&quot;/&gt;
588&lt;/fileset&gt;
589</pre></blockquote>
590
591 <p>Selects all JAR files that are larger than 4096 bytes.</p>
592
593 <a name="typeselect"></a>
594 <h4>Type Selector</h4>
595
596 <p>The <code>&lt;type&gt;</code> tag selects files of a certain type:
597 directory or regular.</p>
598
599 <table border="1" cellpadding="2" cellspacing="0">
600 <tr>
601 <td valign="top"><b>Attribute</b></td>
602 <td valign="top"><b>Description</b></td>
603 <td align="center" valign="top"><b>Required</b></td>
604 </tr>
605 <tr>
606 <td valign="top">type</td>
607 <td valign="top">The type of file which should be tested for.
608 Acceptable values are:
609 <ul>
610 <li>file - regular files</li>
611 <li>dir - directories</li>
612 </ul>
613 </td>
614 <td valign="top" align="center">Yes</td>
615 </tr>
616 </table>
617
618 <p>Here is an example of how to use the Type Selector to select only
619 directories in <code>${src}</code></p>
620
621 <blockquote><pre>
622&lt;fileset dir=&quot;${src}&quot;&gt;
623 &lt;type type="dir"/&gt;
624&lt;/fileset&gt;
625</pre></blockquote>
626
627 <p>The Type Selector is often used in conjunction with other selectors.
628 For example, to select files that also exist in a <code>template</code>
629 directory, but avoid selecting empty directories, use:
630
631<blockquote><pre>
632&lt;fileset dir="${src}"&gt;
633 &lt;and&gt;
634 &lt;present targetdir="template"/&gt;
635 &lt;type type="file"/&gt;
636 &lt;/and&gt;
637&lt;/fileset&gt;
638</pre></blockquote>
639
640
641 <a name="modified"></a>
642 <h4>Modified Selector</h4>
643 <p>The <code>&lt;modified&gt;</code> selector computes a value for a file, compares that
644 to the value stored in a cache and select the file, if these two values
645 differ.</p>
646 <p>Because this selector is highly configurable the order in which the selection is done
647 is: <ol>
648 <li> get the absolute path for the file </li>
649 <li> get the cached value from the configured cache (absolute path as key) </li>
650 <li> get the new value from the configured algorithm </li>
651 <li> compare these two values with the configured comparator </li>
652 <li> update the cache if needed and requested </li>
653 <li> do the selection according to the comparison result </li>
654 </ol>
655 The comparison, computing of the hashvalue and the store is done by implementation
656 of special interfaces. Therefore they may provide additional parameters.</p>
657
658 <table border="1" cellpadding="2" cellspacing="0">
659 <tr>
660 <td valign="top"><b>Attribute</b></td>
661 <td valign="top"><b>Description</b></td>
662 <td align="center" valign="top"><b>Required</b></td>
663 </tr>
664 <tr>
665 <td valign="top"> algorithm </td>
666 <td valign="top"> The type of algorithm should be used.
667 Acceptable values are (further information see later):
668 <ul>
669 <li> hashvalue - HashvalueAlgorithm </li>
670 <li> digest - DigestAlgorithm </li>
671 </ul>
672 </td>
673 <td valign="top" align="center"> No, defaults to <i>digest</i> </td>
674 </tr>
675 <tr>
676 <td valign="top"> cache </td>
677 <td valign="top"> The type of cache should be used.
678 Acceptable values are (further information see later):
679 <ul>
680 <li> propertyfile - PropertyfileCache </li>
681 </ul>
682 </td>
683 <td valign="top" align="center"> No, defaults to <i>propertyfile</i> </td>
684 </tr>
685 <tr>
686 <td valign="top"> comparator </td>
687 <td valign="top"> The type of comparator should be used.
688 Acceptable values are (further information see later):
689 <ul>
690 <li> equal - EqualComparator </li>
691 <li> rule - java.text.RuleBasedCollator </li>
692 </ul>
693 </td>
694 <td valign="top" align="center"> No, defaults to <i>equal</i> </td>
695 </tr>
696 <tr>
697 <td valign="top"> update </td>
698 <td valign="top"> Should the cache be updated when values differ? (boolean) </td>
699 <td valign="top" align="center"> No, defaults to <i>true</i> </td>
700 </tr>
701 <tr>
702 <td valign="top"> seldirs </td>
703 <td valign="top"> Should directories be selected? (boolean) </td>
704 <td valign="top" align="center"> No, defaults to <i>true</i> </td>
705 </tr>
706 </table>
707
708 <p>These attributes can be set with nested <code>&lt;param/&gt;</code> tags. With <code>&lt;param/&gt;</code>
709 tags you can set other values too - as long as they are named according to
710 the following rules: <ul>
711 <li> <b> algorithm </b>: same as attribute algorithm </li>
712 <li> <b> cache </b>: same as attribute cache </li>
713 <li> <b> comparator </b>: same as attribute comparator </li>
714 <li> <b> update </b>: same as attribute update </li>
715 <li> <b> seldirs </b>: same as attribute seldirs </li>
716 <li> <b> algorithm.* </b>: Value is transfered to the algorithm via its
717 <i>set</i>XX-methods </li>
718 <li> <b> cache.* </b>: Value is transfered to the cache via its
719 <i>set</i>XX-methods </li>
720 <li> <b> comparator.* </b>: Value is transfered to the comparator via its
721 <i>set</i>XX-methods </li>
722 </ul></p>
723
724 <table border="1" cellpadding="2" cellspacing="0">
725 <tr><td colspan="2"><font size="+1"><b> Algorithm's </b></font></td></tr>
726 <tr>
727 <td valign="top"><b>Name</b></td>
728 <td valign="top"><b>Description</b></td>
729 </tr>
730 <tr>
731 <td valign="top"> hashvalue </td>
732 <td valign="top"> Reads the content of a file into a java.lang.String
733 and use thats hashValue(). No additional configuration required.
734 </td>
735 </tr>
736 <tr>
737 <td valign="top"> digest </td>
738 <td valign="top"> Uses java.security.MessageDigest. This Algorithm supports
739 the following attributes:
740 <ul>
741 <li><i>algorithm.algorithm</i> (optional): Name of the Digest algorithm
742 (e.g. 'MD5' or 'SHA', default = <i>MD5</i>) </li>
743 <li><i>algorithm.provider</i> (optional): Name of the Digest provider
744 (default = <i>null</i>) </li>
745 </ul>
746 </td>
747 </tr>
748 <tr><td colspan="2"><font size="+1"><b> Cache's </b></font></td></tr>
749 <tr>
750 <td valign="top"> propertyfile </td>
751 <td valign="top"> Use the java.util.Properties class and its possibility
752 to load and store to file.
753 This Cache implementation supports the following attributes:
754 <ul>
755 <li><i>cache.cachefile</i> (optional): Name of the properties-file
756 (default = <i>cache.properties</i>) </li>
757 </ul>
758 </td>
759 </tr>
760 <tr><td colspan="2"><font size="+1"><b> Comparator's </b></font></td></tr>
761 <tr>
762 <td valign="top"> equal </td>
763 <td valign="top"> Very simple object comparison. </td>
764 </tr>
765 <tr>
766 <td valign="top"> rule </td>
767 <td valign="top"> Uses <i>java.text.RuleBasedCollator</i> for Object
768 comparison.
769 </td>
770 </tr>
771 </table>
772
773 <p>Here are some examples of how to use the Modified Selector:</p>
774
775 <blockquote><pre>
776 &lt;copy todir="dest"&gt;
777 &lt;fileset dir="src"&gt;
778 &lt;modified/&gt;
779 &lt;/fileset&gt;
780 &lt;/copy&gt;
781 </pre></blockquote>
782 <p>This will copy all files from <i>src</i> to <i>dest</i> which content has changed.
783 Using an updating PropertyfileCache with cache.properties and
784 MD5-DigestAlgorithm.</p>
785
786 <blockquote><pre>
787 &lt;copy todir="dest"&gt;
788 &lt;fileset dir="src"&gt;
789 &lt;modified update="true"
790 seldirs="true"
791 cache="propertyfile"
792 algorithm="digest"
793 comparator="equal"&gt;
794 &lt;param name="cache.cachefile" value="cache.properties"/&gt;
795 &lt;param name="algorithm.algorithm" value="MD5"/&gt;
796 &lt;/modified&gt;
797 &lt;/fileset&gt;
798 &lt;/copy&gt;
799 </pre></blockquote>
800 <p>This is the same example rewritten as CoreSelector with setting the all the values
801 (same as defaults are).</p>
802
803 <blockquote><pre>
804 &lt;copy todir="dest"&gt;
805 &lt;fileset dir="src"&gt;
806 &lt;custom class="org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector"&gt;
807 &lt;param name="update" value="true"/&gt;
808 &lt;param name="seldirs" value="true"/&gt;
809 &lt;param name="cache" value="propertyfile"/&gt;
810 &lt;param name="algorithm" value="digest"/&gt;
811 &lt;param name="comparator" value="equal"/&gt;
812 &lt;param name="cache.cachefile" value="cache.properties"/&gt;
813 &lt;param name="algorithm.algorithm" value="MD5"/&gt;
814 &lt;/custom&gt;
815 &lt;/fileset&gt;
816 &lt;/copy&gt;
817 </pre></blockquote>
818 <p>And this is the same rewritten as CustomSelector.</p>
819
820 <blockquote><pre>
821 &lt;target name="generate-and-upload-site"&gt;
822 &lt;echo&gt; generate the site using forrest &lt;/echo&gt;
823 &lt;antcall target="site"/&gt;
824
825 &lt;echo&gt; upload the changed file &lt;/echo&gt;
826 &lt;ftp server="${ftp.server}" userid="${ftp.user}" password="${ftp.pwd}"&gt;
827 &lt;fileset dir="htdocs/manual"&gt;
828 &lt;modified/&gt;
829 &lt;/fileset&gt;
830 &lt;/ftp&gt;
831 &lt;/target&gt;
832 </pre></blockquote>
833 <p>A useful scenario for this selector inside a build environment
834 for homepage generation (e.g. with <a href="http://xml.apache.org/forrest/">
835 Apache Forrest</a>). Here all <b>changed</b> files are uploaded to the server. The
836 CacheSelector saves therefore much upload time.</p>
837
838
839 <a name="selectcontainers"></a>
840 <h3>Selector Containers</h3>
841
842 <p>To create more complex selections, a variety of selectors that
843 contain other selectors are available for your use. They combine the
844 selections of their child selectors in various ways.</p>
845
846 <p>The selector containers are:</p>
847
848 <ul>
849 <li><a href="#andselect"><code>&lt;and&gt;</code></a> - select a file only if all
850 the contained selectors select it.
851 <li><a href="#majorityselect"><code>&lt;majority&gt;</code></a> - select a file
852 if a majority of its selectors select it.
853 <li><a href="#noneselect"><code>&lt;none&gt;</code></a> - select a file only if
854 none of the contained selectors select it.
855 <li><a href="#notselect"><code>&lt;not&gt;</code></a> - can contain only one
856 selector, and reverses what it selects and doesn't select.
857 <li><a href="#orselect"><code>&lt;or&gt;</code></a> - selects a file if any one
858 of the contained selectors selects it.
859 <li><a href="#selectorselect"><code>&lt;selector&gt;</code></a> - contains only one
860 selector and forwards all requests to it without alteration, provided
861 that any <code>&quot;if&quot;</code> or
862 <code>&quot;unless&quot;</code> conditions are met. This
863 is the selector to use if you want to define a reference. It is
864 usable as an element of <code>&lt;project&gt;</code>. It is also
865 the one to use if you want selection of files to be dependent on
866 Ant property settings.
867 </ul>
868
869 <p>All selector containers can contain any other selector, including
870 other containers, as an element. Using containers, the selector tags
871 can be arbitrarily deep. Here is a complete list of allowable
872 selector elements within a container:</P>
873
874 <ul>
875 <li><code>&lt;and&gt;</code></li>
876 <li><code>&lt;contains&gt;</code></li>
877 <li><code>&lt;custom&gt;</code></li>
878 <li><code>&lt;date&gt;</code></li>
879 <li><code>&lt;depend&gt;</code></li>
880 <li><code>&lt;depth&gt;</code></li>
881 <li><code>&lt;filename&gt;</code></li>
882 <li><code>&lt;majority&gt;</code></li>
883 <li><code>&lt;none&gt;</code></li>
884 <li><code>&lt;not&gt;</code></li>
885 <li><code>&lt;or&gt;</code></li>
886 <li><code>&lt;present&gt;</code></li>
887 <li><code>&lt;selector&gt;</code></li>
888 <li><code>&lt;size&gt;</code></li>
889 </ul>
890
891 <a name="andselect"></a>
892 <h4>And Selector</h4>
893
894 <p>The <code>&lt;and&gt;</code> tag selects files that are
895 selected by all of the elements it contains. It returns as
896 soon as it finds a selector that does not select the file,
897 so it is not guaranteed to check every selector.
898 </p>
899
900 <p>Here is an example of how to use the And Selector:</p>
901
902 <blockquote><pre>
903&lt;fileset dir=&quot;${dist}&quot; includes=&quot;**/*.jar&quot;&gt;
904 &lt;and&gt;
905 &lt;size value=&quot;4&quot; units=&quot;Ki&quot; when=&quot;more&quot;/&gt;
906 &lt;date datetime=&quot;01/01/2001 12:00 AM&quot; when=&quot;before&quot;/&gt;
907 &lt;/and&gt;
908&lt;/fileset&gt;
909</pre></blockquote>
910
911 <p>Selects all the JAR file larger than 4096 bytes which haven't been update
912 since the last millenium.
913 </p>
914
915
916 <a name="majorityselect"></a>
917 <h4>Majority Selector</h4>
918
919 <p>The <code>&lt;majority&gt;</code> tag selects files provided
920 that a majority of the contained elements also select it. Ties are
921 dealt with as specified by the <code>allowtie</code> attribute.
922 </p>
923
924 <table border="1" cellpadding="2" cellspacing="0">
925 <tr>
926 <td valign="top"><b>Attribute</b></td>
927 <td valign="top"><b>Description</b></td>
928 <td align="center" valign="top"><b>Required</b></td>
929 </tr>
930 <tr>
931 <td valign="top">allowtie</td>
932 <td valign="top">Whether files should be selected if there
933 are an even number of selectors selecting them as are
934 not selecting them. Default is true.
935 </td>
936 <td valign="top" align="center">No</td>
937 </tr>
938 </table>
939
940
941 <p>Here is an example of how to use the Majority Selector:</p>
942
943 <blockquote><pre>
944&lt;fileset dir=&quot;${docs}&quot; includes=&quot;**/*.html&quot;&gt;
945 &lt;majority&gt;
946 &lt;contains text=&quot;project&quot; casesensitive="false"/&gt;
947 &lt;contains text=&quot;taskdef&quot; casesensitive="false"/&gt;
948 &lt;contains text=&quot;IntrospectionHelper&quot; casesensitive="true"/&gt;
949 &lt;/majority&gt;
950&lt;/fileset&gt;
951</pre></blockquote>
952
953 <p>Selects all the HTML files which contain at least two of the three
954 phrases "project", "taskdef", and "IntrospectionHelper" (this last phrase must
955 match case exactly).
956 </p>
957
958
959 <a name="noneselect"></a>
960 <h4>None Selector</h4>
961
962 <p>The <code>&lt;none&gt;</code> tag selects files that are
963 not selected by any of the elements it contains. It returns as
964 soon as it finds a selector that selects the file,
965 so it is not guaranteed to check every selector.
966 </p>
967
968 <p>Here is an example of how to use the None Selector:</p>
969
970 <blockquote><pre>
971&lt;fileset dir=&quot;${src}&quot; includes=&quot;**/*.java&quot;&gt;
972 &lt;none&gt;
973 &lt;present targetdir=&quot;${dest}&quot;/&gt;
974 &lt;present targetdir=&quot;${dest}&quot;&gt;
975 &lt;mapper type=&quot;glob&quot; from=&quot;*.java&quot; to=&quot;*.class&quot;/&gt;
976 &lt;/present&gt;
977 &lt;/none&gt;
978&lt;/fileset&gt;
979</pre></blockquote>
980
981 <p>Selects only Java files which do not have equivalent java or
982 class files in the dest directory.
983 </p>
984
985
986 <a name="notselect"></a>
987 <h4>Not Selector</h4>
988
989 <p>The <code>&lt;not&gt;</code> tag reverses the meaning of the
990 single selector it contains.
991 </p>
992
993 <p>Here is an example of how to use the Not Selector:</p>
994
995 <blockquote><pre>
996&lt;fileset dir=&quot;${src}&quot; includes=&quot;**/*.java&quot;&gt;
997 &lt;not&gt;
998 &lt;contains text=&quot;test&quot;/&gt;
999 &lt;/not&gt;
1000&lt;/fileset&gt;
1001</pre></blockquote>
1002
1003 <p>Selects all the files in the src directory that do not contain the
1004 string "test".
1005 </p>
1006
1007
1008 <a name="orselect"></a>
1009 <h4>Or Selector</h4>
1010
1011 <p>The <code>&lt;or&gt;</code> tag selects files that are
1012 selected by any one of the elements it contains. It returns as
1013 soon as it finds a selector that selects the file,
1014 so it is not guaranteed to check every selector.
1015 </p>
1016
1017 <p>Here is an example of how to use the Or Selector:</p>
1018
1019 <blockquote><pre>
1020&lt;fileset dir=&quot;${basedir}&quot;&gt;
1021 &lt;or&gt;
1022 &lt;depth max=&quot;0&quot;/&gt;
1023 &lt;filename name="*.png"/&gt;
1024 &lt;filename name="*.gif"/&gt;
1025 &lt;filename name="*.jpg"/&gt;
1026 &lt;/or&gt;
1027&lt;/fileset&gt;
1028</pre></blockquote>
1029
1030 <p>Selects all the files in the top directory along with all the
1031 image files below it.
1032 </p>
1033
1034
1035 <a name="selectorselect"></a>
1036 <h4>Selector Reference</h4>
1037
1038 <p>The <code>&lt;selector&gt;</code> tag is used to create selectors
1039 that can be reused through references. It is the only selector which can
1040 be used outside of
1041 any target, as an element of the <code>&lt;project&gt;</code> tag. It
1042 can contain only one other selector, but of course that selector can
1043 be a container.
1044 </p>
1045
1046 <p>The <code>&lt;selector&gt;</code> tag can also be used to select
1047 files conditionally based on whether an Ant property exists or not.
1048 This functionality is realized using the <code>&quot;if&quot;</code> and
1049 <code>&quot;unless&quot;</code> attributes in exactly the same way they
1050 are used on targets or on the <code>&lt;include&gt;</code> and
1051 <code>&lt;exclude&gt;</code> tags within a
1052 <code>&lt;patternset&gt;</code>.</p>
1053
1054 <table border="1" cellpadding="2" cellspacing="0">
1055 <tr>
1056 <td valign="top"><b>Attribute</b></td>
1057 <td valign="top"><b>Description</b></td>
1058 <td align="center" valign="top"><b>Required</b></td>
1059 </tr>
1060 <tr>
1061 <td valign="top">if</td>
1062 <td valign="top">Allow files to be selected only if the named
1063 property is set.
1064 </td>
1065 <td valign="top" align="center">No</td>
1066 </tr>
1067 <tr>
1068 <td valign="top">unless</td>
1069 <td valign="top">Allow files to be selected only if the named
1070 property is <b>not</b> set.
1071 </td>
1072 <td valign="top" align="center">No</td>
1073 </tr>
1074 </table>
1075
1076 <p>Here is an example of how to use the Selector Reference:</p>
1077
1078 <blockquote><pre>
1079&lt;project default=&quot;all&quot; basedir=&quot;./ant&quot;&gt;
1080
1081 &lt;selector id=&quot;completed&quot;&gt;
1082 &lt;none&gt;
1083 &lt;depend targetdir=&quot;build/classes&quot;&gt;
1084 &lt;mapper type=&quot;glob&quot; from=&quot;*.java&quot; to=&quot;*.class&quot;/&gt;
1085 &lt;/depend&gt;
1086 &lt;depend targetdir=&quot;docs/manual/api&quot;&gt;
1087 &lt;mapper type=&quot;glob&quot; from=&quot;*.java&quot; to=&quot;*.html&quot;/&gt;
1088 &lt;/depend&gt;
1089 &lt;/none&gt;
1090 &lt;/selector&gt;
1091
1092 &lt;target&gt;
1093 &lt;zip&gt;
1094 &lt;fileset dir=&quot;src/main&quot; includes=&quot;**/*.java&quot;&gt;
1095 &lt;selector refid=&quot;completed&quot;/&gt;
1096 &lt;/fileset&gt;
1097 &lt;/zip&gt;
1098 &lt;/target&gt;
1099
1100&lt;/project&gt;
1101</pre></blockquote>
1102
1103 <p>Zips up all the Java files which have an up-to-date equivalent
1104 class file and javadoc file associated with them.
1105 </p>
1106
1107 <p>And an example of selecting files conditionally, based on whether
1108 properties are set:</p>
1109
1110 <blockquote><pre>
1111&lt;fileset dir=&quot;${working.copy}&quot;&gt;
1112 &lt;or&gt;
1113 &lt;selector if=&quot;include.tests&quot;&gt;
1114 &lt;filename name=&quot;**/*Test.class&quot;&gt;
1115 &lt;/selector&gt;
1116 &lt;selector if=&quot;include.source&quot;&gt;
1117 &lt;and&gt;
1118 &lt;filename name=&quot;**/*.java&quot;&gt;
1119 &lt;not&gt;
1120 &lt;selector unless=&quot;include.tests&quot;&gt;
1121 &lt;filename name=&quot;**/*Test.java&quot;&gt;
1122 &lt;/selector&gt;
1123 &lt;/not&gt;
1124 &lt;/and&gt;
1125 &lt;/selector&gt;
1126 &lt;/or&gt;
1127&lt;/fileset&gt;
1128</pre></blockquote>
1129
1130 <p>A fileset that conditionally contains Java source files and Test
1131 source and class files.</p>
1132
1133 <a name="customselect"></a>
1134 <h3>Custom Selectors</h3>
1135
1136 <p>You can write your own selectors and use them within the selector
1137 containers by specifying them within the <code>&lt;custom&gt;</code> tag.</p>
1138
1139 <p>First, you have to write your selector class in Java. The only
1140 requirement it must meet in order to be a selector is that it implements
1141 the <code>org.apache.tools.ant.types.selectors.FileSelector</code>
1142 interface, which contains a single method. See
1143 <a href="selectors-program.html">Programming Selectors in Ant</a> for
1144 more information.</p>
1145
1146 <p>Once that is written, you include it in your build file by using
1147 the <code>&lt;custom&gt;</code> tag.
1148 </p>
1149
1150 <table border="1" cellpadding="2" cellspacing="0">
1151 <tr>
1152 <td valign="top"><b>Attribute</b></td>
1153 <td valign="top"><b>Description</b></td>
1154 <td align="center" valign="top"><b>Required</b></td>
1155 </tr>
1156 <tr>
1157 <td valign="top">classname</td>
1158 <td valign="top">The name of your class that implements
1159 <code>org.apache.tools.ant.types.selectors.FileSelector</code>.
1160 </td>
1161 <td valign="top" align="center">Yes</td>
1162 </tr>
1163 <tr>
1164 <td valign="top">classpath</td>
1165 <td valign="top">The classpath to use in order to load the
1166 custom selector class. If neither this classpath nor the
1167 classpathref are specified, the class will be
1168 loaded from the classpath that Ant uses.
1169 </td>
1170 <td valign="top" align="center">No</td>
1171 </tr>
1172 <tr>
1173 <td valign="top">classpathref</td>
1174 <td valign="top">A reference to a classpath previously
1175 defined. If neither this reference nor the
1176 classpath above are specified, the class will be
1177 loaded from the classpath that Ant uses.
1178 </td>
1179 <td valign="top" align="center">No</td>
1180 </tr>
1181 </table>
1182
1183 <p>Here is how you use <code>&lt;custom&gt;</code> to
1184 use your class as a selector:
1185 </p>
1186
1187 <blockquote><pre>
1188&lt;fileset dir=&quot;${mydir}&quot; includes=&quot;**/*&quot;&gt;
1189 &lt;custom classname=&quot;com.mydomain.MySelector&quot;&gt;
1190 &lt;param name=&quot;myattribute&quot; value=&quot;myvalue&quot;/&gt;
1191 &lt;/custom&gt;
1192&lt;/fileset&gt;
1193</pre></blockquote>
1194
1195 <p>A number of core selectors can also be used as custom selectors
1196 by specifying their attributes using <code>&lt;param&gt;</code> elements. These
1197 are</p>
1198
1199 <ul>
1200 <li><a href="#containsselect">Contains Selector</a> with
1201 classname <code>org.apache.tools.ant.types.selectors.ContainsSelector</code>
1202 <li><a href="#dateselect">Date Selector</a> with
1203 classname <code>org.apache.tools.ant.types.selectors.DateSelector</code>
1204 <li><a href="#depthselect">Depth Selector</a> with
1205 classname <code>org.apache.tools.ant.types.selectors.DepthSelector</code>
1206 <li><a href="#filenameselect">Filename Selector</a> with
1207 classname <code>org.apache.tools.ant.types.selectors.FilenameSelector</code>
1208 <li><a href="#sizeselect">Size Selector</a> with
1209 classname <code>org.apache.tools.ant.types.selectors.SizeSelector</code>
1210 </ul>
1211
1212 <p>Here is the example from the Depth Selector section rewritten
1213 to use the selector through <code>&lt;custom&gt;</code>.</p>
1214
1215 <blockquote><pre>
1216&lt;fileset dir=&quot;${doc.path}&quot; includes=&quot;**/*&quot;&gt;
1217 &lt;custom classname=&quot;org.apache.tools.ant.types.selectors.DepthSelector&quot;&gt;
1218 &lt;param name=&quot;max&quot; value=&quot;1&quot;/&gt;
1219 &lt;/custom&gt;
1220&lt;/fileset&gt;
1221</pre></blockquote>
1222
1223 <p>Selects all files in the base directory and one directory below
1224 that.</p>
1225
1226 <p>For more details concerning writing your own selectors, consult
1227 <a href="selectors-program.html">Programming Selectors in Ant</a>.</p>
1228
1229 <hr>
1230 <p align="center">Copyright &copy; 2002-2004 The Apache Software
1231 Foundation. All rights Reserved.</p>
1232
1233 </body>
1234
1235</html>
Note: See TracBrowser for help on using the repository browser.