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.
|
---|
29 | For example, the <a href="CoreTasks/javac.html">javac</a> task, which
|
---|
30 | compiles a directory tree with <code>.java</code> files into
|
---|
31 | <code>.class</code> files, is one of these directory-based tasks. Because
|
---|
32 | some of these tasks do so much work with a directory tree, the task itself
|
---|
33 | can 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
|
---|
35 | work on a subset of the directory tree. This section describes how you can
|
---|
36 | select a subset of such a directory tree when using one of these
|
---|
37 | directory-based tasks.</p>
|
---|
38 | <p>Ant gives you two ways to create a subset of files in a fileset, both of
|
---|
39 | which 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><fileset></code></a>,
|
---|
52 | but in addition to that, a FileSet acts as an implicit
|
---|
53 | <a href="CoreTypes/patternset.html"><code><patternset></code></a>.</p>
|
---|
54 |
|
---|
55 | <p>The inclusion and exclusion elements of the implicit PatternSet can be
|
---|
56 | specified inside the directory-based task (or explicit fileset) via
|
---|
57 | either:</p>
|
---|
58 | <ul>
|
---|
59 | <li>the attributes <code>includes</code> and
|
---|
60 | <code>excludes</code>.</li>
|
---|
61 | <li>nested elements <code><include></code> and
|
---|
62 | <code><exclude></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><includesfile></code> and <code><excludesfile></code>.
|
---|
67 | </li>
|
---|
68 | </ul>
|
---|
69 | <p>
|
---|
70 | When dealing with an external file, each line of the file
|
---|
71 | is taken as a pattern that is added to the list of include or exclude
|
---|
72 | patterns.</p>
|
---|
73 |
|
---|
74 | <p>When both inclusion and exclusion are used, only files/directories that
|
---|
75 | match at least one of the include patterns and don't match any of the
|
---|
76 | exclude patterns are used. If no include pattern is given, all files
|
---|
77 | are assumed to match the include pattern (with the possible exception of
|
---|
78 | the 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
|
---|
83 | of files. These patterns look very much like the patterns used in DOS and
|
---|
84 | UNIX:</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
|
---|
88 | task dependent base directory (the dir attribute in the case of
|
---|
89 | <code><fileset></code>). Only files found below that base
|
---|
90 | directory are considered. So while a pattern like
|
---|
91 | <code>../foo.java</code> is possible, it will not match anything when
|
---|
92 | applied since the base directory's parent is never scanned for
|
---|
93 | files.</p>
|
---|
94 |
|
---|
95 | <p><b>Examples:</b></p>
|
---|
96 | <p>
|
---|
97 | <code>*.java</code> matches <code>.java</code>,
|
---|
98 | <code>x.java</code> and <code>FooBar.java</code>, but
|
---|
99 | not <code>FooBar.xml</code> (does not end with <code>.java</code>).</p>
|
---|
100 | <p>
|
---|
101 | <code>?.java</code> matches <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>
|
---|
105 | Combinations 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
|
---|
107 | the pattern is matched against the first directory in the path to match. Then
|
---|
108 | the second directory is matched, and so on. For example, when we have the pattern
|
---|
109 | <code>/?abc/*/*.java</code>
|
---|
110 | and the path <code>/xabc/foobar/test.java</code>,
|
---|
111 | the first <code>?abc</code> is matched with <code>xabc</code>,
|
---|
112 | then <code>*</code> is matched with <code>foobar</code>,
|
---|
113 | and finally <code>*.java</code> is matched with <code>test.java</code>.
|
---|
114 | They 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
|
---|
116 | possible to match multiple directory levels. This can be used to match a
|
---|
117 | complete directory tree, or a file anywhere in the directory tree.
|
---|
118 | To do this, <code>**</code>
|
---|
119 | must be used as the name of a directory.
|
---|
120 | When <code>**</code> is used as the name of a
|
---|
121 | directory in the pattern, it matches zero or more directories.
|
---|
122 | For example:
|
---|
123 | <code>/test/**</code> matches all files/directories under <code>/test/</code>,
|
---|
124 | such as <code>/test/x.java</code>,
|
---|
125 | or <code>/test/foo/bar/xyz.html</code>, but not <code>/xyz.xml</code>.</p>
|
---|
126 | <p>There is one "shorthand": if a pattern ends
|
---|
127 | with <code>/</code>
|
---|
128 | or <code>\</code>, then <code>**</code>
|
---|
129 | is appended.
|
---|
130 | For 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
|
---|
190 | way 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><fileset></code></a>,
|
---|
194 | whether implicit or explicit in the
|
---|
195 | directory-based task, also acts as an
|
---|
196 | <a href="CoreTypes/selectors.html#andselect"><code><and></code></a>
|
---|
197 | selector container. This can be used to create arbitrarily complicated
|
---|
198 | selection criteria for the files the task should work with. See the
|
---|
199 | <a href="CoreTypes/selectors.html">Selector</a> documentation for more
|
---|
200 | information.</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
|
---|
204 | the rules given here. This list, a subset of those, is a list of standard ant
|
---|
205 | tasks that can act as an implicit fileset:</p>
|
---|
206 | <ul>
|
---|
207 | <li><a href="CoreTasks/checksum.html"><code><checksum></code></a></li>
|
---|
208 | <li><a href="CoreTasks/copydir.html"><code><copydir></code></a> (deprecated)</li>
|
---|
209 | <li><a href="CoreTasks/delete.html"><code><delete></code></a></li>
|
---|
210 | <li><a href="CoreTasks/dependset.html"><code><dependset></code></a></li>
|
---|
211 | <li><a href="CoreTasks/fixcrlf.html"><code><fixcrlf></code></a></li>
|
---|
212 | <li><a href="CoreTasks/javac.html"><code><javac></code></a></li>
|
---|
213 | <li><a href="CoreTasks/replace.html"><code><replace></code></a></li>
|
---|
214 | <li><a href="CoreTasks/rmic.html"><code><rmic></code></a></li>
|
---|
215 | <li><a href="CoreTasks/style.html"><code><style></code> (aka <code><xslt></code>)</a></li>
|
---|
216 | <li><a href="CoreTasks/tar.html"><code><tar></code></a></li>
|
---|
217 | <li><a href="CoreTasks/zip.html"><code><zip></code></a></li>
|
---|
218 | <li><a href="OptionalTasks/ejb.html#ddcreator"><code><ddcreator></code></a></li>
|
---|
219 | <li><a href="OptionalTasks/ejb.html#ejbjar"><code><ejbjar></code></a></li>
|
---|
220 | <li><a href="OptionalTasks/ejb.html#ejbc"><code><ejbc></code></a></li>
|
---|
221 | <li><a href="OptionalTasks/cab.html"><code><cab></code></a></li>
|
---|
222 | <li><a href="OptionalTasks/native2ascii.html"><code><native2ascii></code></a></li>
|
---|
223 | <li><a href="OptionalTasks/netrexxc.html"><code><netrexxc></code></a></li>
|
---|
224 | <li>
|
---|
225 | <a href="OptionalTasks/renameextensions.html"><code><renameextensions></code></a>
|
---|
226 | </li>
|
---|
227 | <li><a href="OptionalTasks/depend.html"><code><depend></code></a></li>
|
---|
228 | <li><a href="OptionalTasks/dotnet.html"><code><ilasm></code></a></li>
|
---|
229 | <li><a href="OptionalTasks/dotnet.html"><code><csc></code></a></li>
|
---|
230 | <li><a href="OptionalTasks/dotnet.html"><code><vbc></code></a></li>
|
---|
231 | <li><a href="OptionalTasks/translate.html"><code><translate></code></a></li>
|
---|
232 | <li><a href="OptionalTasks/image.html"><code><image></code></a></li>
|
---|
233 | <li><a href="OptionalTasks/jlink.html"><code><jlink></code></a> (deprecated)</li>
|
---|
234 | <li><a href="OptionalTasks/jspc.html"><code><jspc></code></a></li>
|
---|
235 | <li><a href="OptionalTasks/wljspc.html"><code><wljspc></code></a></li>
|
---|
236 | </ul>
|
---|
237 |
|
---|
238 | <h3><a name="examples">Examples</a></h3>
|
---|
239 | <pre>
|
---|
240 | <copy todir="${dist}">
|
---|
241 | <fileset dir="${src}"
|
---|
242 | includes="**/images/*"
|
---|
243 | excludes="**/*.gif"
|
---|
244 | />
|
---|
245 | </copy></pre>
|
---|
246 | <p>This copies all files in directories called <code>images</code> that are
|
---|
247 | located in the directory tree defined by <code>${src}</code> to the
|
---|
248 | destination directory defined by <code>${dist}</code>,
|
---|
249 | but excludes all <code>*.gif</code> files from the copy.</p>
|
---|
250 | <pre>
|
---|
251 | <copy todir="${dist}">
|
---|
252 | <fileset dir="${src}">
|
---|
253 | <include name="**/images/*"/>
|
---|
254 | <exclude name="**/*.gif"/>
|
---|
255 | </fileset>
|
---|
256 | </copy>
|
---|
257 | </pre>
|
---|
258 | <p> The same as the example above, but expressed using nested elements.</p>
|
---|
259 |
|
---|
260 | <pre>
|
---|
261 | <delete dir="${dist}">
|
---|
262 | <include name="**/images/*"/>
|
---|
263 | <exclude name="**/*.gif"/>
|
---|
264 | </delete>
|
---|
265 | </pre>
|
---|
266 | <p>Deleting the original set of files, the <code>delete</code> task can act
|
---|
267 | as 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
|
---|
271 | directory-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
|
---|
289 | them with the <code>defaultexcludes="no"</code>
|
---|
290 | attribute.</p>
|
---|
291 |
|
---|
292 | <p>This is the default list; note that you can modify the list of
|
---|
293 | default excludes by using the <a
|
---|
294 | href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 | </body>
|
---|
299 | </html>
|
---|
300 |
|
---|