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

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