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

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