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.
|
---|
13 | For example, the <a href="CoreTasks/javac.html">javac</a> task, which
|
---|
14 | compiles a directory tree with <code>.java</code> files into
|
---|
15 | <code>.class</code> files, is one of these directory-based tasks. Because
|
---|
16 | some of these tasks do so much work with a directory tree, the task itself
|
---|
17 | can 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
|
---|
19 | work on a subset of the directory tree. This section describes how you can
|
---|
20 | select a subset of such a directory tree when using one of these
|
---|
21 | directory-based tasks.</p>
|
---|
22 | <p>Ant gives you two ways to create a subset of files in a fileset, both of
|
---|
23 | which 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><fileset></code></a>,
|
---|
36 | but in addition to that, a FileSet acts as an implicit
|
---|
37 | <a href="CoreTypes/patternset.html"><code><patternset></code></a>.</p>
|
---|
38 |
|
---|
39 | <p>The inclusion and exclusion elements of the implicit PatternSet can be
|
---|
40 | specified inside the directory-based task (or explicit fileset) via
|
---|
41 | either:</p>
|
---|
42 | <ul>
|
---|
43 | <li>the attributes <code>includes</code> and
|
---|
44 | <code>excludes</code>.</li>
|
---|
45 | <li>nested elements <code><include></code> and
|
---|
46 | <code><exclude></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><includesfile></code> and <code><excludesfile></code>.
|
---|
51 | </li>
|
---|
52 | </ul>
|
---|
53 | When dealing with an external file, each line of the file
|
---|
54 | is taken as a pattern that is added to the list of include or exclude
|
---|
55 | patterns.</p>
|
---|
56 |
|
---|
57 | <p>When both inclusion and exclusion are used, only files/directories that
|
---|
58 | match at least one of the include patterns and don't match any of the
|
---|
59 | exclude patterns are used. If no include pattern is given, all files
|
---|
60 | are assumed to match the include pattern (with the possible exception of
|
---|
61 | the 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
|
---|
66 | of files. These patterns look very much like the patterns used in DOS and
|
---|
67 | UNIX:</p>
|
---|
68 | <p>'*' matches zero or more characters, '?' matches one character.</p>
|
---|
69 | <p><b>Examples:</b></p>
|
---|
70 | <p>
|
---|
71 | <code>*.java</code> matches <code>.java</code>,
|
---|
72 | <code>x.java</code> and <code>FooBar.java</code>, but
|
---|
73 | not <code>FooBar.xml</code> (does not end with <code>.java</code>).</p>
|
---|
74 | <p>
|
---|
75 | <code>?.java</code> matches <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>
|
---|
79 | Combinations 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
|
---|
81 | the pattern is matched against the first directory in the path to match. Then
|
---|
82 | the second directory is matched, and so on. For example, when we have the pattern
|
---|
83 | <code>/?abc/*/*.java</code>
|
---|
84 | and the path <code>/xabc/foobar/test.java</code>,
|
---|
85 | the first <code>?abc</code> is matched with <code>xabc</code>,
|
---|
86 | then <code>*</code> is matched with <code>foobar</code>,
|
---|
87 | and finally <code>*.java</code> is matched with <code>test.java</code>.
|
---|
88 | They 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
|
---|
90 | possible to match multiple directory levels. This can be used to match a
|
---|
91 | complete directory tree, or a file anywhere in the directory tree.
|
---|
92 | To do this, <code>**</code>
|
---|
93 | must be used as the name of a directory.
|
---|
94 | When <code>**</code> is used as the name of a
|
---|
95 | directory in the pattern, it matches zero or more directories.
|
---|
96 | For example:
|
---|
97 | <code>/test/**</code> matches all files/directories under <code>/test/</code>,
|
---|
98 | such as <code>/test/x.java</code>,
|
---|
99 | or <code>/test/foo/bar/xyz.html</code>, but not <code>/xyz.xml</code>.</p>
|
---|
100 | <p>There is one "shorthand" - if a pattern ends
|
---|
101 | with <code>/</code>
|
---|
102 | or <code>\</code>, then <code>**</code>
|
---|
103 | is appended.
|
---|
104 | For 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
|
---|
163 | way 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><fileset></code></a>,
|
---|
167 | whether implicit or explicit in the
|
---|
168 | directory-based task, also acts as an
|
---|
169 | <a href="CoreTypes/selectors.html#andselect"><code><and></code></a>
|
---|
170 | selector container. This can be used to create arbitrarily complicated
|
---|
171 | selection criteria for the files the task should work with. See the
|
---|
172 | <a href="CoreTypes/selectors.html">Selector</a> documentation for more
|
---|
173 | information.</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
|
---|
177 | the rules given here. This list, a subset of those, is a list of standard ant
|
---|
178 | tasks that can act as an implicit fileset:</p>
|
---|
179 | <ul>
|
---|
180 | <li><a href="CoreTasks/checksum.html"><checksum></a></li>
|
---|
181 | <li><a href="CoreTasks/copydir.html"><copydir></a> (deprecated)</li>
|
---|
182 | <li><a href="CoreTasks/delete.html"><delete></a></li>
|
---|
183 | <li><a href="CoreTasks/dependset.html"><dependset></a></li>
|
---|
184 | <li><a href="CoreTasks/fixcrlf.html"><fixcrlf></a></li>
|
---|
185 | <li><a href="CoreTasks/javac.html"><javac></a></li>
|
---|
186 | <li><a href="CoreTasks/replace.html"><replace></a></li>
|
---|
187 | <li><a href="CoreTasks/rmic.html"><rmic></a></li>
|
---|
188 | <li><a href="CoreTasks/style.html"><style> (aka <xslt>)</a></li>
|
---|
189 | <li><a href="CoreTasks/tar.html"><tar></a></li>
|
---|
190 | <li><a href="CoreTasks/zip.html"><zip></a></li>
|
---|
191 | <li><a href="OptionalTasks/ejb.html#ddcreator"><ddcreator></a></li>
|
---|
192 | <li><a href="OptionalTasks/ejb.html#ejbjar"><ejbjar></a></li>
|
---|
193 | <li><a href="OptionalTasks/ejb.html#ejbc"><ejbc></a></li>
|
---|
194 | <li><a href="OptionalTasks/cab.html"><cab></a></li>
|
---|
195 | <li><a href="OptionalTasks/icontract.html"><icontract></a></li>
|
---|
196 | <li><a href="OptionalTasks/native2ascii.html"><native2ascii></a></li>
|
---|
197 | <li><a href="OptionalTasks/netrexxc.html"><netrexxc></a></li>
|
---|
198 | <li>
|
---|
199 | <a href="OptionalTasks/renameextensions.html"><renameextensions></a>
|
---|
200 | </li>
|
---|
201 | <li><a href="OptionalTasks/depend.html"><depend></a></li>
|
---|
202 | <li><a href="OptionalTasks/dotnet.html"><ilasm></a></li>
|
---|
203 | <li><a href="OptionalTasks/dotnet.html"><csc></a></li>
|
---|
204 | <li><a href="OptionalTasks/dotnet.html"><vbc></a></li>
|
---|
205 | <li><a href="OptionalTasks/translate.html"><translate></a></li>
|
---|
206 | <li>
|
---|
207 | <a href="Integration/VAJAntTool.html#vajexport"><vajexport></a>
|
---|
208 | </li>
|
---|
209 | <li><image></li>
|
---|
210 | <li><a href="OptionalTasks/jlink.html"><jlink></a> (deprecated)</li>
|
---|
211 | <li><a href="OptionalTasks/jspc.html"><jspc></a></li>
|
---|
212 | <li><a href="OptionalTasks/wljspc.html"><wljspc></a></li>
|
---|
213 | </ul>
|
---|
214 |
|
---|
215 | <h3><a name="examples">Examples</a></h3>
|
---|
216 | <pre>
|
---|
217 | <copy todir="${dist}">
|
---|
218 | <fileset dir="${src}"
|
---|
219 | includes="**/images/*"
|
---|
220 | excludes="**/*.gif"
|
---|
221 | />
|
---|
222 | </copy></pre>
|
---|
223 | <p>This copies all files in directories called <code>images</code> that are
|
---|
224 | located in the directory tree defined by <code>${src}</code> to the
|
---|
225 | destination directory defined by <code>${dist}</code>,
|
---|
226 | but excludes all <code>*.gif</code> files from the copy.</p>
|
---|
227 | <pre>
|
---|
228 | <copy todir="${dist}">
|
---|
229 | <fileset dir="${src}">
|
---|
230 | <include name="**/images/*"/>
|
---|
231 | <exclude name="**/*.gif"/>
|
---|
232 | </fileset>
|
---|
233 | </copy>
|
---|
234 | </pre>
|
---|
235 | <p> The same as the example above, but expressed using nested elements.</p>
|
---|
236 |
|
---|
237 | <pre>
|
---|
238 | <delete dir="${dist}">
|
---|
239 | <include name="**/images/*"/>
|
---|
240 | <exclude name="**/*.gif"/>
|
---|
241 | </delete>
|
---|
242 | </pre>
|
---|
243 | <p>Deleting the original set of files, the <code>delete</code> task can act
|
---|
244 | as 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
|
---|
248 | directory-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
|
---|
266 | them with the <code>defaultexcludes="no"</code>
|
---|
267 | attribute.</p>
|
---|
268 |
|
---|
269 | <p>This is the default list, note that you can modify the list of
|
---|
270 | default excludes by using the <a
|
---|
271 | href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
|
---|
272 |
|
---|
273 | <hr>
|
---|
274 | <p align="center">Copyright © 2000-2004 The Apache Software Foundation. All
|
---|
275 | rights Reserved.</p>
|
---|
276 |
|
---|
277 | </body>
|
---|
278 | </html>
|
---|
279 |
|
---|