source: other-projects/trunk/realistic-books/packages/AntInstaller/web/manual1.6.2/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: 11.1 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<p><b>Examples:</b></p>
70<p>
71<code>*.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>.java</code>,
72<code>x.java</code> and <code>FooBar.java</code>, but
73not <code>FooBar.xml</code> (does not end with <code>.java</code>).</p>
74<p>
75<code>?.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>x.java</code>,
76<code>A.java</code>, but not <code>.java</code> or <code>xyz.java</code>
77(both don't have one character before <code>.java</code>).</p>
78<p>
79Combinations of <code>*</code>'s and <code>?</code>'s are allowed.</p>
80<p>Matching is done per-directory. This means that first the first directory in
81the pattern is matched against the first directory in the path to match. Then
82the second directory is matched, and so on. For example, when we have the pattern
83<code>/?abc/*/*.java</code>
84and the path <code>/xabc/foobar/test.java</code>,
85the first <code>?abc</code> is matched with <code>xabc</code>,
86then <code>*</code> is matched with <code>foobar</code>,
87and finally <code>*.java</code> is matched with <code>test.java</code>.
88They all match, so the path matches the pattern.</p>
89<p>To make things a bit more flexible, we add one extra feature, which makes it
90possible to match multiple directory levels. This can be used to match a
91complete directory tree, or a file anywhere in the directory tree.
92To do this, <code>**</code>
93must be used as the name of a directory.
94When <code>**</code> is used as the name of a
95directory in the pattern, it matches zero or more directories.
96For example:
97<code>/test/**</code> matches all files/directories under <code>/test/</code>,
98such as <code>/test/x.java</code>,
99or <code>/test/foo/bar/xyz.html</code>, but not <code>/xyz.xml</code>.</p>
100<p>There is one &quot;shorthand&quot; - if a pattern ends
101with <code>/</code>
102or <code>\</code>, then <code>**</code>
103is appended.
104For example, <code>mypackage/test/</code> is interpreted as if it were
105<code>mypackage/test/**</code>.</p>
106<p><b>Example patterns:</b></p>
107<table border="1" cellpadding="2" cellspacing="0">
108 <tr>
109 <td valign="top"><code>**/CVS/*</code></td>
110 <td valign="top">Matches all files in <code>CVS</code>
111 directories that can be located
112 anywhere in the directory tree.<br>
113 Matches:
114 <pre>
115 CVS/Repository
116 org/apache/CVS/Entries
117 org/apache/jakarta/tools/ant/CVS/Entries
118 </pre>
119 But not:
120 <pre>
121 org/apache/CVS/foo/bar/Entries (<code>foo/bar/</code>
122 part does not match)</td>
123 </pre>
124 </tr>
125 <tr>
126 <td valign="top"><code>org/apache/jakarta/**</code></td>
127 <td valign="top">Matches all files in the <code>org/apache/jakarta</code>
128 directory tree.<br>
129 Matches:
130 <pre>
131 org/apache/jakarta/tools/ant/docs/index.html
132 org/apache/jakarta/test.xml
133 </pre>
134 But not:
135 <pre>
136 org/apache/xyz.java
137 </pre>
138 (<code>jakarta/</code> part is missing).</td>
139 </tr>
140 <tr>
141 <td valign="top"><code>org/apache/**/CVS/*</code></td>
142 <td valign="top">Matches all files in <code>CVS</code> directories
143 that are located anywhere in the directory tree under
144 <code>org/apache</code>.<br>
145 Matches:
146 <pre>
147 org/apache/CVS/Entries
148 org/apache/jakarta/tools/ant/CVS/Entries
149 </pre>
150 But not:
151 <pre>
152 org/apache/CVS/foo/bar/Entries
153 </pre>
154 (<code>foo/bar/</code> part does not match)</td>
155 </tr>
156 <tr>
157 <td valign="top"><code>**/test/**</code></td>
158 <td valign="top">Matches all files that have a <code>test</code>
159 element in their path, including <code>test</code> as a filename.</td>
160 </tr>
161</table>
162<p>When these patterns are used in inclusion and exclusion, you have a powerful
163way to select just the files you want.</p>
164
165<h3><a name="selectors">Selectors</a></h3>
166<p>The <a href="CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a>,
167whether implicit or explicit in the
168directory-based task, also acts as an
169<a href="CoreTypes/selectors.html#andselect"><code>&lt;and&gt;</code></a>
170selector container. This can be used to create arbitrarily complicated
171selection criteria for the files the task should work with. See the
172<a href="CoreTypes/selectors.html">Selector</a> documentation for more
173information.</p>
174
175<h3><a name="tasklist">Standard Tasks/Filesets</a></h3>
176<p>Many of the standard tasks in ant take one or more filesets which follow
177the rules given here. This list, a subset of those, is a list of standard ant
178tasks that can act as an implicit fileset:</p>
179<ul>
180 <li><a href="CoreTasks/checksum.html">&lt;checksum&gt;</a></li>
181 <li><a href="CoreTasks/copydir.html">&lt;copydir&gt;</a> (deprecated)</li>
182 <li><a href="CoreTasks/delete.html">&lt;delete&gt;</a></li>
183 <li><a href="CoreTasks/dependset.html">&lt;dependset&gt;</a></li>
184 <li><a href="CoreTasks/fixcrlf.html">&lt;fixcrlf&gt;</a></li>
185 <li><a href="CoreTasks/javac.html">&lt;javac&gt;</a></li>
186 <li><a href="CoreTasks/replace.html">&lt;replace&gt;</a></li>
187 <li><a href="CoreTasks/rmic.html">&lt;rmic&gt;</a></li>
188 <li><a href="CoreTasks/style.html">&lt;style&gt; (aka &lt;xslt&gt;)</a></li>
189 <li><a href="CoreTasks/tar.html">&lt;tar&gt;</a></li>
190 <li><a href="CoreTasks/zip.html">&lt;zip&gt;</a></li>
191 <li><a href="OptionalTasks/ejb.html#ddcreator">&lt;ddcreator&gt;</a></li>
192 <li><a href="OptionalTasks/ejb.html#ejbjar">&lt;ejbjar&gt;</a></li>
193 <li><a href="OptionalTasks/ejb.html#ejbc">&lt;ejbc&gt;</a></li>
194 <li><a href="OptionalTasks/cab.html">&lt;cab&gt;</a></li>
195 <li><a href="OptionalTasks/icontract.html">&lt;icontract&gt;</a></li>
196 <li><a href="OptionalTasks/native2ascii.html">&lt;native2ascii&gt;</a></li>
197 <li><a href="OptionalTasks/netrexxc.html">&lt;netrexxc&gt;</a></li>
198 <li>
199 <a href="OptionalTasks/renameextensions.html">&lt;renameextensions&gt;</a>
200 </li>
201 <li><a href="OptionalTasks/depend.html">&lt;depend&gt;</a></li>
202 <li><a href="OptionalTasks/dotnet.html">&lt;ilasm&gt;</a></li>
203 <li><a href="OptionalTasks/dotnet.html">&lt;csc&gt;</a></li>
204 <li><a href="OptionalTasks/dotnet.html">&lt;vbc&gt;</a></li>
205 <li><a href="OptionalTasks/translate.html">&lt;translate&gt;</a></li>
206 <li>
207 <a href="Integration/VAJAntTool.html#vajexport">&lt;vajexport&gt;</a>
208 </li>
209 <li>&lt;image&gt;</li>
210 <li><a href="OptionalTasks/jlink.html">&lt;jlink&gt;</a> (deprecated)</li>
211 <li><a href="OptionalTasks/jspc.html">&lt;jspc&gt;</a></li>
212 <li><a href="OptionalTasks/wljspc.html">&lt;wljspc&gt;</a></li>
213</ul>
214
215<h3><a name="examples">Examples</a></h3>
216<pre>
217&lt;copy todir=&quot;${dist}&quot;&gt;
218 &lt;fileset dir=&quot;${src}&quot;
219 includes=&quot;**/images/*&quot;
220 excludes=&quot;**/*.gif&quot;
221 /&gt;
222&lt;/copy&gt;</pre>
223<p>This copies all files in directories called <code>images</code> that are
224located in the directory tree defined by <code>${src}</code> to the
225destination directory defined by <code>${dist}</code>,
226but excludes all <code>*.gif</code> files from the copy.</p>
227<pre>
228&lt;copy todir=&quot;${dist}&quot;&gt;
229 &lt;fileset dir=&quot;${src}&quot;&gt;
230 &lt;include name=&quot;**/images/*&quot;/&gt;
231 &lt;exclude name=&quot;**/*.gif&quot;/&gt;
232 &lt;/fileset&gt;
233&lt;/copy&gt;
234</pre>
235<p> The same as the example above, but expressed using nested elements.</p>
236
237<pre>
238&lt;delete dir=&quot;${dist}&quot;&gt;
239 &lt;include name=&quot;**/images/*&quot;/&gt;
240 &lt;exclude name=&quot;**/*.gif&quot;/&gt;
241&lt;/delete&gt;
242</pre>
243<p>Deleting the original set of files, the <code>delete</code> task can act
244as an implicit fileset.</p>
245
246<h3><a name="defaultexcludes">Default Excludes</a></h3>
247<p>There are a set of definitions that are excluded by default from all
248directory-based tasks. They are:</p>
249<pre>
250 **/*~
251 **/#*#
252 **/.#*
253 **/%*%
254 **/._*
255 **/CVS
256 **/CVS/**
257 **/.cvsignore
258 **/SCCS
259 **/SCCS/**
260 **/vssver.scc
261 **/.svn
262 **/.svn/**
263 **/.DS_Store
264</pre>
265<p>If you do not want these default excludes applied, you may disable
266them with the <code>defaultexcludes=&quot;no&quot;</code>
267attribute.</p>
268
269<p>This is the default list, note that you can modify the list of
270default excludes by using the <a
271href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
272
273<hr>
274<p align="center">Copyright &copy; 2000-2004 The Apache Software Foundation. All
275rights Reserved.</p>
276
277</body>
278</html>
279
Note: See TracBrowser for help on using the repository browser.