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.5 KiB

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