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 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 addtion 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><b>Examples:</b></p>
  61. <p>
  62. <code>*.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>.java</code>,
  63. <code>x.java</code> and <code>FooBar.java</code>, but
  64. not <code>FooBar.xml</code> (does not end with <code>.java</code>).</p>
  65. <p>
  66. <code>?.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>x.java</code>,
  67. <code>A.java</code>, but not <code>.java</code> or <code>xyz.java</code>
  68. (both don't have one character before <code>.java</code>).</p>
  69. <p>
  70. Combinations of <code>*</code>'s and <code>?</code>'s are allowed.</p>
  71. <p>Matching is done per-directory. This means that first the first directory in
  72. the pattern is matched against the first directory in the path to match. Then
  73. the second directory is matched, and so on. For example, when we have the pattern
  74. <code>/?abc/*/*.java</code>
  75. and the path <code>/xabc/foobar/test.java</code>,
  76. the first <code>?abc</code> is matched with <code>xabc</code>,
  77. then <code>*</code> is matched with <code>foobar</code>,
  78. and finally <code>*.java</code> is matched with <code>test.java</code>.
  79. They all match, so the path matches the pattern.</p>
  80. <p>To make things a bit more flexible, we add one extra feature, which makes it
  81. possible to match multiple directory levels. This can be used to match a
  82. complete directory tree, or a file anywhere in the directory tree.
  83. To do this, <code>**</code>
  84. must be used as the name of a directory.
  85. When <code>**</code> is used as the name of a
  86. directory in the pattern, it matches zero or more directories.
  87. For example:
  88. <code>/test/**</code> matches all files/directories under <code>/test/</code>,
  89. such as <code>/test/x.java</code>,
  90. or <code>/test/foo/bar/xyz.html</code>, but not <code>/xyz.xml</code>.</p>
  91. <p>There is one &quot;shorthand&quot; - if a pattern ends
  92. with <code>/</code>
  93. or <code>\</code>, then <code>**</code>
  94. is appended.
  95. For example, <code>mypackage/test/</code> is interpreted as if it were
  96. <code>mypackage/test/**</code>.</p>
  97. <p><b>Example patterns:</b></p>
  98. <table border="1" cellpadding="2" cellspacing="0">
  99. <tr>
  100. <td valign="top"><code>**/CVS/*</code></td>
  101. <td valign="top">Matches all files in <code>CVS</code>
  102. directories that can be located
  103. anywhere in the directory tree.<br>
  104. Matches:
  105. <pre>
  106. CVS/Repository
  107. org/apache/CVS/Entries
  108. org/apache/jakarta/tools/ant/CVS/Entries
  109. </pre>
  110. But not:
  111. <pre>
  112. org/apache/CVS/foo/bar/Entries (<code>foo/bar/</code>
  113. part does not match)</td>
  114. </pre>
  115. </tr>
  116. <tr>
  117. <td valign="top"><code>org/apache/jakarta/**</code></td>
  118. <td valign="top">Matches all files in the <code>org/apache/jakarta</code>
  119. directory tree.<br>
  120. Matches:
  121. <pre>
  122. org/apache/jakarta/tools/ant/docs/index.html
  123. org/apache/jakarta/test.xml
  124. </pre>
  125. But not:
  126. <pre>
  127. org/apache/xyz.java
  128. </pre>
  129. (<code>jakarta/</code> part is missing).</td>
  130. </tr>
  131. <tr>
  132. <td valign="top"><code>org/apache/**/CVS/*</code></td>
  133. <td valign="top">Matches all files in <code>CVS</code> directories
  134. that are located anywhere in the directory tree under
  135. <code>org/apache</code>.<br>
  136. Matches:
  137. <pre>
  138. org/apache/CVS/Entries
  139. org/apache/jakarta/tools/ant/CVS/Entries
  140. </pre>
  141. But not:
  142. <pre>
  143. org/apache/CVS/foo/bar/Entries
  144. </pre>
  145. (<code>foo/bar/</code> part does not match)</td>
  146. </tr>
  147. <tr>
  148. <td valign="top"><code>**/test/**</code></td>
  149. <td valign="top">Matches all files that have a <code>test</code>
  150. element in their path, including <code>test</code> as a filename.</td>
  151. </tr>
  152. </table>
  153. <p>When these patterns are used in inclusion and exclusion, you have a powerful
  154. way to select just the files you want.</p>
  155. <h3><a name="selectors">Selectors</a></h3>
  156. <p>The <a href="CoreTypes/fileset.html"><code>&lt;fileset&gt;</code></a>,
  157. whether implicit or explicit in the
  158. directory-based task, also acts as an
  159. <a href="CoreTypes/selectors.html#andselect"><code>&lt;and&gt;</code></a>
  160. selector container. This can be used to create arbitrarily complicated
  161. selection criteria for the files the task should work with. See the
  162. <a href="CoreTypes/selectors.html">Selector</a> documentation for more
  163. information.</p>
  164. <h3><a name="tasklist">Standard Tasks/Filesets</a></h3>
  165. <p>Many of the standard tasks in ant take one or more filesets which follow
  166. the rules given here. This list, a subset of those, is a list of standard ant
  167. tasks that can act as an implicit fileset:</p>
  168. <ul>
  169. <li><a href="CoreTasks/checksum.html">&lt;checksum&gt;</a></li>
  170. <li><a href="CoreTasks/copydir.html">&lt;copydir&gt;</a> (deprecated)</li>
  171. <li><a href="CoreTasks/delete.html">&lt;delete&gt;</a></li>
  172. <li><a href="CoreTasks/dependset.html">&lt;dependset&gt;</a></li>
  173. <li><a href="CoreTasks/fixcrlf.html">&lt;fixcrlf&gt;</a></li>
  174. <li><a href="CoreTasks/javac.html">&lt;javac&gt;</a></li>
  175. <li><a href="CoreTasks/replace.html">&lt;replace&gt;</a></li>
  176. <li><a href="CoreTasks/rmic.html">&lt;rmic&gt;</a></li>
  177. <li><a href="CoreTasks/style.html">&lt;style&gt; (aka &lt;xslt&gt;)</a></li>
  178. <li><a href="CoreTasks/tar.html">&lt;tar&gt;</a></li>
  179. <li><a href="CoreTasks/zip.html">&lt;zip&gt;</a></li>
  180. <li><a href="OptionalTasks/ejb.html#ddcreator">&lt;ddcreator&gt;</a></li>
  181. <li><a href="OptionalTasks/ejb.html#ejbjar.html">&lt;ejbjar&gt;</a></li>
  182. <li><a href="OptionalTasks/ejb.html#ejbc">&lt;ejbc&gt;</a></li>
  183. <li><a href="OptionalTasks/cab.html">&lt;cab&gt;</a></li>
  184. <li><a href="OptionalTasks/icontract.html">&lt;icontract&gt;</a></li>
  185. <li><a href="OptionalTasks/native2ascii.html">&lt;native2ascii&gt;</a></li>
  186. <li><a href="OptionalTasks/netrexxc.html">&lt;netrexxc&gt;</a></li>
  187. <li>
  188. <a href="OptionalTasks/renameextensions.html">&lt;renameextensions&gt;</a>
  189. </li>
  190. <li><a href="OptionalTasks/depend.html">&lt;depend&gt;</a></li>
  191. <li><a href="OptionalTasks/dotnet.html">&lt;ilasm&gt;</a></li>
  192. <li><a href="OptionalTasks/dotnet.html">&lt;csc&gt;</a></li>
  193. <li><a href="OptionalTasks/dotnet.html">&lt;vbc&gt;</a></li>
  194. <li><a href="OptionalTasks/translate.html">&lt;translate&gt;</a></li>
  195. <li>
  196. <a href="Integration/VAJAntTool.html#vajexport">&lt;vajexport&gt;</a>
  197. </li>
  198. <li>&lt;image&gt;</li>
  199. <li><a href="OptionalTasks/jlink.html">&lt;jlink&gt;</a> (deprecated)</li>
  200. <li><a href="OptionalTasks/jspc.html">&lt;jspc&gt;</a></li>
  201. <li><a href="OptionalTasks/wljspc.html">&lt;wljspc&gt;</a></li>
  202. </ul>
  203. <h3><a name="examples">Examples</a></h3>
  204. <pre>
  205. &lt;copy todir=&quot;${dist}&quot;&gt;
  206. &lt;fileset dir=&quot;${src}&quot;
  207. includes=&quot;**/images/*&quot;
  208. excludes=&quot;**/*.gif&quot;
  209. /&gt;
  210. &lt;/copy&gt;</pre>
  211. <p>This copies all files in directories called <code>images</code> that are
  212. located in the directory tree defined by <code>${src}</code> to the
  213. destination directory defined by <code>${dist}</code>,
  214. but excludes all <code>*.gif</code> files from the copy.</p>
  215. <pre>
  216. &lt;copy todir=&quot;${dist}&quot;&gt;
  217. &lt;fileset dir=&quot;${src}&quot;&gt;
  218. &lt;include name=&quot;**/images/*&quot;/&gt;
  219. &lt;exclude name=&quot;**/*.gif&quot;/&gt;
  220. &lt;/fileset&gt;
  221. &lt;/copy&gt;
  222. </pre>
  223. <p> The same as the example above, but expressed using nested elements.</p>
  224. <pre>
  225. &lt;delete dir=&quot;${dist}&quot;&gt;
  226. &lt;include name=&quot;**/images/*&quot;/&gt;
  227. &lt;exclude name=&quot;**/*.gif&quot;/&gt;
  228. &lt;/delete&gt;
  229. </pre>
  230. <p>Deleting the original set of files, the <code>delete</code> task can act
  231. as an implicit fileset.</p>
  232. <h3><a name="defaultexcludes">Default Excludes</a></h3>
  233. <p>There are a set of definitions that are excluded by default from all
  234. directory-based tasks. They are:</p>
  235. <pre>
  236. **/*~
  237. **/#*#
  238. **/.#*
  239. **/%*%
  240. **/._*
  241. **/CVS
  242. **/CVS/**
  243. **/.cvsignore
  244. **/SCCS
  245. **/SCCS/**
  246. **/vssver.scc
  247. **/.svn
  248. **/.svn/**
  249. **/.DS_Store
  250. </pre>
  251. <p>If you do not want these default excludes applied, you may disable
  252. them with the <code>defaultexcludes=&quot;no&quot;</code>
  253. attribute.</p>
  254. <p>This is the default list, note that you can modify the list of
  255. default excludes by using the <a
  256. href="CoreTasks/defaultexcludes.html">defaultexcludes</a> task.</p>
  257. <hr>
  258. <p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All
  259. rights Reserved.</p>
  260. </body>
  261. </html>