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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="stylesheets/style.css">
  19. <title>Directory-based Tasks</title>
  20. </head>
  21. <body>
  22. <h2><a name="directorybasedtasks">Directory-based Tasks</a></h2>
  23. <p>Some tasks use directory trees for the actions they perform.
  24. For example, the <a href="CoreTasks/javac.html">javac</a> task, which
  25. compiles a directory tree with <code>.java</code> files into
  26. <code>.class</code> files, is one of these directory-based tasks. Because
  27. some of these tasks do so much work with a directory tree, the task itself
  28. can act as an implicit <a href="CoreTypes/fileset.html">FileSet</a>.</p>
  29. <p>Whether the fileset is implicit or not, it can often be very useful to
  30. work on a subset of the directory tree. This section describes how you can
  31. select a subset of such a directory tree when using one of these
  32. directory-based tasks.</p>
  33. <p>Ant gives you two ways to create a subset of files in a fileset, both of
  34. which can be used at the same time:</p>
  35. <ul>
  36. <li>Only include files and directories that match any
  37. <code>include</code> patterns and do not match any
  38. <code>exclude</code> patterns in a given
  39. <a href="CoreTypes/patternset.html">PatternSet</a>.</li>
  40. <li>Select files based on selection criteria defined by a collection of
  41. <a href="CoreTypes/selectors.html">selector</a> nested elements.</li>
  42. </ul>
  43. <h3><a name="patternset">Patternset</a></h3>
  44. <p>We said that Directory-based tasks can sometimes act as an implicit
  45. <a href="CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a>,
  46. but in addition to that, a FileSet acts as an implicit
  47. <a href="CoreTypes/patternset.html"><code>&lt;patternset&gt;</code></a>.</p>
  48. <p>The inclusion and exclusion elements of the implicit PatternSet can be
  49. specified inside the directory-based task (or explicit fileset) via
  50. either:</p>
  51. <ul>
  52. <li>the attributes <code>includes</code> and
  53. <code>excludes</code>.</li>
  54. <li>nested elements <code>&lt;include&gt;</code> and
  55. <code>&lt;exclude&gt;</code>.</li>
  56. <li>external files specified with the attributes
  57. <code>includesfile</code> and <code>excludesfile</code>.</li>
  58. <li>external files specified with the nested elements
  59. <code>&lt;includesfile&gt;</code> and <code>&lt;excludesfile&gt;</code>.
  60. </li>
  61. </ul>
  62. <p>
  63. When dealing with an external file, each line of the file
  64. is taken as a pattern that is added to the list of include or exclude
  65. patterns.</p>
  66. <p>When both inclusion and exclusion are used, only files/directories that
  67. match at least one of the include patterns and don't match any of the
  68. exclude patterns are used. If no include pattern is given, all files
  69. are assumed to match the include pattern (with the possible exception of
  70. the default excludes).</p>
  71. <h4><a name="patterns">Patterns</a></h4>
  72. <p>As described earlier, patterns are used for the inclusion and exclusion
  73. of files. These patterns look very much like the patterns used in DOS and
  74. UNIX:</p>
  75. <p>'*' matches zero or more characters, '?' matches one character.</p>
  76. <p>In general, patterns are considered relative paths, relative to a
  77. task dependent base directory (the dir attribute in the case of
  78. <code>&lt;fileset&gt;</code>). Only files found below that base
  79. directory are considered. So while a pattern like
  80. <code>../foo.java</code> is possible, it will not match anything when
  81. applied since the base directory's parent is never scanned for
  82. files.</p>
  83. <p><b>Examples:</b></p>
  84. <p>
  85. <code>*.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>.java</code>,
  86. <code>x.java</code> and <code>FooBar.java</code>, but
  87. not <code>FooBar.xml</code> (does not end with <code>.java</code>).</p>
  88. <p>
  89. <code>?.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>x.java</code>,
  90. <code>A.java</code>, but not <code>.java</code> or <code>xyz.java</code>
  91. (both don't have one character before <code>.java</code>).</p>
  92. <p>
  93. Combinations of <code>*</code>'s and <code>?</code>'s are allowed.</p>
  94. <p>Matching is done per-directory. This means that first the first directory in
  95. the pattern is matched against the first directory in the path to match. Then
  96. the second directory is matched, and so on. For example, when we have the pattern
  97. <code>/?abc/*/*.java</code>
  98. and the path <code>/xabc/foobar/test.java</code>,
  99. the first <code>?abc</code> is matched with <code>xabc</code>,
  100. then <code>*</code> is matched with <code>foobar</code>,
  101. and finally <code>*.java</code> is matched with <code>test.java</code>.
  102. They all match, so the path matches the pattern.</p>
  103. <p>To make things a bit more flexible, we add one extra feature, which makes it
  104. possible to match multiple directory levels. This can be used to match a
  105. complete directory tree, or a file anywhere in the directory tree.
  106. To do this, <code>**</code>
  107. must be used as the name of a directory.
  108. When <code>**</code> is used as the name of a
  109. directory in the pattern, it matches zero or more directories.
  110. For example:
  111. <code>/test/**</code> matches all files/directories under <code>/test/</code>,
  112. such as <code>/test/x.java</code>,
  113. or <code>/test/foo/bar/xyz.html</code>, but not <code>/xyz.xml</code>.</p>
  114. <p>There is one &quot;shorthand&quot;: if a pattern ends
  115. with <code>/</code>
  116. or <code>\</code>, then <code>**</code>
  117. is appended.
  118. For example, <code>mypackage/test/</code> is interpreted as if it were
  119. <code>mypackage/test/**</code>.</p>
  120. <p><b>Example patterns:</b></p>
  121. <table border="1" cellpadding="2" cellspacing="0">
  122. <tr>
  123. <td valign="top"><code>**/CVS/*</code></td>
  124. <td valign="top">Matches all files in <code>CVS</code>
  125. directories that can be located
  126. anywhere in the directory tree.<br>
  127. Matches:
  128. <pre>
  129. CVS/Repository
  130. org/apache/CVS/Entries
  131. org/apache/jakarta/tools/ant/CVS/Entries
  132. </pre>
  133. But not:
  134. <pre>
  135. org/apache/CVS/foo/bar/Entries (<code>foo/bar/</code>
  136. part does not match)
  137. </pre>
  138. </td>
  139. </tr>
  140. <tr>
  141. <td valign="top"><code>org/apache/jakarta/**</code></td>
  142. <td valign="top">Matches all files in the <code>org/apache/jakarta</code>
  143. directory tree.<br>
  144. Matches:
  145. <pre>
  146. org/apache/jakarta/tools/ant/docs/index.html
  147. org/apache/jakarta/test.xml
  148. </pre>
  149. But not:
  150. <pre>
  151. org/apache/xyz.java
  152. </pre>
  153. (<code>jakarta/</code> part is missing).</td>
  154. </tr>
  155. <tr>
  156. <td valign="top"><code>org/apache/**/CVS/*</code></td>
  157. <td valign="top">Matches all files in <code>CVS</code> directories
  158. that are located anywhere in the directory tree under
  159. <code>org/apache</code>.<br>
  160. Matches:
  161. <pre>
  162. org/apache/CVS/Entries
  163. org/apache/jakarta/tools/ant/CVS/Entries
  164. </pre>
  165. But not:
  166. <pre>
  167. org/apache/CVS/foo/bar/Entries
  168. </pre>
  169. (<code>foo/bar/</code> part does not match)</td>
  170. </tr>
  171. <tr>
  172. <td valign="top"><code>**/test/**</code></td>
  173. <td valign="top">Matches all files that have a <code>test</code>
  174. element in their path, including <code>test</code> as a filename.</td>
  175. </tr>
  176. </table>
  177. <p>When these patterns are used in inclusion and exclusion, you have a powerful
  178. way to select just the files you want.</p>
  179. <h3><a name="selectors">Selectors</a></h3>
  180. <p>The <a href="CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a>,
  181. whether implicit or explicit in the
  182. directory-based task, also acts as an
  183. <a href="CoreTypes/selectors.html#andselect"><code>&lt;and&gt;</code></a>
  184. selector container. This can be used to create arbitrarily complicated
  185. selection criteria for the files the task should work with. See the
  186. <a href="CoreTypes/selectors.html">Selector</a> documentation for more
  187. information.</p>
  188. <h3><a name="tasklist">Standard Tasks/Filesets</a></h3>
  189. <p>Many of the standard tasks in ant take one or more filesets which follow
  190. the rules given here. This list, a subset of those, is a list of standard ant
  191. tasks that can act as an implicit fileset:</p>
  192. <ul>
  193. <li><a href="CoreTasks/checksum.html"><code>&lt;checksum&gt;</code></a></li>
  194. <li><a href="CoreTasks/copydir.html"><code>&lt;copydir&gt;</code></a> (deprecated)</li>
  195. <li><a href="CoreTasks/delete.html"><code>&lt;delete&gt;</code></a></li>
  196. <li><a href="CoreTasks/dependset.html"><code>&lt;dependset&gt;</code></a></li>
  197. <li><a href="CoreTasks/fixcrlf.html"><code>&lt;fixcrlf&gt;</code></a></li>
  198. <li><a href="CoreTasks/javac.html"><code>&lt;javac&gt;</code></a></li>
  199. <li><a href="CoreTasks/replace.html"><code>&lt;replace&gt;</code></a></li>
  200. <li><a href="CoreTasks/rmic.html"><code>&lt;rmic&gt;</code></a></li>
  201. <li><a href="CoreTasks/style.html"><code>&lt;style&gt;</code> (aka <code>&lt;xslt&gt;</code>)</a></li>
  202. <li><a href="CoreTasks/tar.html"><code>&lt;tar&gt;</code></a></li>
  203. <li><a href="CoreTasks/zip.html"><code>&lt;zip&gt;</code></a></li>
  204. <li><a href="OptionalTasks/ejb.html#ddcreator"><code>&lt;ddcreator&gt;</code></a></li>
  205. <li><a href="OptionalTasks/ejb.html#ejbjar"><code>&lt;ejbjar&gt;</code></a></li>
  206. <li><a href="OptionalTasks/ejb.html#ejbc"><code>&lt;ejbc&gt;</code></a></li>
  207. <li><a href="OptionalTasks/cab.html"><code>&lt;cab&gt;</code></a></li>
  208. <li><a href="OptionalTasks/native2ascii.html"><code>&lt;native2ascii&gt;</code></a></li>
  209. <li><a href="OptionalTasks/netrexxc.html"><code>&lt;netrexxc&gt;</code></a></li>
  210. <li>
  211. <a href="OptionalTasks/renameextensions.html"><code>&lt;renameextensions&gt;</code></a>
  212. </li>
  213. <li><a href="OptionalTasks/depend.html"><code>&lt;depend&gt;</code></a></li>
  214. <li><a href="OptionalTasks/dotnet.html"><code>&lt;ilasm&gt;</code></a></li>
  215. <li><a href="OptionalTasks/dotnet.html"><code>&lt;csc&gt;</code></a></li>
  216. <li><a href="OptionalTasks/dotnet.html"><code>&lt;vbc&gt;</code></a></li>
  217. <li><a href="OptionalTasks/translate.html"><code>&lt;translate&gt;</code></a></li>
  218. <li><a href="OptionalTasks/image.html"><code>&lt;image&gt;</code></a></li>
  219. <li><a href="OptionalTasks/jlink.html"><code>&lt;jlink&gt;</code></a> (deprecated)</li>
  220. <li><a href="OptionalTasks/jspc.html"><code>&lt;jspc&gt;</code></a></li>
  221. <li><a href="OptionalTasks/wljspc.html"><code>&lt;wljspc&gt;</code></a></li>
  222. </ul>
  223. <h3><a name="examples">Examples</a></h3>
  224. <pre>
  225. &lt;copy todir=&quot;${dist}&quot;&gt;
  226. &lt;fileset dir=&quot;${src}&quot;
  227. includes=&quot;**/images/*&quot;
  228. excludes=&quot;**/*.gif&quot;
  229. /&gt;
  230. &lt;/copy&gt;</pre>
  231. <p>This copies all files in directories called <code>images</code> that are
  232. located in the directory tree defined by <code>${src}</code> to the
  233. destination directory defined by <code>${dist}</code>,
  234. but excludes all <code>*.gif</code> files from the copy.</p>
  235. <pre>
  236. &lt;copy todir=&quot;${dist}&quot;&gt;
  237. &lt;fileset dir=&quot;${src}&quot;&gt;
  238. &lt;include name=&quot;**/images/*&quot;/&gt;
  239. &lt;exclude name=&quot;**/*.gif&quot;/&gt;
  240. &lt;/fileset&gt;
  241. &lt;/copy&gt;
  242. </pre>
  243. <p> The same as the example above, but expressed using nested elements.</p>
  244. <pre>
  245. &lt;delete dir=&quot;${dist}&quot;&gt;
  246. &lt;include name=&quot;**/images/*&quot;/&gt;
  247. &lt;exclude name=&quot;**/*.gif&quot;/&gt;
  248. &lt;/delete&gt;
  249. </pre>
  250. <p>Deleting the original set of files, the <code>delete</code> task can act
  251. as an implicit fileset.</p>
  252. <h3><a name="defaultexcludes">Default Excludes</a></h3>
  253. <p>There are a set of definitions that are excluded by default from all
  254. directory-based tasks. They are:</p>
  255. <pre>
  256. **/*~
  257. **/#*#
  258. **/.#*
  259. **/%*%
  260. **/._*
  261. **/CVS
  262. **/CVS/**
  263. **/.cvsignore
  264. **/SCCS
  265. **/SCCS/**
  266. **/vssver.scc
  267. **/.svn
  268. **/.svn/**
  269. **/.DS_Store
  270. </pre>
  271. <p>If you do not want these default excludes applied, you may disable
  272. them with the <code>defaultexcludes=&quot;no&quot;</code>
  273. attribute.</p>
  274. <p>This is the default list; note that you can modify the list of
  275. default excludes by using the <a
  276. href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
  277. </body>
  278. </html>