source: other-projects/trunk/realistic-books/packages/AntInstaller/web/manual1.6.2/manual/CoreTypes/selectors.html@ 19253

Last change on this file since 19253 was 19253, checked in by davidb, 15 years ago

Establishing a source code repository for Veronica's Realistic Book's software

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