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 KiB

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