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

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