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

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