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.

concat.html 9.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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>Concat</title>
  20. </head>
  21. <body>
  22. <h2 id="concat">Concat</h2>
  23. <h3>Description</h3>
  24. <p>Concatenates one or more <a href="../Types/resources.html">resource</a>s to a single file or
  25. to the console. The destination file will be created if it does not exist unless the resource
  26. list is empty and <var>ignoreempty</var> is <q>true</q>.</p>
  27. <p><em>Since Apache Ant 1.7.1</em>, this task can be used as
  28. a <a href="../Types/resources.html#collection">resource collection</a> that will return
  29. exactly one <a href="../Types/resources.html">resource</a>.</p>
  30. <p><a href="../Types/resources.html#collection">Resource collections</a> are used to select
  31. which resources are to be concatenated. There is no singular attribute to specify a single
  32. resource to <code>concat</code>.</p>
  33. <h3>Parameters</h3>
  34. <table class="attr">
  35. <tr>
  36. <th>Attribute</th>
  37. <th>Description</th>
  38. <th>Required</th>
  39. </tr>
  40. <tr>
  41. <td>destfile</td>
  42. <td>The destination file for the concatenated stream. If not specified the console will be
  43. used instead.</td>
  44. <td>No</td>
  45. </tr>
  46. <tr>
  47. <td>append</td>
  48. <td>Specifies whether or not the file specified by <var>destfile</var> should be
  49. appended.</td>
  50. <td>No; defaults to <q>no</q></td>
  51. </tr>
  52. <tr>
  53. <td>force</td>
  54. <td>Specifies whether or not the file specified by <var>destfile</var> should be written to
  55. even if it is newer than all source files. <em><u>Deprecated</u>, use
  56. the <var>overwrite</var> attribute instead.</em></td>
  57. <td>No; defaults to <q>yes</q></td>
  58. </tr>
  59. <tr>
  60. <td>overwrite</td>
  61. <td>Specifies whether or not the file specified by <var>destfile</var> should be written to
  62. even if it is newer than all source files. <em>Since Ant 1.8.2</em>.</td>
  63. <td>No; defaults to <q>yes</q></td>
  64. </tr>
  65. <tr>
  66. <td>forceReadOnly</td>
  67. <td>Overwrite read-only destination files. <em>Since Ant 1.8.2</em></td>
  68. <td>No; defaults to <q>false</q></td>
  69. </tr>
  70. <tr>
  71. <td>encoding</td>
  72. <td>Specifies the encoding for the input files. Please
  73. see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html"
  74. target="_top">Supported Encodings</a> for a list of possible values.</td>
  75. <td>No; defaults to default JVM character encoding</td>
  76. </tr>
  77. <tr>
  78. <td>outputencoding</td>
  79. <td>The encoding to use when writing the output file. <em>Since Ant 1.6</em>.</td>
  80. <td>No; defaults to <var>encoding</var> if set or default JVM character encoding
  81. otherwise</td>
  82. </tr>
  83. <tr>
  84. <td>fixlastline</td>
  85. <td>Specifies whether or not to check if each file concatenated is terminated by a new
  86. line. If this attribute is <q>yes</q> a new line will be appended to the stream if the
  87. file did not end in a new line. <em>Since Ant 1.6</em>. This attribute does not apply to
  88. embedded text.</td>
  89. <td>No; defaults to <q>no</q></td>
  90. </tr>
  91. <tr>
  92. <td>eol</td>
  93. <td>Specifies what the end of line character are for use by the fixlastline
  94. attribute. <em>Since Ant 1.6</em> Valid values for this property are:
  95. <ul>
  96. <li><q>cr</q>: a single CR</li>
  97. <li><q>lf</q>: a single LF</li>
  98. <li><q>crlf</q>: the pair CRLF</li>
  99. <li><q>mac</q>: a single CR</li>
  100. <li><q>unix</q>: a single LF</li>
  101. <li><q>dos</q>: the pair CRLF</li>
  102. </ul></td>
  103. <td>No; default is platform dependent: <q>lf</q> for Unix, <q>crlf</q> for DOS family
  104. (including Windows), <q>cr</q> for Mac OS 9 or earlier</td></tr>
  105. <tr>
  106. <td>binary</td>
  107. <td><em>Since Ant 1.6.2</em> If this attribute is set to <q>true</q>, the task concatenates
  108. the files in a byte by byte fashion. If this attribute is <q>false</q>, concat will not
  109. normally work for binary files due to character encoding issues. If this option is set
  110. to <q>true</q>, the <var>destfile</var> attribute must be set, and the task cannot used
  111. nested text. Also the
  112. attributes <var>encoding</var>, <var>outputencoding</var>, <var>filelastline</var> cannot
  113. be used.</td>
  114. <td>No; default is <q>false</q></td>
  115. </tr>
  116. <tr>
  117. <td>ignoreempty</td>
  118. <td><em>Since Ant 1.8.0</em> Specifies whether or not the file specified
  119. by <var>destfile</var> should be created if the source resource list is empty.
  120. </td>
  121. <td>No; defaults to <q>true</q></td>
  122. </tr>
  123. <tr>
  124. <td>resourcename</td>
  125. <td><em>Since Ant 1.8.3</em> Specifies the name reported if this task is exposed as
  126. a <a href="../Types/resources.html">resource</a>.
  127. </td>
  128. <td>No</td>
  129. </tr>
  130. </table>
  131. <h3>Parameters specified as nested elements</h3>
  132. <h4>resource collection</h4>
  133. <p><em>Since Ant 1.7</em>.</p>
  134. <p>Any of the various <a href="../Types/resources.html#collection">resource collection</a> types
  135. can specify the resources to be concatenated.</p>
  136. <h4>filterchain</h4>
  137. <p><em>Since Ant 1.6</em>.</p>
  138. <p>The task supports nested <a href="../Types/filterchain.html">FilterChain</a>s.</p>
  139. <h4>header, footer</h4>
  140. <p><em>Since Ant 1.6</em>.</p>
  141. <p>Used to prepend or postpend text into the concatenated stream.</p>
  142. <p>The text may be in-line or be in a file.</p>
  143. <table class="attr">
  144. <tr>
  145. <th>Attribute</th>
  146. <th>Description</th>
  147. <th>Required</th>
  148. </tr>
  149. <tr>
  150. <td>filtering</td>
  151. <td>Whether to filter the text provided by this sub element.</td>
  152. <td>No; default is <q>yes</q></td>
  153. </tr>
  154. <tr>
  155. <td>file</td>
  156. <td>A file to place at the head or tail of the concatenated text.</td>
  157. <td>No</td>
  158. </tr>
  159. <tr>
  160. <td>trim</td>
  161. <td>Whether to trim the value.</td>
  162. <td>No; default is <q>no</q></td>
  163. </tr>
  164. <tr>
  165. <td>trimleading</td>
  166. <td>Whether to trim leading white space on each line.</td>
  167. <td>No; default is <q>no</q></td>
  168. </tr>
  169. </table>
  170. <h3>Examples</h3>
  171. <p><strong>Concatenate a string to a file:</strong></p>
  172. <pre>&lt;concat destfile=&quot;README&quot;&gt;Hello, World!&lt;/concat&gt;</pre>
  173. <p><strong>Concatenate a series of files to the console:</strong></p>
  174. <pre>
  175. &lt;concat&gt;
  176. &lt;fileset dir=&quot;messages&quot; includes=&quot;*important*&quot;/&gt;
  177. &lt;/concat&gt;</pre>
  178. <p><strong>Concatenate a single file, appending if the destination file exists:</strong></p>
  179. <pre>
  180. &lt;concat destfile=&quot;NOTES&quot; append=&quot;true&quot;&gt;
  181. &lt;filelist dir=&quot;notes&quot; files=&quot;note.txt&quot;/&gt;
  182. &lt;/concat&gt;</pre>
  183. <p><strong>Concatenate a series of files, update the destination file only if is older that all
  184. the source files:</strong></p>
  185. <pre>
  186. &lt;concat destfile=&quot;${docbook.dir}/all-sections.xml&quot;
  187. force=&quot;no&quot;&gt;
  188. &lt;filelist dir=&quot;${docbook.dir}/sections&quot;
  189. files=&quot;introduction.xml,overview.xml&quot;/&gt;
  190. &lt;fileset dir=&quot;${docbook.dir}&quot;
  191. includes=&quot;sections/*.xml&quot;
  192. excludes=&quot;introduction.xml,overview.xml&quot;/&gt;
  193. &lt;/concat&gt;</pre>
  194. <p><strong>Concatenate a series of files, expanding Ant properties</strong></p>
  195. <pre>
  196. &lt;concat destfile="${build.dir}/subs"&gt;
  197. &lt;path&gt;
  198. &lt;fileset dir="${src.dir}" includes="*.xml"/&gt;
  199. &lt;pathelement location="build.xml"/&gt;
  200. &lt;/path&gt;
  201. &lt;filterchain&gt;
  202. &lt;expandproperties/&gt;
  203. &lt;/filterchain&gt;
  204. &lt;/concat&gt;</pre>
  205. <p><strong>Filter the lines containing project from build.xml and output them to report.output,
  206. prepending with a header</strong></p>
  207. <pre>
  208. &lt;concat destfile="${build.dir}/report.output"&gt;
  209. &lt;header filtering="no" trimleading="yes"&gt;
  210. Lines that contain project
  211. ==========================
  212. &lt;/header&gt;
  213. &lt;path path="build.xml"/&gt;
  214. &lt;filterchain&gt;
  215. &lt;linecontains&gt;
  216. &lt;contains value="project"/&gt;
  217. &lt;/linecontains&gt;
  218. &lt;/filterchain&gt;
  219. &lt;/concat&gt;</pre>
  220. <p><strong>Concatenate a number of binary files.</strong></p>
  221. <pre>
  222. &lt;concat destfile="${build.dir}/dist.bin" binary="yes"&gt;
  223. &lt;fileset file="${src.dir}/scripts/dist.sh"/&gt;
  224. &lt;fileset file="${build.dir}/dist.tar.bz2"/&gt;
  225. &lt;/concat&gt;</pre>
  226. </body>
  227. </html>