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.

patternset.html 7.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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>PatternSet Type</title>
  20. </head>
  21. <body>
  22. <h2 id="patternset">PatternSet</h2>
  23. <p><a href="../dirtasks.html#patterns">Patterns</a> can be grouped to sets and later be
  24. referenced by their <var>id</var> attribute. They are defined via a <code>patternset</code>
  25. element, which can appear nested into a <a href="fileset.html">FileSet</a> or a directory-based
  26. task that constitutes an implicit FileSet. In addition, <code>patternset</code>s can be defined
  27. as a stand alone element at the same level as <code>target</code>&mdash;i.e., as children of
  28. <code>project</code> as well as as children of <code>target</code>.</p>
  29. <p>Patterns can be specified by nested <code>&lt;include&gt;</code>,
  30. or <code>&lt;exclude&gt;</code> elements or the following attributes.</p>
  31. <table class="attr">
  32. <tr>
  33. <th>Attribute</th>
  34. <th>Description</th>
  35. <th>Default</th>
  36. </tr>
  37. <tr>
  38. <td>includes</td>
  39. <td>comma- or space-separated list of patterns of files that must be included.</td>
  40. <td>All files are included.</td>
  41. </tr>
  42. <tr>
  43. <td>includesfile</td>
  44. <td>name of a file; each line of this file is taken to be an include pattern. You can
  45. specify more than one include file by using a nested <code>includesfile</code> elements.
  46. <strong>Note:</strong> if the file is empty and there are no other
  47. patterns defined for the fileset, all files will be included.
  48. </td>
  49. <td>See <var>includes</var></td>
  50. </tr>
  51. <tr>
  52. <td>excludes</td>
  53. <td>comma- or space-separated list of patterns of files that must be excluded.</td>
  54. <td>No files except default excludes are excluded.</td>
  55. </tr>
  56. <tr>
  57. <td>excludesfile</td>
  58. <td>name of a file; each line of this file is taken to be an exclude pattern. You can
  59. specify more than one exclude file by using a nested <code>excludesfile</code>
  60. elements.</td>
  61. <td>See <var>excludes</var></td>
  62. </tr>
  63. </table>
  64. <h3>Parameters specified as nested elements</h3>
  65. <h4><code>include</code> and <code>exclude</code></h4>
  66. <p>Each such element defines a single pattern for files to include or exclude.</p>
  67. <table class="attr">
  68. <tr>
  69. <th>Attribute</th>
  70. <th>Description</th>
  71. <th>Required</th>
  72. </tr>
  73. <tr>
  74. <td>name</td>
  75. <td>the <a href="../dirtasks.html#patterns">pattern</a> to in/exclude.</td>
  76. <td>Yes</td>
  77. </tr>
  78. <tr>
  79. <td>if</td>
  80. <td>Only use this pattern <a href="../properties.html#if+unless">if the named property is
  81. set</a>.</td>
  82. <td>No</td>
  83. </tr>
  84. <tr>
  85. <td>unless</td>
  86. <td>Only use this pattern <a href="../properties.html#if+unless">if the named property
  87. is <strong>not</strong> set</a>.</td>
  88. <td>No</td>
  89. </tr>
  90. </table>
  91. <h4><code>includesfile</code> and <code>excludesfile</code></h4>
  92. <p>If you want to list the files to include or exclude external to your build file, you should
  93. use the <var>includesfile</var>/<var>excludesfile</var> attributes or elements. Using the
  94. attribute, you can only specify a single file of each type, while the nested elements can be
  95. specified more than once&mdash;the nested elements also support <var>if</var>/<var>unless</var>
  96. attributes you can use to test the existence of a property.</p>
  97. <table class="attr">
  98. <tr>
  99. <th>Attribute</th>
  100. <th>Description</th>
  101. <th>Required</th>
  102. </tr>
  103. <tr>
  104. <td>name</td>
  105. <td>the name of the file holding the patterns to in/exclude.</td>
  106. <td>Yes</td>
  107. </tr>
  108. <tr>
  109. <td>if</td>
  110. <td>Only read this file <a href="../properties.html#if+unless">if the named property is
  111. set</a>.</td>
  112. <td>No</td>
  113. </tr>
  114. <tr>
  115. <td>unless</td>
  116. <td>Only read this file <a href="../properties.html#if+unless">if the named property
  117. is <strong>not</strong> set</a>.</td>
  118. <td>No</td>
  119. </tr>
  120. </table>
  121. <h4><code>patternset</code></h4>
  122. <p>Patternsets may be nested within one another, adding the nested patterns to the parent
  123. patternset.</p>
  124. <h4><code>invert</code></h4>
  125. <p><em>Since Apache Ant 1.7.1</em></p>
  126. <p>A nested patternset can be inverted using the <code>&lt;invert&gt;</code> element.</p>
  127. <h3>Examples</h3>
  128. <pre>
  129. &lt;patternset id=&quot;non.test.sources&quot;&gt;
  130. &lt;include name=&quot;**/*.java&quot;/&gt;
  131. &lt;exclude name=&quot;**/*Test*&quot;/&gt;
  132. &lt;/patternset&gt;
  133. </pre>
  134. <p>Builds a set of patterns that matches all <samp>.java</samp> files that do not contain the
  135. text <samp>Test</samp> in their name. This set can
  136. be <a href="../using.html#references">referred</a> to via <code>&lt;patternset
  137. refid=&quot;non.test.sources&quot;/&gt;</code>, by tasks that support this feature, or by
  138. FileSets.</p>
  139. <p>Note that while the <var>includes</var> and <var>excludes</var> attributes accept multiple
  140. elements separated by commas or spaces, the nested <code>&lt;include&gt;</code>
  141. and <code>&lt;exclude&gt;</code> elements expect their name attribute to hold a single
  142. pattern.</p>
  143. <p>The nested elements allow you to use <var>if</var> and <var>unless</var> attributes to
  144. specify that the element should only be used if a property is set, or that it should be used
  145. only if a property is not set.</p>
  146. <p>For example</p>
  147. <pre>
  148. &lt;patternset id=&quot;sources&quot;&gt;
  149. &lt;include name=&quot;std/**/*.java&quot;/&gt;
  150. &lt;include name=&quot;prof/**/*.java&quot; if=&quot;professional&quot;/&gt;
  151. &lt;exclude name=&quot;**/*Test*&quot;/&gt;
  152. &lt;/patternset&gt;
  153. </pre>
  154. <p>will only include the files in the sub-directory <samp>prof</samp> if the
  155. property <code>professional</code> is set to some value.</p>
  156. <p>The two sets</p>
  157. <pre>
  158. &lt;patternset includesfile=&quot;some-file&quot;/&gt;
  159. </pre>
  160. <p>and</p>
  161. <pre>
  162. &lt;patternset&gt;
  163. &lt;includesfile name=&quot;some-file&quot;/&gt;
  164. &lt;patternset/&gt;
  165. </pre>
  166. <p>are identical. The include patterns will be read from the file <samp>some-file</samp>, one
  167. pattern per line.</p>
  168. <pre>
  169. &lt;patternset&gt;
  170. &lt;includesfile name=&quot;some-file&quot;/&gt;
  171. &lt;includesfile name=&quot;${some-other-file}&quot;
  172. if=&quot;some-other-file&quot;/&gt;
  173. &lt;patternset/&gt;
  174. </pre>
  175. <p>will also read include patterns from the file the property <code>some-other-file</code>
  176. points to, if a property of that name has been defined.</p>
  177. </body>
  178. </html>