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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apache Ant User Manual</title>
  5. </head>
  6. <body>
  7. <h2><a name="directorybasedtasks">Directory-based Tasks</a></h2>
  8. <p>Some tasks use directory trees for the task they perform.
  9. For example, the <a
  10. href="CoreTasks/javac.html">javac</a> task, which works upon a directory tree
  11. with <code>.java</code> files.
  12. Sometimes it can be very useful to work on a subset of that directory tree. This
  13. section describes how you can select a subset of such a directory tree.</p>
  14. <p>Ant gives you two ways to create a subset, both of which can be used at the same
  15. time:</p>
  16. <ul>
  17. <li>Only include files/directories that match at least one pattern of a set of
  18. patterns.</li>
  19. <li>Exclude files/directories that match at least one pattern a set of
  20. patterns.</li>
  21. </ul>
  22. <p>When both inclusion and exclusion are used, only files/directories that match
  23. the include patterns, and don't match the exclude patterns, are used.</p>
  24. <p>Patterns can be specified inside the buildfile via task attributes or
  25. nested elements and via external files. Each line of the external file
  26. is taken as a pattern that is added to the list of include or exclude
  27. patterns.</p>
  28. <h3><a name="patterns">Patterns</a></h3>
  29. <p>As described earlier, patterns are used for the inclusion and exclusion.
  30. These patterns look very much like the patterns used in DOS and UNIX:</p>
  31. <p>'*' matches zero or more characters, '?' matches one character.</p>
  32. <p><b>Examples:</b></p>
  33. <p>
  34. <code>*.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>.java</code>,
  35. <code>x.java</code> and <code>FooBar.java</code>, but
  36. not <code>FooBar.xml</code> (does not end with <code>.java</code>).</p>
  37. <p>
  38. <code>?.java</code>&nbsp;&nbsp;matches&nbsp;&nbsp;<code>x.java</code>,
  39. <code>A.java</code>, but not <code>.java</code> or <code>xyz.java</code>
  40. (both don't have one character before <code>.java</code>).</p>
  41. <p>
  42. Combinations of <code>*</code>'s and <code>?</code>'s are allowed.</p>
  43. <p>Matching is done per-directory. This means that first the first directory in
  44. the pattern is matched against the first directory in the path to match. Then
  45. the second directory is matched, and so on. For example, when we have the pattern <code>/?abc/*/*.java</code>
  46. and the path <code>/xabc/foobar/test.java</code>,
  47. the first <code>?abc</code> is matched with <code>xabc</code>,
  48. then <code>*</code> is matched with <code>foobar</code>,
  49. and finally <code>*.java</code> is matched with <code>test.java</code>.
  50. They all match, so the path matches the pattern.</p>
  51. <p>To make things a bit more flexible, we add one extra feature, which makes it
  52. possible to match multiple directory levels. This can be used to match a
  53. complete directory tree, or a file anywhere in the directory tree.
  54. To do this, <code>**</code>
  55. must be used as the name of a directory.
  56. When <code>**</code> is used as the name of a
  57. directory in the pattern, it matches zero or more directories.
  58. For example:
  59. <code>/test/**</code> matches all files/directories under <code>/test/</code>,
  60. such as <code>/test/x.java</code>,
  61. or <code>/test/foo/bar/xyz.html</code>, but not <code>/xyz.xml</code>.</p>
  62. <p>There is one &quot;shorthand&quot; - if a pattern ends
  63. with <code>/</code>
  64. or <code>\</code>, then <code>**</code>
  65. is appended.
  66. For example, <code>mypackage/test/</code> is interpreted as if it were
  67. <code>mypackage/test/**</code>.</p>
  68. <p><b>Example patterns:</b></p>
  69. <table border="1" cellpadding="2" cellspacing="0">
  70. <tr>
  71. <td valign="top"><code>**/CVS/*</code></td>
  72. <td valign="top">Matches all files in <code>CVS</code> directories that can be located
  73. anywhere in the directory tree.<br>
  74. Matches:
  75. <pre>
  76. CVS/Repository
  77. org/apache/CVS/Entries
  78. org/apache/jakarta/tools/ant/CVS/Entries
  79. </pre>
  80. But not:
  81. <pre>
  82. org/apache/CVS/foo/bar/Entries (<code>foo/bar/</code> part does not match)</td>
  83. </pre>
  84. </tr>
  85. <tr>
  86. <td valign="top"><code>org/apache/jakarta/**</code></td>
  87. <td valign="top">Matches all files in the <code>org/apache/jakarta</code> directory tree.<br>
  88. Matches:
  89. <pre>
  90. org/apache/jakarta/tools/ant/docs/index.html
  91. org/apache/jakarta/test.xml
  92. </pre>
  93. But not:
  94. <pre>
  95. org/apache/xyz.java
  96. </pre>
  97. (<code>jakarta/</code> part is missing).</td>
  98. </tr>
  99. <tr>
  100. <td valign="top"><code>org/apache/**/CVS/*</code></td>
  101. <td valign="top">Matches all files in <code>CVS</code> directories
  102. that are located anywhere in the directory tree under
  103. <code>org/apache</code>.<br>
  104. Matches:
  105. <pre>
  106. org/apache/CVS/Entries
  107. org/apache/jakarta/tools/ant/CVS/Entries
  108. </pre>
  109. But not:
  110. <pre>
  111. org/apache/CVS/foo/bar/Entries
  112. </pre>
  113. (<code>foo/bar/</code> part does not match)</td>
  114. </tr>
  115. <tr>
  116. <td valign="top"><code>**/test/**</code></td>
  117. <td valign="top">Matches all files that have a <code>test</code>
  118. element in their path, including <code>test</code> as a filename.</td>
  119. </tr>
  120. </table>
  121. <p>When these patterns are used in inclusion and exclusion, you have a powerful
  122. way to select just the files you want.</p>
  123. <h3>Examples</h3>
  124. <pre>
  125. &lt;copy todir=&quot;${dist}&quot;&gt;
  126. &lt;fileset dir=&quot;${src}&quot;
  127. includes=&quot;**/images/*&quot;
  128. excludes=&quot;**/*.gif&quot;
  129. /&gt;
  130. &lt;/copy&gt;</pre>
  131. <p>This copies all files in directories called <code>images</code> that are
  132. located in the directory tree defined by <code>${src}</code> to the
  133. destination directory defined by <code>${dist}</code>,
  134. but excludes all <code>*.gif</code> files from the copy.</p>
  135. <p> This example can also be expressed using nested elements:</p>
  136. <pre>
  137. &lt;copy todir=&quot;${dist}&quot;&gt;
  138. &lt;fileset dir=&quot;${src}&quot;&gt;
  139. &lt;include name=&quot;**/images/*&quot;/&gt;
  140. &lt;exclude name=&quot;**/*.gif&quot;/&gt;
  141. &lt;/fileset&gt;
  142. &lt;/copy&gt;
  143. </pre>
  144. <h3>Default Excludes</h3>
  145. <p>There are a set of definitions that are excluded by default from all directory-based tasks.
  146. They are:</p>
  147. <pre>
  148. **/*~
  149. **/#*#
  150. **/.#*
  151. **/%*%
  152. **/CVS
  153. **/CVS/**
  154. **/.cvsignore
  155. **/SCCS
  156. **/SCCS/**
  157. **/vssver.scc
  158. </pre>
  159. <p>If you do not want these default excludes applied, you may disable them with the
  160. <code>defaultexcludes=&quot;no&quot;</code> attribute.</p>
  161. <hr>
  162. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  163. Reserved.</p>
  164. </body>
  165. </html>