source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/docs/manual/dirtasks.html@ 14982

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

initial import of LiRK3

File size: 11.9 KB
Line 
1<html>
2
3<head>
4<meta http-equiv="Content-Language" content="en-us">
5<title>Directory-based Tasks</title>
6<link rel="stylesheet" type="text/css" href="stylesheets/antmanual.css">
7</head>
8
9<body>
10
11<h2><a name="directorybasedtasks">Directory-based Tasks</a></h2>
12<p>Some tasks use directory trees for the actions they perform.
13For example, the <a href="CoreTasks/javac.html">javac</a> task, which
14compiles a directory tree with <code>.java</code> files into
15<code>.class</code> files, is one of these directory-based tasks. Because
16some of these tasks do so much work with a directory tree, the task itself
17can act as an implicit <a href="CoreTypes/fileset.html">FileSet</a>.</p>
18<p>Whether the fileset is implicit or not, it can often be very useful to
19work on a subset of the directory tree. This section describes how you can
20select a subset of such a directory tree when using one of these
21directory-based tasks.</p>
22<p>Ant gives you two ways to create a subset of files in a fileset, both of
23which can be used at the same time:</p>
24<ul>
25 <li>Only include files and directories that match any
26 <code>include</code> patterns and do not match any
27 <code>exclude</code> patterns in a given
28 <a href="CoreTypes/patternset.html">PatternSet</a>.</li>
29 <li>Select files based on selection criteria defined by a collection of
30 <a href="CoreTypes/selectors.html">selector</a> nested elements.</li>
31</ul>
32<h3><a name="patternset">Patternset</a></h3>
33
34<p>We said that Directory-based tasks can sometimes act as an implicit
35<a href="CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a>,
36but in addition to that, a FileSet acts as an implicit
37<a href="CoreTypes/patternset.html"><code>&lt;patternset&gt;</code></a>.</p>
38
39<p>The inclusion and exclusion elements of the implicit PatternSet can be
40specified inside the directory-based task (or explicit fileset) via
41either:</p>
42<ul>
43 <li>the attributes <code>includes</code> and
44 <code>excludes</code>.</li>
45 <li>nested elements <code>&lt;include&gt;</code> and
46 <code>&lt;exclude&gt;</code>.</li>
47 <li>external files specified with the attributes
48 <code>includesfile</code> and <code>excludesfile</code>.</li>
49 <li>external files specified with the nested elements
50 <code>&lt;includesfile&gt;</code> and <code>&lt;excludesfile&gt;</code>.
51 </li>
52</ul>
53When dealing with an external file, each line of the file
54is taken as a pattern that is added to the list of include or exclude
55patterns.</p>
56
57<p>When both inclusion and exclusion are used, only files/directories that
58match at least one of the include patterns and don't match any of the
59exclude patterns are used. If no include pattern is given, all files
60are assumed to match the include pattern (with the possible exception of
61the default excludes).</p>
62
63<h4><a name="patterns">Patterns</a></h4>
64
65<p>As described earlier, patterns are used for the inclusion and exclusion
66of files. These patterns look very much like the patterns used in DOS and
67UNIX:</p>
68<p>'*' matches zero or more characters, '?' matches one character.</p>
69
70<p>In general, patterns are considered relative paths, relative to a
71task dependent base directory (the dir attribute in the case of
72<code>&lt;fileset&gt;</code>). Only files found below that base
73directory are considered. So while a pattern like
74<code>../foo.java</code> is possible, it will not match anything when
75applied since the base directory's parent is never scanned for
76files.</p>
77
78<p><b>Examples:</b></p>
79<p>
80<code>*.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>.java</code>,
81<code>x.java</code> and <code>FooBar.java</code>, but
82not <code>FooBar.xml</code> (does not end with <code>.java</code>).</p>
83<p>
84<code>?.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>x.java</code>,
85<code>A.java</code>, but not <code>.java</code> or <code>xyz.java</code>
86(both don't have one character before <code>.java</code>).</p>
87<p>
88Combinations of <code>*</code>'s and <code>?</code>'s are allowed.</p>
89<p>Matching is done per-directory. This means that first the first directory in
90the pattern is matched against the first directory in the path to match. Then
91the second directory is matched, and so on. For example, when we have the pattern
92<code>/?abc/*/*.java</code>
93and the path <code>/xabc/foobar/test.java</code>,
94the first <code>?abc</code> is matched with <code>xabc</code>,
95then <code>*</code> is matched with <code>foobar</code>,
96and finally <code>*.java</code> is matched with <code>test.java</code>.
97They all match, so the path matches the pattern.</p>
98<p>To make things a bit more flexible, we add one extra feature, which makes it
99possible to match multiple directory levels. This can be used to match a
100complete directory tree, or a file anywhere in the directory tree.
101To do this, <code>**</code>
102must be used as the name of a directory.
103When <code>**</code> is used as the name of a
104directory in the pattern, it matches zero or more directories.
105For example:
106<code>/test/**</code> matches all files/directories under <code>/test/</code>,
107such as <code>/test/x.java</code>,
108or <code>/test/foo/bar/xyz.html</code>, but not <code>/xyz.xml</code>.</p>
109<p>There is one &quot;shorthand&quot; - if a pattern ends
110with <code>/</code>
111or <code>\</code>, then <code>**</code>
112is appended.
113For example, <code>mypackage/test/</code> is interpreted as if it were
114<code>mypackage/test/**</code>.</p>
115<p><b>Example patterns:</b></p>
116<table border="1" cellpadding="2" cellspacing="0">
117 <tr>
118 <td valign="top"><code>**/CVS/*</code></td>
119 <td valign="top">Matches all files in <code>CVS</code>
120 directories that can be located
121 anywhere in the directory tree.<br>
122 Matches:
123 <pre>
124 CVS/Repository
125 org/apache/CVS/Entries
126 org/apache/jakarta/tools/ant/CVS/Entries
127 </pre>
128 But not:
129 <pre>
130 org/apache/CVS/foo/bar/Entries (<code>foo/bar/</code>
131 part does not match)</td>
132 </pre>
133 </tr>
134 <tr>
135 <td valign="top"><code>org/apache/jakarta/**</code></td>
136 <td valign="top">Matches all files in the <code>org/apache/jakarta</code>
137 directory tree.<br>
138 Matches:
139 <pre>
140 org/apache/jakarta/tools/ant/docs/index.html
141 org/apache/jakarta/test.xml
142 </pre>
143 But not:
144 <pre>
145 org/apache/xyz.java
146 </pre>
147 (<code>jakarta/</code> part is missing).</td>
148 </tr>
149 <tr>
150 <td valign="top"><code>org/apache/**/CVS/*</code></td>
151 <td valign="top">Matches all files in <code>CVS</code> directories
152 that are located anywhere in the directory tree under
153 <code>org/apache</code>.<br>
154 Matches:
155 <pre>
156 org/apache/CVS/Entries
157 org/apache/jakarta/tools/ant/CVS/Entries
158 </pre>
159 But not:
160 <pre>
161 org/apache/CVS/foo/bar/Entries
162 </pre>
163 (<code>foo/bar/</code> part does not match)</td>
164 </tr>
165 <tr>
166 <td valign="top"><code>**/test/**</code></td>
167 <td valign="top">Matches all files that have a <code>test</code>
168 element in their path, including <code>test</code> as a filename.</td>
169 </tr>
170</table>
171<p>When these patterns are used in inclusion and exclusion, you have a powerful
172way to select just the files you want.</p>
173
174<h3><a name="selectors">Selectors</a></h3>
175<p>The <a href="CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a>,
176whether implicit or explicit in the
177directory-based task, also acts as an
178<a href="CoreTypes/selectors.html#andselect"><code>&lt;and&gt;</code></a>
179selector container. This can be used to create arbitrarily complicated
180selection criteria for the files the task should work with. See the
181<a href="CoreTypes/selectors.html">Selector</a> documentation for more
182information.</p>
183
184<h3><a name="tasklist">Standard Tasks/Filesets</a></h3>
185<p>Many of the standard tasks in ant take one or more filesets which follow
186the rules given here. This list, a subset of those, is a list of standard ant
187tasks that can act as an implicit fileset:</p>
188<ul>
189 <li><a href="CoreTasks/checksum.html"><code>&lt;checksum&gt;</code></a></li>
190 <li><a href="CoreTasks/copydir.html"><code>&lt;copydir&gt;</code></a> (deprecated)</li>
191 <li><a href="CoreTasks/delete.html"><code>&lt;delete&gt;</code></a></li>
192 <li><a href="CoreTasks/dependset.html"><code>&lt;dependset&gt;</code></a></li>
193 <li><a href="CoreTasks/fixcrlf.html"><code>&lt;fixcrlf&gt;</code></a></li>
194 <li><a href="CoreTasks/javac.html"><code>&lt;javac&gt;</code></a></li>
195 <li><a href="CoreTasks/replace.html"><code>&lt;replace&gt;</code></a></li>
196 <li><a href="CoreTasks/rmic.html"><code>&lt;rmic&gt;</code></a></li>
197 <li><a href="CoreTasks/style.html"><code>&lt;style&gt;</code> (aka <code>&lt;xslt&gt;</code>)</a></li>
198 <li><a href="CoreTasks/tar.html"><code>&lt;tar&gt;</code></a></li>
199 <li><a href="CoreTasks/zip.html"><code>&lt;zip&gt;</code></a></li>
200 <li><a href="OptionalTasks/ejb.html#ddcreator"><code>&lt;ddcreator&gt;</code></a></li>
201 <li><a href="OptionalTasks/ejb.html#ejbjar"><code>&lt;ejbjar&gt;</code></a></li>
202 <li><a href="OptionalTasks/ejb.html#ejbc"><code>&lt;ejbc&gt;</code></a></li>
203 <li><a href="OptionalTasks/cab.html"><code>&lt;cab&gt;</code></a></li>
204 <li><a href="OptionalTasks/icontract.html"><code>&lt;icontract&gt;</code></a></li>
205 <li><a href="OptionalTasks/native2ascii.html"><code>&lt;native2ascii&gt;</code></a></li>
206 <li><a href="OptionalTasks/netrexxc.html"><code>&lt;netrexxc&gt;</code></a></li>
207 <li>
208 <a href="OptionalTasks/renameextensions.html"><code>&lt;renameextensions&gt;</code></a>
209 </li>
210 <li><a href="OptionalTasks/depend.html"><code>&lt;depend&gt;</code></a></li>
211 <li><a href="OptionalTasks/dotnet.html"><code>&lt;ilasm&gt;</code></a></li>
212 <li><a href="OptionalTasks/dotnet.html"><code>&lt;csc&gt;</code></a></li>
213 <li><a href="OptionalTasks/dotnet.html"><code>&lt;vbc&gt;</code></a></li>
214 <li><a href="OptionalTasks/translate.html"><code>&lt;translate&gt;</code></a></li>
215 <li>
216 <a href="Integration/VAJAntTool.html#vajexport"><code>&lt;vajexport&gt;</code></a>
217 </li>
218 <li><code>&lt;image&gt;</code></li>
219 <li><a href="OptionalTasks/jlink.html"><code>&lt;jlink&gt;</code></a> (deprecated)</li>
220 <li><a href="OptionalTasks/jspc.html"><code>&lt;jspc&gt;</code></a></li>
221 <li><a href="OptionalTasks/wljspc.html"><code>&lt;wljspc&gt;</code></a></li>
222</ul>
223
224<h3><a name="examples">Examples</a></h3>
225<pre>
226&lt;copy todir=&quot;${dist}&quot;&gt;
227 &lt;fileset dir=&quot;${src}&quot;
228 includes=&quot;**/images/*&quot;
229 excludes=&quot;**/*.gif&quot;
230 /&gt;
231&lt;/copy&gt;</pre>
232<p>This copies all files in directories called <code>images</code> that are
233located in the directory tree defined by <code>${src}</code> to the
234destination directory defined by <code>${dist}</code>,
235but excludes all <code>*.gif</code> files from the copy.</p>
236<pre>
237&lt;copy todir=&quot;${dist}&quot;&gt;
238 &lt;fileset dir=&quot;${src}&quot;&gt;
239 &lt;include name=&quot;**/images/*&quot;/&gt;
240 &lt;exclude name=&quot;**/*.gif&quot;/&gt;
241 &lt;/fileset&gt;
242&lt;/copy&gt;
243</pre>
244<p> The same as the example above, but expressed using nested elements.</p>
245
246<pre>
247&lt;delete dir=&quot;${dist}&quot;&gt;
248 &lt;include name=&quot;**/images/*&quot;/&gt;
249 &lt;exclude name=&quot;**/*.gif&quot;/&gt;
250&lt;/delete&gt;
251</pre>
252<p>Deleting the original set of files, the <code>delete</code> task can act
253as an implicit fileset.</p>
254
255<h3><a name="defaultexcludes">Default Excludes</a></h3>
256<p>There are a set of definitions that are excluded by default from all
257directory-based tasks. They are:</p>
258<pre>
259 **/*~
260 **/#*#
261 **/.#*
262 **/%*%
263 **/._*
264 **/CVS
265 **/CVS/**
266 **/.cvsignore
267 **/SCCS
268 **/SCCS/**
269 **/vssver.scc
270 **/.svn
271 **/.svn/**
272 **/.DS_Store
273</pre>
274<p>If you do not want these default excludes applied, you may disable
275them with the <code>defaultexcludes=&quot;no&quot;</code>
276attribute.</p>
277
278<p>This is the default list, note that you can modify the list of
279default excludes by using the <a
280href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
281
282<hr>
283<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All
284rights Reserved.</p>
285
286</body>
287</html>
288
Note: See TracBrowser for help on using the repository browser.