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