You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dirtasks.html 12 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
  5. <title>Directory-based Tasks</title>
  6. </head>
  7. <body>
  8. <h2><a name="directorybasedtasks">Directory-based Tasks</a></h2>
  9. <p>Some tasks use directory trees for the actions they perform.
  10. For example, the <a href="CoreTasks/javac.html">javac</a> task, which
  11. compiles a directory tree with <code>.java</code> files into
  12. <code>.class</code> files, is one of these directory-based tasks. Because
  13. some of these tasks do so much work with a directory tree, the task itself
  14. can act as an implicit <a href="CoreTypes/fileset.html">FileSet</a>.</p>
  15. <p>Whether the fileset is implicit or not, it can often be very useful to
  16. work on a subset of the directory tree. This section describes how you can
  17. select a subset of such a directory tree when using one of these
  18. directory-based tasks.</p>
  19. <p>Ant gives you two ways to create a subset of files in a fileset, both of
  20. which can be used at the same time:</p>
  21. <ul>
  22. <li>Only include files and directories that match any
  23. <code>include</code> patterns and do not match any
  24. <code>exclude</code> patterns in a given
  25. <a href="CoreTypes/patternset.html">PatternSet</a>.</li>
  26. <li>Select files based on selection criteria defined by a collection of
  27. <a href="CoreTypes/selectors.html">selector</a> nested elements.</li>
  28. </ul>
  29. <h3><a name="patternset">Patternset</a></h3>
  30. <p>We said that Directory-based tasks can sometimes act as an implicit
  31. <a href="CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a>,
  32. but in addition to that, a FileSet acts as an implicit
  33. <a href="CoreTypes/patternset.html"><code>&lt;patternset&gt;</code></a>.</p>
  34. <p>The inclusion and exclusion elements of the implicit PatternSet can be
  35. specified inside the directory-based task (or explicit fileset) via
  36. either:</p>
  37. <ul>
  38. <li>the attributes <code>includes</code> and
  39. <code>excludes</code>.</li>
  40. <li>nested elements <code>&lt;include&gt;</code> and
  41. <code>&lt;exclude&gt;</code>.</li>
  42. <li>external files specified with the attributes
  43. <code>includesfile</code> and <code>excludesfile</code>.</li>
  44. <li>external files specified with the nested elements
  45. <code>&lt;includesfile&gt;</code> and <code>&lt;excludesfile&gt;</code>.
  46. </li>
  47. </ul>
  48. <p>
  49. When dealing with an external file, each line of the file
  50. is taken as a pattern that is added to the list of include or exclude
  51. patterns.</p>
  52. <p>When both inclusion and exclusion are used, only files/directories that
  53. match at least one of the include patterns and don't match any of the
  54. exclude patterns are used. If no include pattern is given, all files
  55. are assumed to match the include pattern (with the possible exception of
  56. the default excludes).</p>
  57. <h4><a name="patterns">Patterns</a></h4>
  58. <p>As described earlier, patterns are used for the inclusion and exclusion
  59. of files. These patterns look very much like the patterns used in DOS and
  60. UNIX:</p>
  61. <p>'*' matches zero or more characters, '?' matches one character.</p>
  62. <p>In general, patterns are considered relative paths, relative to a
  63. task dependent base directory (the dir attribute in the case of
  64. <code>&lt;fileset&gt;</code>). Only files found below that base
  65. directory are considered. So while a pattern like
  66. <code>../foo.java</code> is possible, it will not match anything when
  67. applied since the base directory's parent is never scanned for
  68. files.</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
  73. not <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>
  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 &quot;shorthand&quot;: 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)
  123. </pre>
  124. </td>
  125. </tr>
  126. <tr>
  127. <td valign="top"><code>org/apache/jakarta/**</code></td>
  128. <td valign="top">Matches all files in the <code>org/apache/jakarta</code>
  129. directory tree.<br>
  130. Matches:
  131. <pre>
  132. org/apache/jakarta/tools/ant/docs/index.html
  133. org/apache/jakarta/test.xml
  134. </pre>
  135. But not:
  136. <pre>
  137. org/apache/xyz.java
  138. </pre>
  139. (<code>jakarta/</code> part is missing).</td>
  140. </tr>
  141. <tr>
  142. <td valign="top"><code>org/apache/**/CVS/*</code></td>
  143. <td valign="top">Matches all files in <code>CVS</code> directories
  144. that are located anywhere in the directory tree under
  145. <code>org/apache</code>.<br>
  146. Matches:
  147. <pre>
  148. org/apache/CVS/Entries
  149. org/apache/jakarta/tools/ant/CVS/Entries
  150. </pre>
  151. But not:
  152. <pre>
  153. org/apache/CVS/foo/bar/Entries
  154. </pre>
  155. (<code>foo/bar/</code> part does not match)</td>
  156. </tr>
  157. <tr>
  158. <td valign="top"><code>**/test/**</code></td>
  159. <td valign="top">Matches all files that have a <code>test</code>
  160. element in their path, including <code>test</code> as a filename.</td>
  161. </tr>
  162. </table>
  163. <p>When these patterns are used in inclusion and exclusion, you have a powerful
  164. way to select just the files you want.</p>
  165. <h3><a name="selectors">Selectors</a></h3>
  166. <p>The <a href="CoreTypes/fileset.html"><code>&lt;fileset&gt;</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>&lt;and&gt;</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. <h3><a name="tasklist">Standard Tasks/Filesets</a></h3>
  175. <p>Many of the standard tasks in ant take one or more filesets which follow
  176. the rules given here. This list, a subset of those, is a list of standard ant
  177. tasks that can act as an implicit fileset:</p>
  178. <ul>
  179. <li><a href="CoreTasks/checksum.html"><code>&lt;checksum&gt;</code></a></li>
  180. <li><a href="CoreTasks/copydir.html"><code>&lt;copydir&gt;</code></a> (deprecated)</li>
  181. <li><a href="CoreTasks/delete.html"><code>&lt;delete&gt;</code></a></li>
  182. <li><a href="CoreTasks/dependset.html"><code>&lt;dependset&gt;</code></a></li>
  183. <li><a href="CoreTasks/fixcrlf.html"><code>&lt;fixcrlf&gt;</code></a></li>
  184. <li><a href="CoreTasks/javac.html"><code>&lt;javac&gt;</code></a></li>
  185. <li><a href="CoreTasks/replace.html"><code>&lt;replace&gt;</code></a></li>
  186. <li><a href="CoreTasks/rmic.html"><code>&lt;rmic&gt;</code></a></li>
  187. <li><a href="CoreTasks/style.html"><code>&lt;style&gt;</code> (aka <code>&lt;xslt&gt;</code>)</a></li>
  188. <li><a href="CoreTasks/tar.html"><code>&lt;tar&gt;</code></a></li>
  189. <li><a href="CoreTasks/zip.html"><code>&lt;zip&gt;</code></a></li>
  190. <li><a href="OptionalTasks/ejb.html#ddcreator"><code>&lt;ddcreator&gt;</code></a></li>
  191. <li><a href="OptionalTasks/ejb.html#ejbjar"><code>&lt;ejbjar&gt;</code></a></li>
  192. <li><a href="OptionalTasks/ejb.html#ejbc"><code>&lt;ejbc&gt;</code></a></li>
  193. <li><a href="OptionalTasks/cab.html"><code>&lt;cab&gt;</code></a></li>
  194. <li><a href="OptionalTasks/native2ascii.html"><code>&lt;native2ascii&gt;</code></a></li>
  195. <li><a href="OptionalTasks/netrexxc.html"><code>&lt;netrexxc&gt;</code></a></li>
  196. <li>
  197. <a href="OptionalTasks/renameextensions.html"><code>&lt;renameextensions&gt;</code></a>
  198. </li>
  199. <li><a href="OptionalTasks/depend.html"><code>&lt;depend&gt;</code></a></li>
  200. <li><a href="OptionalTasks/dotnet.html"><code>&lt;ilasm&gt;</code></a></li>
  201. <li><a href="OptionalTasks/dotnet.html"><code>&lt;csc&gt;</code></a></li>
  202. <li><a href="OptionalTasks/dotnet.html"><code>&lt;vbc&gt;</code></a></li>
  203. <li><a href="OptionalTasks/translate.html"><code>&lt;translate&gt;</code></a></li>
  204. <li><a href="OptionalTasks/image.html"><code>&lt;image&gt;</code></a></li>
  205. <li><a href="OptionalTasks/jlink.html"><code>&lt;jlink&gt;</code></a> (deprecated)</li>
  206. <li><a href="OptionalTasks/jspc.html"><code>&lt;jspc&gt;</code></a></li>
  207. <li><a href="OptionalTasks/wljspc.html"><code>&lt;wljspc&gt;</code></a></li>
  208. </ul>
  209. <h3><a name="examples">Examples</a></h3>
  210. <pre>
  211. &lt;copy todir=&quot;${dist}&quot;&gt;
  212. &lt;fileset dir=&quot;${src}&quot;
  213. includes=&quot;**/images/*&quot;
  214. excludes=&quot;**/*.gif&quot;
  215. /&gt;
  216. &lt;/copy&gt;</pre>
  217. <p>This copies all files in directories called <code>images</code> that are
  218. located in the directory tree defined by <code>${src}</code> to the
  219. destination directory defined by <code>${dist}</code>,
  220. but excludes all <code>*.gif</code> files from the copy.</p>
  221. <pre>
  222. &lt;copy todir=&quot;${dist}&quot;&gt;
  223. &lt;fileset dir=&quot;${src}&quot;&gt;
  224. &lt;include name=&quot;**/images/*&quot;/&gt;
  225. &lt;exclude name=&quot;**/*.gif&quot;/&gt;
  226. &lt;/fileset&gt;
  227. &lt;/copy&gt;
  228. </pre>
  229. <p> The same as the example above, but expressed using nested elements.</p>
  230. <pre>
  231. &lt;delete dir=&quot;${dist}&quot;&gt;
  232. &lt;include name=&quot;**/images/*&quot;/&gt;
  233. &lt;exclude name=&quot;**/*.gif&quot;/&gt;
  234. &lt;/delete&gt;
  235. </pre>
  236. <p>Deleting the original set of files, the <code>delete</code> task can act
  237. as an implicit fileset.</p>
  238. <h3><a name="defaultexcludes">Default Excludes</a></h3>
  239. <p>There are a set of definitions that are excluded by default from all
  240. directory-based tasks. They are:</p>
  241. <pre>
  242. **/*~
  243. **/#*#
  244. **/.#*
  245. **/%*%
  246. **/._*
  247. **/CVS
  248. **/CVS/**
  249. **/.cvsignore
  250. **/SCCS
  251. **/SCCS/**
  252. **/vssver.scc
  253. **/.svn
  254. **/.svn/**
  255. **/.DS_Store
  256. </pre>
  257. <p>If you do not want these default excludes applied, you may disable
  258. them with the <code>defaultexcludes=&quot;no&quot;</code>
  259. attribute.</p>
  260. <p>This is the default list, note that you can modify the list of
  261. default excludes by using the <a
  262. href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
  263. <hr>
  264. <p align="center">Copyright &copy; 2000-2006 The Apache Software Foundation. All
  265. rights Reserved.</p>
  266. </body>
  267. </html>