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><include></code> and <code><exclude></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 <selector> 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"><contains></a> - Select
|
---|
44 | files that contain a particular text string</li>
|
---|
45 | <li><a href="#dateselect"><date></a> - Select files
|
---|
46 | that have been modified either before or after a particular date
|
---|
47 | and time</li>
|
---|
48 | <li><a href="#dependselect"><depend></a> - Select files
|
---|
49 | that have been modified more recently than equivalent files
|
---|
50 | elsewhere</li>
|
---|
51 | <li><a href="#depthselect"><depth></a> - Select files
|
---|
52 | that appear so many directories down in a directory tree</li>
|
---|
53 | <li><a href="#differentselect"><different></a> - Select files
|
---|
54 | that are different from those elsewhere</li>
|
---|
55 | <li><a href="#filenameselect"><filename></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"><present></a> - Select
|
---|
59 | files that either do or do not exist in some other location</li>
|
---|
60 | <li><a href="#regexpselect"><containsregexp></a> - Select
|
---|
61 | files that match a regular expression</li>
|
---|
62 | <li><a href="#sizeselect"><size></a> - Select files
|
---|
63 | that are larger or smaller than a particular number of bytes.</li>
|
---|
64 | <li><a href="#typeselect"><type></a> - Select files
|
---|
65 | that are either regular files or directories.</li>
|
---|
66 | <li><a href="#modified"><modified></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><contains></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 | <fileset dir="${doc.path}" includes="**/*.html">
|
---|
113 | <contains text="script" casesensitive="no"/>
|
---|
114 | </fileset>
|
---|
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><date></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 | <fileset dir="${jar.path}" includes="**/*.jar">
|
---|
188 | <date datetime="01/01/2001 12:00 AM" when="before"/>
|
---|
189 | </fileset>
|
---|
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><depend></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><depend></code> tag supports the use of a
|
---|
204 | contained <a href="mapper.html"><code><mapper></code></a> element
|
---|
205 | to define the location of the file to be compared against. If no
|
---|
206 | <code><mapper></code> element is specified, the
|
---|
207 | <code>identity</code> type mapper is used.</p>
|
---|
208 |
|
---|
209 | <p>The <code><depend></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><mapper></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 | <fileset dir="${ant.1.5}/src/main" includes="**/*.java">
|
---|
240 | <depend targetdir="${ant.1.4.1}/src/main"/>
|
---|
241 | </fileset>
|
---|
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><depth></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 | <fileset dir="${doc.path}" includes="**/*">
|
---|
284 | <depth max="1"/>
|
---|
285 | </fileset>
|
---|
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><different></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 <copy> 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><different></code> tag supports the use of a
|
---|
319 | contained <a href="mapper.html"><code><mapper></code></a> element
|
---|
320 | to define the location of the file to be compared against. If no
|
---|
321 | <code><mapper></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><mapper></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 | <fileset dir="${ant.1.5}/src/main" includes="**/*.java">
|
---|
360 | <different targetdir="${ant.1.4.1}/src/main"
|
---|
361 | ignoreFileTimes="true"/>
|
---|
362 | </fileset>
|
---|
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><filename></code> tag acts like the
|
---|
373 | <code><include></code> and <code><exclude></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><filename></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 | <fileset dir="${doc.path}" includes="**/*">
|
---|
416 | <filename name="**/*.css"/>
|
---|
417 | </fileset>
|
---|
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><present></code> tag selects files
|
---|
427 | that have an equivalent file in another directory tree.</p>
|
---|
428 |
|
---|
429 | <p>The <code><present></code> tag supports the use of a
|
---|
430 | contained <a href="mapper.html"><code><mapper></code></a> element
|
---|
431 | to define the location of the file to be tested against. If no
|
---|
432 | <code><mapper></code> element is specified, the
|
---|
433 | <code>identity</code> type mapper is used.</p>
|
---|
434 |
|
---|
435 | <p>The <code><present></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><mapper></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 "srconly"
|
---|
463 | is equivalent to wrapping the selector in the <not>
|
---|
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 | <fileset dir="${ant.1.5}/src/main" includes="**/*.java">
|
---|
474 | <present present="srconly" targetdir="${ant.1.4.1}/src/main"/>
|
---|
475 | </fileset>
|
---|
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><containsregexp></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 | <fileset dir="${doc.path}" includes="*.txt">
|
---|
508 | <containsregexp expression="[4-6]\.[0-9]"/>
|
---|
509 | </fileset>
|
---|
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><size></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 "k","M", or
|
---|
541 | "G", multiples of 1000 are used. If you want to use
|
---|
542 | power of 2 units, use the IEC standard: "Ki" for 1024,
|
---|
543 | "Mi" 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 | <fileset dir="${jar.path}">
|
---|
568 | <patternset>
|
---|
569 | <include name="**/*.jar"/>
|
---|
570 | </patternset>
|
---|
571 | <size value="4" units="Ki" when="more"/>
|
---|
572 | </fileset>
|
---|
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><type></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 | <fileset dir="${src}">
|
---|
607 | <type type="dir"/>
|
---|
608 | </fileset>
|
---|
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 | <fileset dir="${src}">
|
---|
617 | <and>
|
---|
618 | <present targetdir="template"/>
|
---|
619 | <type type="file"/>
|
---|
620 | </and>
|
---|
621 | </fileset>
|
---|
622 | </pre></blockquote>
|
---|
623 |
|
---|
624 |
|
---|
625 | <a name="modified"></a>
|
---|
626 | <h4>Modified Selector</h4>
|
---|
627 | <p>The <modified> 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 <param/> tags. With <param/>
|
---|
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 | <copy todir="dest">
|
---|
761 | <fileset dir="src">
|
---|
762 | <modified/>
|
---|
763 | </fileset>
|
---|
764 | </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 | <copy todir="dest">
|
---|
772 | <fileset dir="src">
|
---|
773 | <modified update="true"
|
---|
774 | seldirs="true"
|
---|
775 | cache="propertyfile"
|
---|
776 | algorithm="digest"
|
---|
777 | comparator="equal">
|
---|
778 | <param name="cache.cachefile" value="cache.properties"/>
|
---|
779 | <param name="algorithm.algorithm" value="MD5"/>
|
---|
780 | </modified>
|
---|
781 | </fileset>
|
---|
782 | </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 | <copy todir="dest">
|
---|
789 | <fileset dir="src">
|
---|
790 | <custom class="org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector">
|
---|
791 | <param name="update" value="true"/>
|
---|
792 | <param name="seldirs" value="true"/>
|
---|
793 | <param name="cache" value="propertyfile"/>
|
---|
794 | <param name="algorithm" value="digest"/>
|
---|
795 | <param name="comparator" value="equal"/>
|
---|
796 | <param name="cache.cachefile" value="cache.properties"/>
|
---|
797 | <param name="algorithm.algorithm" value="MD5"/>
|
---|
798 | </custom>
|
---|
799 | </fileset>
|
---|
800 | </copy>
|
---|
801 | </pre></blockquote>
|
---|
802 | <p>And this is the same rewritten as CustomSelector.</p>
|
---|
803 |
|
---|
804 | <blockquote><pre>
|
---|
805 | <target name="generate-and-upload-site">
|
---|
806 | <echo> generate the site using forrest </echo>
|
---|
807 | <antcall target="site"/>
|
---|
808 |
|
---|
809 | <echo> upload the changed file </echo>
|
---|
810 | <ftp server="${ftp.server}" userid="${ftp.user}" password="${ftp.pwd}">
|
---|
811 | <fileset dir="htdocs/manual">
|
---|
812 | <modified/>
|
---|
813 | </fileset>
|
---|
814 | </ftp>
|
---|
815 | </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"><and></a> - select a file only if all
|
---|
834 | the contained selectors select it.
|
---|
835 | <li><a href="#majorityselect"><majority></a> - select a file
|
---|
836 | if a majority of its selectors select it.
|
---|
837 | <li><a href="#noneselect"><none></a> - select a file only if
|
---|
838 | none of the contained selectors select it.
|
---|
839 | <li><a href="#notselect"><not></a> - can contain only one
|
---|
840 | selector, and reverses what it selects and doesn't select.
|
---|
841 | <li><a href="#orselect"><or></a> - selects a file if any one
|
---|
842 | of the contained selectors selects it.
|
---|
843 | <li><a href="#selectorselect"><selector></a> - contains only one
|
---|
844 | selector and forwards all requests to it without alteration, provided
|
---|
845 | that any <code>"if"</code> or
|
---|
846 | <code>"unless"</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><project></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><and>
|
---|
860 | <li><contains>
|
---|
861 | <li><custom>
|
---|
862 | <li><date>
|
---|
863 | <li><depend>
|
---|
864 | <li><depth>
|
---|
865 | <li><filename>
|
---|
866 | <li><majority>
|
---|
867 | <li><none>
|
---|
868 | <li><not>
|
---|
869 | <li><or>
|
---|
870 | <li><present>
|
---|
871 | <li><selector>
|
---|
872 | <li><size>
|
---|
873 | </ul>
|
---|
874 |
|
---|
875 | <a name="andselect"></a>
|
---|
876 | <h4>And Selector</h4>
|
---|
877 |
|
---|
878 | <p>The <code><and></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 | <fileset dir="${dist}" includes="**/*.jar">
|
---|
888 | <and>
|
---|
889 | <size value="4" units="Ki" when="more"/>
|
---|
890 | <date datetime="01/01/2001 12:00 AM" when="before"/>
|
---|
891 | </and>
|
---|
892 | </fileset>
|
---|
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><majority></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 | <fileset dir="${docs}" includes="**/*.html">
|
---|
929 | <majority>
|
---|
930 | <contains text="project" casesensitive="false"/>
|
---|
931 | <contains text="taskdef" casesensitive="false"/>
|
---|
932 | <contains text="IntrospectionHelper" casesensitive="true"/>
|
---|
933 | </majority>
|
---|
934 | </fileset>
|
---|
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><none></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 | <fileset dir="${src}" includes="**/*.java">
|
---|
956 | <none>
|
---|
957 | <present targetdir="${dest}"/>
|
---|
958 | <present targetdir="${dest}">
|
---|
959 | <mapper type="glob" from="*.java" to="*.class"/>
|
---|
960 | </present>
|
---|
961 | </none>
|
---|
962 | </fileset>
|
---|
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><not></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 | <fileset dir="${src}" includes="**/*.java">
|
---|
981 | <not>
|
---|
982 | <contains text="test"/>
|
---|
983 | </not>
|
---|
984 | </fileset>
|
---|
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><or></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 | <fileset dir="${basedir}">
|
---|
1005 | <or>
|
---|
1006 | <depth max="0"/>
|
---|
1007 | <filename name="*.png"/>
|
---|
1008 | <filename name="*.gif"/>
|
---|
1009 | <filename name="*.jpg"/>
|
---|
1010 | </or>
|
---|
1011 | </fileset>
|
---|
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><selector></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><project></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><selector></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>"if"</code> and
|
---|
1033 | <code>"unless"</code> attributes in exactly the same way they
|
---|
1034 | are used on targets or on the <code><include></code> and
|
---|
1035 | <code><exclude></code> tags within a
|
---|
1036 | <code><patternset></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 | <project default="all" basedir="./ant">
|
---|
1064 |
|
---|
1065 | <selector id="completed">
|
---|
1066 | <none>
|
---|
1067 | <depend targetdir="build/classes">
|
---|
1068 | <mapper type="glob" from="*.java" to="*.class"/>
|
---|
1069 | </depend>
|
---|
1070 | <depend targetdir="docs/manual/api">
|
---|
1071 | <mapper type="glob" from="*.java" to="*.html"/>
|
---|
1072 | </depend>
|
---|
1073 | </none>
|
---|
1074 | </selector>
|
---|
1075 |
|
---|
1076 | <target>
|
---|
1077 | <zip>
|
---|
1078 | <fileset dir="src/main" includes="**/*.java">
|
---|
1079 | <selector refid="completed"/>
|
---|
1080 | </fileset>
|
---|
1081 | </zip>
|
---|
1082 | </target>
|
---|
1083 |
|
---|
1084 | </project>
|
---|
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 | <fileset dir="${working.copy}">
|
---|
1096 | <or>
|
---|
1097 | <selector if="include.tests">
|
---|
1098 | <filename name="**/*Test.class">
|
---|
1099 | </selector>
|
---|
1100 | <selector if="include.source">
|
---|
1101 | <and>
|
---|
1102 | <filename name="**/*.java">
|
---|
1103 | <not>
|
---|
1104 | <selector unless="include.tests">
|
---|
1105 | <filename name="**/*Test.java">
|
---|
1106 | </selector>
|
---|
1107 | </not>
|
---|
1108 | </and>
|
---|
1109 | </selector>
|
---|
1110 | </or>
|
---|
1111 | </fileset>
|
---|
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 <custom> 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><custom></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><custom></code> to
|
---|
1168 | use your class as a selector:
|
---|
1169 | </p>
|
---|
1170 |
|
---|
1171 | <blockquote><pre>
|
---|
1172 | <fileset dir="${mydir}" includes="**/*">
|
---|
1173 | <custom classname="com.mydomain.MySelector">
|
---|
1174 | <param name="myattribute" value="myvalue"/>
|
---|
1175 | </custom>
|
---|
1176 | </fileset>
|
---|
1177 | </pre></blockquote>
|
---|
1178 |
|
---|
1179 | <p>A number of core selectors can also be used as custom selectors
|
---|
1180 | by specifying their attributes using <param> 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><custom></code>.</p>
|
---|
1198 |
|
---|
1199 | <blockquote><pre>
|
---|
1200 | <fileset dir="${doc.path}" includes="**/*">
|
---|
1201 | <custom classname="org.apache.tools.ant.types.selectors.DepthSelector">
|
---|
1202 | <param name="max" value="1"/>
|
---|
1203 | </custom>
|
---|
1204 | </fileset>
|
---|
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 © 2002-2004 The Apache Software
|
---|
1215 | Foundation. All rights Reserved.</p>
|
---|
1216 |
|
---|
1217 | </body>
|
---|
1218 |
|
---|
1219 | </html>
|
---|