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.

fixcrlf.html 13 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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>FixCRLF Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="fixcrlf">FixCRLF</a></h2>
  23. <h3>Description</h3>
  24. <p>
  25. Adjusts a text file to local conventions.
  26. </p>
  27. <p>
  28. The set of files to be adjusted can be refined with the
  29. <i>includes</i>, <i>includesfile</i>, <i>excludes</i>,
  30. <i>excludesfile</i> and <i>defaultexcludes</i>
  31. attributes. Patterns provided through the <i>includes</i> or
  32. <i>includesfile</i> attributes specify files to be
  33. included. Patterns provided through the <i>exclude</i> or
  34. <i>excludesfile</i> attribute specify files to be
  35. excluded. Additionally, default exclusions can be specified with
  36. the <i>defaultexcludes</i> attribute. See the section on <a
  37. href="../dirtasks.html#directorybasedtasks">directory-based
  38. tasks</a>, for details of file inclusion/exclusion patterns
  39. and their usage.
  40. </p>
  41. <p>
  42. This task forms an implicit
  43. <a href="../Types/fileset.html">FileSet</a> and
  44. supports most attributes of <code>&lt;fileset&gt;</code>
  45. (<code>dir</code> becomes <code>srcdir</code>) as well as the nested
  46. <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  47. <code>&lt;patternset&gt;</code> elements.
  48. </p>
  49. <p>
  50. The output file is only written if it is a new file, or if it
  51. differs from the existing file. This prevents spurious
  52. rebuilds based on unchanged files which have been regenerated
  53. by this task. In order to assess whether a file has changed, this
  54. task will create a pre-processed version of the source file inside of
  55. the <a href="../running.html#tmpdir">temporary directory</a>.
  56. </p>
  57. <p>
  58. Since <b>Apache Ant 1.7</b>, this task can be used in a
  59. <a href="../Types/filterchain.html">filterchain</a>.
  60. </p>
  61. <h3>Parameters</h3>
  62. <table border="1" cellpadding="2" cellspacing="0">
  63. <tr>
  64. <td valign="center" rowspan="2"><b>Attribute</b></td>
  65. <td valign="center" rowspan="2"><b>Description</b></td>
  66. <td align="center" valign="top" colspan="2"><b>Required</b></td>
  67. </tr>
  68. <tr>
  69. <td valign="center"><b>As Task</b></td>
  70. <td valign="center"><b>As Filter</b></td>
  71. </tr>
  72. <tr>
  73. <td valign="top">srcDir</td>
  74. <td valign="top">Where to find the files to be fixed up.</td>
  75. <td valign="top" align="center" rowspan="2">One of these</td>
  76. <td bgcolor="#CCCCCC">&nbsp;</td>
  77. </tr>
  78. <tr>
  79. <td valign="top">file</td>
  80. <td valign="top">Name of a single file to fix. <b>Since Ant 1.7</b></td>
  81. <td bgcolor="#CCCCCC">&nbsp;</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">destDir</td>
  85. <td valign="top">Where to place the corrected files. Defaults to
  86. srcDir (replacing the original file).</td>
  87. <td valign="top" align="center">No</td>
  88. <td bgcolor="#CCCCCC">&nbsp;</td>
  89. </tr>
  90. <tr>
  91. <td valign="top">includes</td>
  92. <td valign="top">comma- or space-separated list of patterns of files that must be
  93. included. All files are included when omitted.</td>
  94. <td valign="top" align="center">No</td>
  95. <td bgcolor="#CCCCCC">&nbsp;</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">includesfile</td>
  99. <td valign="top">the name of a file. Each line of this file is
  100. taken to be an include pattern.</td>
  101. <td valign="top" align="center">No</td>
  102. <td bgcolor="#CCCCCC">&nbsp;</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">excludes</td>
  106. <td valign="top">comma- or space-separated list of patterns of files that must be
  107. excluded. No files (except default excludes) are excluded when omitted.</td>
  108. <td valign="top" align="center">No</td>
  109. <td bgcolor="#CCCCCC">&nbsp;</td>
  110. </tr>
  111. <tr>
  112. <td valign="top">excludesfile</td>
  113. <td valign="top">the name of a file. Each line of this file is
  114. taken to be an exclude pattern.</td>
  115. <td valign="top" align="center">No</td>
  116. <td bgcolor="#CCCCCC">&nbsp;</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">defaultexcludes</td>
  120. <td valign="top">indicates whether default excludes should be used or not
  121. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.
  122. </td>
  123. <td valign="top" align="center">No</td>
  124. <td bgcolor="#CCCCCC">&nbsp;</td>
  125. </tr>
  126. <tr>
  127. <td valign="top">encoding</td>
  128. <td valign="top">The encoding of the files.</td>
  129. <td align="center">No; defaults to default JVM encoding.</td>
  130. <td bgcolor="#CCCCCC">&nbsp;</td>
  131. </tr>
  132. <tr>
  133. <td valign="top">outputencoding</td>
  134. <td valign="top">The encoding to use when writing the files.
  135. <b>Since Ant 1.7</b></td>
  136. <td align="center">No; defaults to the value of the encoding attribute.</td>
  137. <td bgcolor="#CCCCCC">&nbsp;</td>
  138. </tr>
  139. <tr>
  140. <td valign="top">preservelastmodified</td>
  141. <td valign="top">Whether to preserve the last modified
  142. date of source files. <b>Since Ant 1.6.3</b></td>
  143. <td align="center">No; default is <i>false</i></td>
  144. <td bgcolor="#CCCCCC">&nbsp;</td>
  145. </tr>
  146. <tr>
  147. <td valign="top">eol</td>
  148. <td valign="top">
  149. Specifies how end-of-line (EOL) characters are to be
  150. handled. The EOL characters are CR, LF and the pair CRLF.
  151. Valid values for this property are:
  152. <ul>
  153. <li>asis: leave EOL characters alone</li>
  154. <li>cr: convert all EOLs to a single CR</li>
  155. <li>lf: convert all EOLs to a single LF</li>
  156. <li>crlf: convert all EOLs to the pair CRLF</li>
  157. <li>mac: convert all EOLs to a single CR</li>
  158. <li>unix: convert all EOLs to a single LF</li>
  159. <li>dos: convert all EOLs to the pair CRLF</li>
  160. </ul>
  161. Default is based on the platform on which you are running this task.
  162. For Unix platforms (including Mac OS X), the default is &quot;lf&quot;.
  163. For DOS-based systems (including Windows), the default is
  164. &quot;crlf&quot;.
  165. For Mac environments other than OS X, the default is &quot;cr&quot;.
  166. <p>
  167. This is the preferred method for specifying EOL. The
  168. &quot;<i><b>cr</b></i>&quot; attribute (see below) is
  169. now deprecated.
  170. </p>
  171. <p>
  172. <i>N.B.</i>: One special case is recognized. The three
  173. characters CR-CR-LF are regarded as a single EOL.
  174. Unless this property is specified as &quot;asis&quot;,
  175. this sequence will be converted into the specified EOL
  176. type.
  177. </p>
  178. </td>
  179. <td valign="top" align="center" colspan="2">No</td>
  180. </tr>
  181. <tr>
  182. <td valign="top">cr</td>
  183. <td valign="top">
  184. <i><b>Deprecated.</b></i> Specifies how CR characters are
  185. to be handled at end-of-line (EOL). Valid values for this
  186. property are:
  187. <ul>
  188. <li>asis: leave EOL characters alone.</li>
  189. <li>
  190. add: add a CR before any single LF characters. The
  191. intent is to convert all EOLs to the pair CRLF.
  192. </li>
  193. <li>
  194. remove: remove all CRs from the file. The intent is
  195. to convert all EOLs to a single LF.
  196. </li>
  197. </ul>
  198. Default is based on the platform on which you are running
  199. this task. For Unix platforms, the default is &quot;remove&quot;.
  200. For DOS based systems (including Windows), the default is
  201. &quot;add&quot;.
  202. <p>
  203. <i>N.B.</i>: One special case is recognized. The three
  204. characters CR-CR-LF are regarded as a single EOL.
  205. Unless this property is specified as &quot;asis&quot;,
  206. this sequence will be converted into the specified EOL
  207. type.
  208. </p>
  209. </td>
  210. <td valign="top" align="center" colspan="2">No</td>
  211. </tr>
  212. <tr>
  213. <td valign="top">javafiles</td>
  214. <td valign="top">
  215. Used only in association with the
  216. &quot;<i><b>tab</b></i>&quot; attribute (see below), this
  217. boolean attribute indicates whether the fileset is a set
  218. of java source files
  219. (&quot;yes&quot;/&quot;no&quot;). Defaults to
  220. &quot;no&quot;. See notes in section on &quot;tab&quot;.
  221. </td>
  222. <td valign="top" align="center" colspan="2">No</td>
  223. </tr>
  224. <tr>
  225. <td valign="top">tab</td>
  226. <td valign="top">Specifies how tab characters are to be handled. Valid
  227. values for this property are:
  228. <ul>
  229. <li>add: convert sequences of spaces which span a tab stop to tabs</li>
  230. <li>asis: leave tab and space characters alone</li>
  231. <li>remove: convert tabs to spaces</li>
  232. </ul>
  233. Default for this parameter is &quot;asis&quot;.
  234. <p>
  235. <i>N.B.</i>: When the attribute
  236. &quot;<i><b>javafiles</b></i>&quot; (see above) is
  237. &quot;true&quot;, literal TAB characters occurring
  238. within Java string or character constants are never
  239. modified. This functionality also requires the
  240. recognition of Java-style comments.
  241. </p>
  242. <p>
  243. <i>N.B.</i>: There is an incompatibility between this
  244. and the previous version in the handling of white
  245. space at the end of lines. This version does
  246. <i><b>not</b></i> remove trailing whitespace on lines.
  247. </p>
  248. </td>
  249. <td valign="top" align="center" colspan="2">No</td>
  250. </tr>
  251. <tr>
  252. <td valign="top">tablength</td>
  253. <td valign="top">TAB character interval. Valid values are between
  254. 2 and 80 inclusive. The default for this parameter is 8.</td>
  255. <td valign="top" align="center" colspan="2">No</td>
  256. </tr>
  257. <tr>
  258. <td valign="top">eof</td>
  259. <td valign="top">Specifies how DOS end of file (control-Z) characters are
  260. to be handled. Valid values for this property are:
  261. <ul>
  262. <li>add: ensure that there is an EOF character at the end of the file</li>
  263. <li>asis: leave EOF characters alone</li>
  264. <li>remove: remove any EOF character found at the end</li>
  265. </ul>
  266. Default is based on the platform on which you are running this task.
  267. For Unix platforms, the default is remove. For DOS based systems
  268. (including Windows), the default is asis.
  269. </td>
  270. <td valign="top" align="center" colspan="2">No</td>
  271. </tr>
  272. <tr>
  273. <td valign="top">fixlast</td>
  274. <td valign="top">Whether to add a missing EOL to the last line
  275. of a processed file.<br/>Ignored if EOL is asis.<br/><b>Since Ant 1.6.1</b></td>
  276. <td align="center" colspan="2">No; default is <i>true</i></td>
  277. </tr>
  278. </table>
  279. <h3>Examples</h3>
  280. <pre>&lt;fixcrlf srcdir=&quot;${src}&quot; includes=&quot;**/*.sh&quot;
  281. eol=&quot;lf&quot; eof=&quot;remove&quot; /&gt;</pre>
  282. <p>Replaces EOLs with LF characters and removes eof characters from
  283. the shell scripts. Tabs and spaces are left as is.</p>
  284. <pre>&lt;fixcrlf srcdir=&quot;${src}&quot;
  285. includes=&quot;**/*.bat&quot; eol=&quot;crlf&quot; /&gt;</pre>
  286. <p>Replaces all EOLs with cr-lf pairs in the batch files.
  287. Tabs and spaces are left as is.
  288. EOF characters are left alone if run on
  289. DOS systems, and are removed if run on Unix systems.</p>
  290. <pre>&lt;fixcrlf srcdir=&quot;${src}&quot;
  291. includes=&quot;**/Makefile&quot; tab=&quot;add&quot; /&gt;</pre>
  292. <p>Sets EOLs according to local OS conventions, and
  293. converts sequences of spaces and tabs to the minimal set of spaces and
  294. tabs which will maintain spacing within the line. Tabs are
  295. set at 8 character intervals. EOF characters are left alone if
  296. run on DOS systems, and are removed if run on Unix systems.
  297. Many versions of make require tabs prior to commands.</p>
  298. <pre>&lt;fixcrlf srcdir=&quot;${src}&quot; includes=&quot;**/*.java&quot;
  299. tab=&quot;remove&quot; tablength=&quot;3&quot;
  300. eol=&quot;lf&quot; javafiles=&quot;yes&quot; /&gt;</pre>
  301. <p>
  302. Converts all EOLs in the included java source files to a
  303. single LF. Replace all TAB characters except those in string
  304. or character constants with spaces, assuming a tab width of 3.
  305. If run on a unix system, any CTRL-Z EOF characters at the end
  306. of the file are removed. On DOS/Windows, any such EOF
  307. characters will be left untouched.
  308. </p>
  309. <pre>&lt;fixcrlf srcdir=&quot;${src}&quot;
  310. includes=&quot;**/README*&quot; tab=&quot;remove&quot; /&gt;</pre>
  311. <p>Sets EOLs according to local OS conventions, and
  312. converts all tabs to spaces, assuming a tab width of 8.
  313. EOF characters are left alone if run on
  314. DOS systems, and are removed if run on Unix systems.
  315. You never know what editor a user will use to browse READMEs.</p>
  316. </body>
  317. </html>