2001-02-13 12:32:01 +00:00
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Language" content="en-us">
|
2005-03-07 18:38:27 +00:00
|
|
|
<link rel="stylesheet" type="text/css" href="stylesheets/style.css"/>
|
2002-02-04 20:57:49 +00:00
|
|
|
<title>Directory-based Tasks</title>
|
2001-02-13 12:32:01 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h2><a name="directorybasedtasks">Directory-based Tasks</a></h2>
|
2003-02-04 17:29:11 +00:00
|
|
|
<p>Some tasks use directory trees for the actions they perform.
|
|
|
|
For example, the <a href="CoreTasks/javac.html">javac</a> task, which
|
|
|
|
compiles a directory tree with <code>.java</code> files into
|
|
|
|
<code>.class</code> files, is one of these directory-based tasks. Because
|
|
|
|
some of these tasks do so much work with a directory tree, the task itself
|
|
|
|
can act as an implicit <a href="CoreTypes/fileset.html">FileSet</a>.</p>
|
|
|
|
<p>Whether the fileset is implicit or not, it can often be very useful to
|
|
|
|
work on a subset of the directory tree. This section describes how you can
|
|
|
|
select a subset of such a directory tree when using one of these
|
|
|
|
directory-based tasks.</p>
|
|
|
|
<p>Ant gives you two ways to create a subset of files in a fileset, both of
|
|
|
|
which can be used at the same time:</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<ul>
|
2003-02-04 17:29:11 +00:00
|
|
|
<li>Only include files and directories that match any
|
|
|
|
<code>include</code> patterns and do not match any
|
|
|
|
<code>exclude</code> patterns in a given
|
|
|
|
<a href="CoreTypes/patternset.html">PatternSet</a>.</li>
|
|
|
|
<li>Select files based on selection criteria defined by a collection of
|
|
|
|
<a href="CoreTypes/selectors.html">selector</a> nested elements.</li>
|
2001-02-13 12:32:01 +00:00
|
|
|
</ul>
|
2003-02-04 17:29:11 +00:00
|
|
|
<h3><a name="patternset">Patternset</a></h3>
|
|
|
|
|
|
|
|
<p>We said that Directory-based tasks can sometimes act as an implicit
|
|
|
|
<a href="CoreTypes/fileset.html"><code><fileset></code></a>,
|
2003-09-21 20:34:38 +00:00
|
|
|
but in addition to that, a FileSet acts as an implicit
|
2003-02-04 17:29:11 +00:00
|
|
|
<a href="CoreTypes/patternset.html"><code><patternset></code></a>.</p>
|
|
|
|
|
|
|
|
<p>The inclusion and exclusion elements of the implicit PatternSet can be
|
|
|
|
specified inside the directory-based task (or explicit fileset) via
|
|
|
|
either:</p>
|
|
|
|
<ul>
|
|
|
|
<li>the attributes <code>includes</code> and
|
|
|
|
<code>excludes</code>.</li>
|
|
|
|
<li>nested elements <code><include></code> and
|
|
|
|
<code><exclude></code>.</li>
|
|
|
|
<li>external files specified with the attributes
|
|
|
|
<code>includesfile</code> and <code>excludesfile</code>.</li>
|
|
|
|
<li>external files specified with the nested elements
|
|
|
|
<code><includesfile></code> and <code><excludesfile></code>.
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
When dealing with an external file, each line of the file
|
2002-02-03 01:53:34 +00:00
|
|
|
is taken as a pattern that is added to the list of include or exclude
|
2001-02-13 12:32:01 +00:00
|
|
|
patterns.</p>
|
2003-02-04 17:29:11 +00:00
|
|
|
|
|
|
|
<p>When both inclusion and exclusion are used, only files/directories that
|
|
|
|
match at least one of the include patterns and don't match any of the
|
|
|
|
exclude patterns are used. If no include pattern is given, all files
|
|
|
|
are assumed to match the include pattern (with the possible exception of
|
|
|
|
the default excludes).</p>
|
|
|
|
|
|
|
|
<h4><a name="patterns">Patterns</a></h4>
|
|
|
|
|
|
|
|
<p>As described earlier, patterns are used for the inclusion and exclusion
|
|
|
|
of files. These patterns look very much like the patterns used in DOS and
|
|
|
|
UNIX:</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<p>'*' matches zero or more characters, '?' matches one character.</p>
|
2004-11-18 09:44:28 +00:00
|
|
|
|
|
|
|
<p>In general, patterns are considered relative paths, relative to a
|
|
|
|
task dependent base directory (the dir attribute in the case of
|
|
|
|
<code><fileset></code>). Only files found below that base
|
|
|
|
directory are considered. So while a pattern like
|
|
|
|
<code>../foo.java</code> is possible, it will not match anything when
|
|
|
|
applied since the base directory's parent is never scanned for
|
|
|
|
files.</p>
|
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<p><b>Examples:</b></p>
|
|
|
|
<p>
|
|
|
|
<code>*.java</code> matches <code>.java</code>,
|
|
|
|
<code>x.java</code> and <code>FooBar.java</code>, but
|
|
|
|
not <code>FooBar.xml</code> (does not end with <code>.java</code>).</p>
|
|
|
|
<p>
|
|
|
|
<code>?.java</code> matches <code>x.java</code>,
|
|
|
|
<code>A.java</code>, but not <code>.java</code> or <code>xyz.java</code>
|
|
|
|
(both don't have one character before <code>.java</code>).</p>
|
|
|
|
<p>
|
|
|
|
Combinations of <code>*</code>'s and <code>?</code>'s are allowed.</p>
|
|
|
|
<p>Matching is done per-directory. This means that first the first directory in
|
|
|
|
the pattern is matched against the first directory in the path to match. Then
|
2003-02-04 17:29:11 +00:00
|
|
|
the second directory is matched, and so on. For example, when we have the pattern
|
|
|
|
<code>/?abc/*/*.java</code>
|
2001-02-13 12:32:01 +00:00
|
|
|
and the path <code>/xabc/foobar/test.java</code>,
|
|
|
|
the first <code>?abc</code> is matched with <code>xabc</code>,
|
|
|
|
then <code>*</code> is matched with <code>foobar</code>,
|
|
|
|
and finally <code>*.java</code> is matched with <code>test.java</code>.
|
|
|
|
They all match, so the path matches the pattern.</p>
|
|
|
|
<p>To make things a bit more flexible, we add one extra feature, which makes it
|
|
|
|
possible to match multiple directory levels. This can be used to match a
|
|
|
|
complete directory tree, or a file anywhere in the directory tree.
|
|
|
|
To do this, <code>**</code>
|
|
|
|
must be used as the name of a directory.
|
|
|
|
When <code>**</code> is used as the name of a
|
|
|
|
directory in the pattern, it matches zero or more directories.
|
|
|
|
For example:
|
|
|
|
<code>/test/**</code> matches all files/directories under <code>/test/</code>,
|
|
|
|
such as <code>/test/x.java</code>,
|
|
|
|
or <code>/test/foo/bar/xyz.html</code>, but not <code>/xyz.xml</code>.</p>
|
2001-03-09 08:54:35 +00:00
|
|
|
<p>There is one "shorthand" - if a pattern ends
|
2001-02-13 12:32:01 +00:00
|
|
|
with <code>/</code>
|
|
|
|
or <code>\</code>, then <code>**</code>
|
|
|
|
is appended.
|
|
|
|
For example, <code>mypackage/test/</code> is interpreted as if it were
|
|
|
|
<code>mypackage/test/**</code>.</p>
|
|
|
|
<p><b>Example patterns:</b></p>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><code>**/CVS/*</code></td>
|
2003-02-04 17:29:11 +00:00
|
|
|
<td valign="top">Matches all files in <code>CVS</code>
|
|
|
|
directories that can be located
|
2001-02-13 12:32:01 +00:00
|
|
|
anywhere in the directory tree.<br>
|
|
|
|
Matches:
|
|
|
|
<pre>
|
|
|
|
CVS/Repository
|
|
|
|
org/apache/CVS/Entries
|
|
|
|
org/apache/jakarta/tools/ant/CVS/Entries
|
|
|
|
</pre>
|
|
|
|
But not:
|
|
|
|
<pre>
|
2003-02-04 17:29:11 +00:00
|
|
|
org/apache/CVS/foo/bar/Entries (<code>foo/bar/</code>
|
|
|
|
part does not match)</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</pre>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><code>org/apache/jakarta/**</code></td>
|
2003-02-04 17:29:11 +00:00
|
|
|
<td valign="top">Matches all files in the <code>org/apache/jakarta</code>
|
|
|
|
directory tree.<br>
|
2001-02-13 12:32:01 +00:00
|
|
|
Matches:
|
|
|
|
<pre>
|
|
|
|
org/apache/jakarta/tools/ant/docs/index.html
|
|
|
|
org/apache/jakarta/test.xml
|
|
|
|
</pre>
|
|
|
|
But not:
|
|
|
|
<pre>
|
|
|
|
org/apache/xyz.java
|
|
|
|
</pre>
|
|
|
|
(<code>jakarta/</code> part is missing).</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><code>org/apache/**/CVS/*</code></td>
|
|
|
|
<td valign="top">Matches all files in <code>CVS</code> directories
|
|
|
|
that are located anywhere in the directory tree under
|
|
|
|
<code>org/apache</code>.<br>
|
|
|
|
Matches:
|
|
|
|
<pre>
|
|
|
|
org/apache/CVS/Entries
|
|
|
|
org/apache/jakarta/tools/ant/CVS/Entries
|
|
|
|
</pre>
|
|
|
|
But not:
|
|
|
|
<pre>
|
|
|
|
org/apache/CVS/foo/bar/Entries
|
|
|
|
</pre>
|
|
|
|
(<code>foo/bar/</code> part does not match)</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><code>**/test/**</code></td>
|
|
|
|
<td valign="top">Matches all files that have a <code>test</code>
|
|
|
|
element in their path, including <code>test</code> as a filename.</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<p>When these patterns are used in inclusion and exclusion, you have a powerful
|
|
|
|
way to select just the files you want.</p>
|
|
|
|
|
2003-02-04 17:29:11 +00:00
|
|
|
<h3><a name="selectors">Selectors</a></h3>
|
|
|
|
<p>The <a href="CoreTypes/fileset.html"><code><fileset></code></a>,
|
|
|
|
whether implicit or explicit in the
|
|
|
|
directory-based task, also acts as an
|
|
|
|
<a href="CoreTypes/selectors.html#andselect"><code><and></code></a>
|
|
|
|
selector container. This can be used to create arbitrarily complicated
|
|
|
|
selection criteria for the files the task should work with. See the
|
|
|
|
<a href="CoreTypes/selectors.html">Selector</a> documentation for more
|
|
|
|
information.</p>
|
|
|
|
|
|
|
|
<h3><a name="tasklist">Standard Tasks/Filesets</a></h3>
|
|
|
|
<p>Many of the standard tasks in ant take one or more filesets which follow
|
|
|
|
the rules given here. This list, a subset of those, is a list of standard ant
|
|
|
|
tasks that can act as an implicit fileset:</p>
|
|
|
|
<ul>
|
2004-11-19 09:07:12 +00:00
|
|
|
<li><a href="CoreTasks/checksum.html"><code><checksum></code></a></li>
|
|
|
|
<li><a href="CoreTasks/copydir.html"><code><copydir></code></a> (deprecated)</li>
|
|
|
|
<li><a href="CoreTasks/delete.html"><code><delete></code></a></li>
|
|
|
|
<li><a href="CoreTasks/dependset.html"><code><dependset></code></a></li>
|
|
|
|
<li><a href="CoreTasks/fixcrlf.html"><code><fixcrlf></code></a></li>
|
|
|
|
<li><a href="CoreTasks/javac.html"><code><javac></code></a></li>
|
|
|
|
<li><a href="CoreTasks/replace.html"><code><replace></code></a></li>
|
|
|
|
<li><a href="CoreTasks/rmic.html"><code><rmic></code></a></li>
|
|
|
|
<li><a href="CoreTasks/style.html"><code><style></code> (aka <code><xslt></code>)</a></li>
|
|
|
|
<li><a href="CoreTasks/tar.html"><code><tar></code></a></li>
|
|
|
|
<li><a href="CoreTasks/zip.html"><code><zip></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/ejb.html#ddcreator"><code><ddcreator></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/ejb.html#ejbjar"><code><ejbjar></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/ejb.html#ejbc"><code><ejbc></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/cab.html"><code><cab></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/icontract.html"><code><icontract></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/native2ascii.html"><code><native2ascii></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/netrexxc.html"><code><netrexxc></code></a></li>
|
2003-02-04 17:29:11 +00:00
|
|
|
<li>
|
2004-11-19 09:07:12 +00:00
|
|
|
<a href="OptionalTasks/renameextensions.html"><code><renameextensions></code></a>
|
2003-02-04 17:29:11 +00:00
|
|
|
</li>
|
2004-11-19 09:07:12 +00:00
|
|
|
<li><a href="OptionalTasks/depend.html"><code><depend></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/dotnet.html"><code><ilasm></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/dotnet.html"><code><csc></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/dotnet.html"><code><vbc></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/translate.html"><code><translate></code></a></li>
|
2003-02-04 17:29:11 +00:00
|
|
|
<li>
|
2004-11-19 09:07:12 +00:00
|
|
|
<a href="Integration/VAJAntTool.html#vajexport"><code><vajexport></code></a>
|
2003-02-04 17:29:11 +00:00
|
|
|
</li>
|
2004-11-19 09:07:12 +00:00
|
|
|
<li><code><image></code></li>
|
|
|
|
<li><a href="OptionalTasks/jlink.html"><code><jlink></code></a> (deprecated)</li>
|
|
|
|
<li><a href="OptionalTasks/jspc.html"><code><jspc></code></a></li>
|
|
|
|
<li><a href="OptionalTasks/wljspc.html"><code><wljspc></code></a></li>
|
2003-02-04 17:29:11 +00:00
|
|
|
</ul>
|
|
|
|
|
|
|
|
<h3><a name="examples">Examples</a></h3>
|
2002-02-03 01:53:34 +00:00
|
|
|
<pre>
|
2001-09-08 01:05:18 +00:00
|
|
|
<copy todir="${dist}">
|
2002-02-03 01:53:34 +00:00
|
|
|
<fileset dir="${src}"
|
|
|
|
includes="**/images/*"
|
|
|
|
excludes="**/*.gif"
|
2001-02-13 12:32:01 +00:00
|
|
|
/>
|
|
|
|
</copy></pre>
|
|
|
|
<p>This copies all files in directories called <code>images</code> that are
|
|
|
|
located in the directory tree defined by <code>${src}</code> to the
|
|
|
|
destination directory defined by <code>${dist}</code>,
|
|
|
|
but excludes all <code>*.gif</code> files from the copy.</p>
|
|
|
|
<pre>
|
2001-09-08 01:05:18 +00:00
|
|
|
<copy todir="${dist}">
|
2001-07-20 14:01:48 +00:00
|
|
|
<fileset dir="${src}">
|
2001-02-13 12:32:01 +00:00
|
|
|
<include name="**/images/*"/>
|
|
|
|
<exclude name="**/*.gif"/>
|
|
|
|
</fileset>
|
|
|
|
</copy>
|
|
|
|
</pre>
|
2003-02-04 17:29:11 +00:00
|
|
|
<p> The same as the example above, but expressed using nested elements.</p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<delete dir="${dist}">
|
|
|
|
<include name="**/images/*"/>
|
|
|
|
<exclude name="**/*.gif"/>
|
|
|
|
</delete>
|
|
|
|
</pre>
|
|
|
|
<p>Deleting the original set of files, the <code>delete</code> task can act
|
|
|
|
as an implicit fileset.</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
|
2001-11-21 16:29:49 +00:00
|
|
|
<h3><a name="defaultexcludes">Default Excludes</a></h3>
|
2003-02-04 17:29:11 +00:00
|
|
|
<p>There are a set of definitions that are excluded by default from all
|
|
|
|
directory-based tasks. They are:</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<pre>
|
|
|
|
**/*~
|
|
|
|
**/#*#
|
2001-03-29 10:29:46 +00:00
|
|
|
**/.#*
|
2001-02-13 12:32:01 +00:00
|
|
|
**/%*%
|
2002-02-03 01:53:34 +00:00
|
|
|
**/._*
|
2001-02-13 12:32:01 +00:00
|
|
|
**/CVS
|
|
|
|
**/CVS/**
|
|
|
|
**/.cvsignore
|
2001-03-29 10:29:46 +00:00
|
|
|
**/SCCS
|
|
|
|
**/SCCS/**
|
2001-07-12 13:02:47 +00:00
|
|
|
**/vssver.scc
|
2002-07-09 21:06:15 +00:00
|
|
|
**/.svn
|
|
|
|
**/.svn/**
|
2003-01-19 01:32:11 +00:00
|
|
|
**/.DS_Store
|
2001-02-13 12:32:01 +00:00
|
|
|
</pre>
|
2003-05-09 12:10:36 +00:00
|
|
|
<p>If you do not want these default excludes applied, you may disable
|
|
|
|
them with the <code>defaultexcludes="no"</code>
|
|
|
|
attribute.</p>
|
|
|
|
|
|
|
|
<p>This is the default list, note that you can modify the list of
|
|
|
|
default excludes by using the <a
|
|
|
|
href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
|
|
|
|
|
2001-02-13 12:32:01 +00:00
|
|
|
<hr>
|
2005-03-07 18:38:27 +00:00
|
|
|
<p align="center">Copyright © 2000-2005 The Apache Software Foundation. All
|
2003-02-04 17:29:11 +00:00
|
|
|
rights Reserved.</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|