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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 id="fixcrlf">FixCRLF</h2>
  23. <h3>Description</h3>
  24. <p>Adjusts a text file to local conventions.</p>
  25. <p>The set of files to be adjusted can be refined with
  26. the <var>includes</var>, <var>includesfile</var>, <var>excludes</var>, <var>excludesfile</var>
  27. and <var>defaultexcludes</var> attributes. Patterns provided through the <var>includes</var>
  28. or <var>includesfile</var> attributes specify files to be included. Patterns provided through
  29. the <var>exclude</var> or <var>excludesfile</var> attribute specify files to be
  30. excluded. Additionally, default exclusions can be specified with the <var>defaultexcludes</var>
  31. attribute. See the section on <a href="../dirtasks.html#directorybasedtasks">directory-based
  32. tasks</a>, for details of file inclusion/exclusion patterns and their usage.</p>
  33. <p>This task forms an implicit <a href="../Types/fileset.html">FileSet</a> and supports most
  34. attributes of <code>&lt;fileset&gt;</code> (<var>dir</var> becomes <var>srcdir</var>) as well as
  35. the nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code>
  36. and <code>&lt;patternset&gt;</code> elements.</p>
  37. <p>The output file is only written if it is a new file, or if it differs from the existing file.
  38. This prevents spurious rebuilds based on unchanged files which have been regenerated by this
  39. task.</p>
  40. <p><em>Since Apache Ant 1.7</em>, this task can be used in
  41. a <a href="../Types/filterchain.html">filterchain</a>.</p>
  42. <h3>Parameters</h3>
  43. <table class="attr">
  44. <tr>
  45. <th scope="col" rowspan="2">Attribute</th>
  46. <th scope="col" rowspan="2">Description</th>
  47. <th scope="col" colspan="2">Required</th>
  48. </tr>
  49. <tr>
  50. <th scope="col">As Task</th>
  51. <th scope="col">As Filter</th>
  52. </tr>
  53. <tr>
  54. <td>srcDir</td>
  55. <td>Where to find the files to be fixed up.</td>
  56. <td rowspan="2" class="center">One of these</td>
  57. <td rowspan="11">N/A</td>
  58. </tr>
  59. <tr>
  60. <td>file</td>
  61. <td class="left">Name of a single file to fix. <em>Since Ant 1.7</em></td>
  62. </tr>
  63. <tr>
  64. <td>destDir</td>
  65. <td>Where to place the corrected files.</td>
  66. <td class="center">No; defaults to <var>srcDir</var> (replace the original files)</td>
  67. </tr>
  68. <tr>
  69. <td>includes</td>
  70. <td>comma- or space-separated list of patterns of files that must be included.</td>
  71. <td class="center">No; defaults to all (<q>**</q>)</td>
  72. </tr>
  73. <tr>
  74. <td>includesfile</td>
  75. <td>name of a file. Each line of this file is taken to be an include pattern.</td>
  76. <td class="center">No</td>
  77. </tr>
  78. <tr>
  79. <td>excludes</td>
  80. <td>comma- or space-separated list of patterns of files that must be excluded.</td>
  81. <td class="center">No; defaults to default excludes or none if <var>defaultexcludes</var>
  82. is <q>no</q></td>
  83. </tr>
  84. <tr>
  85. <td>excludesfile</td>
  86. <td>name of a file. Each line of this file is taken to be an exclude pattern.</td>
  87. <td class="center">No</td>
  88. </tr>
  89. <tr>
  90. <td>defaultexcludes</td>
  91. <td>indicates whether default excludes should be used or not (<q>yes|no</q>).</td>
  92. <td class="center">No; defaults to <q>yes</q></td>
  93. </tr>
  94. <tr>
  95. <td>encoding</td>
  96. <td>The encoding of the files.</td>
  97. <td class="center">No; defaults to default JVM character encoding</td>
  98. </tr>
  99. <tr>
  100. <td>outputencoding</td>
  101. <td>The encoding to use when writing the files. <em>Since Ant 1.7</em></td>
  102. <td class="center">No; defaults to <var>encoding</var> if set or default JVM character encoding
  103. otherwise</td>
  104. </tr>
  105. <tr>
  106. <td>preservelastmodified</td>
  107. <td>Whether to preserve the last modified date of source files. <em>Since Ant 1.6.3</em></td>
  108. <td class="center">No; default is <q>false</q></td>
  109. </tr>
  110. <tr>
  111. <td>eol</td>
  112. <td>Specifies how end-of-line (EOL) characters are to be handled. The EOL characters are CR, LF
  113. and the pair CRLF. Valid values for this property are:
  114. <ul>
  115. <li><q>asis</q>: leave EOL characters alone</li>
  116. <li><q>cr</q>: convert all EOLs to a single CR</li>
  117. <li><q>lf</q>: convert all EOLs to a single LF</li>
  118. <li><q>crlf</q>: convert all EOLs to the pair CRLF</li>
  119. <li><q>mac</q>: convert all EOLs to a single CR</li>
  120. <li><q>unix</q>: convert all EOLs to a single LF</li>
  121. <li><q>dos</q>: convert all EOLs to the pair CRLF</li>
  122. </ul>
  123. <p>This is the preferred method for specifying EOL. The <var>cr</var> attribute (see below)
  124. is now deprecated.</p>
  125. <p><strong>Note</strong>: One special case is recognized. The three characters CR-CR-LF are
  126. regarded as a single EOL. Unless this property is specified as <q>asis</q>, this sequence
  127. will be converted into the specified EOL type.</p>
  128. </td>
  129. <td colspan="2">No; default is platform-specific: <q>lf</q> for Unix platforms (including Mac OS
  130. X/macOS), <q>crlf</q> for DOS-based systems (including Windows), <q>cr</q> for Mac environments
  131. other than OS X</td>
  132. </tr>
  133. <tr>
  134. <td>cr</td>
  135. <td><em><u>Deprecated</u></em>. Specifies how CR characters are to be handled at end-of-line
  136. (EOL). Valid values for this property are:
  137. <ul>
  138. <li><q>asis</q>: leave EOL characters alone.</li>
  139. <li><q>add</q>: add a CR before any single LF characters. The intent is to convert all EOLs
  140. to the pair CRLF.</li>
  141. <li><q>remove</q>: remove all CRs from the file. The intent is to convert all EOLs to a
  142. single LF.</li>
  143. </ul>
  144. <p><strong>Note</strong>: One special case is recognized. The three characters CR-CR-LF are
  145. regarded as a single EOL. Unless this property is specified as <q>asis</q>, this sequence
  146. will be converted into the specified EOL type.</p>
  147. </td>
  148. <td colspan="2">No; default is platform-specific: <q>remove</q> for Unix platforms, <q>add</q>
  149. for DOS based systems (including Windows)</td>
  150. </tr>
  151. <tr>
  152. <td>javafiles</td>
  153. <td>Used only in association with the <var>tab</var> attribute (see below), this boolean
  154. attribute indicates whether the fileset is a set of Java source files (<q>yes|no</q>). See
  155. notes in section on <var>tab</var>.</td>
  156. <td colspan="2">No; defaults to <q>no</q></td>
  157. </tr>
  158. <tr>
  159. <td>tab</td>
  160. <td>Specifies how tab characters are to be handled. Valid values for this property are:
  161. <ul>
  162. <li><q>add</q>: convert sequences of spaces which span a tab stop to tabs</li>
  163. <li><q>asis</q>: leave tab and space characters alone</li>
  164. <li><q>remove</q>: convert tabs to spaces</li>
  165. </ul>
  166. <p><strong>Note</strong>: When the attribute <var>javafiles</var> (see above) is <q>true</q>,
  167. literal TAB characters occurring within Java string or character constants are never
  168. modified. This functionality also requires the recognition of Java-style comments.</p>
  169. <p><strong>Note</strong>: There is an incompatibility between this and the previous version in
  170. the handling of white space at the end of lines. This version
  171. does <em><strong>not</strong></em> remove trailing whitespace on lines.</p>
  172. </td>
  173. <td colspan="2">No; default is <q>asis</q></td>
  174. </tr>
  175. <tr>
  176. <td>tablength</td>
  177. <td>TAB character interval. Valid values are between <q>2</q> and <q>80</q> inclusive.</td>
  178. <td colspan="2">No; default is <q>8</q></td>
  179. </tr>
  180. <tr>
  181. <td>eof</td>
  182. <td>Specifies how DOS end of file (control-Z) characters are to be handled. Valid values for
  183. this property are:
  184. <ul>
  185. <li><q>add</q>: ensure that there is an EOF character at the end of the file</li>
  186. <li><q>asis</q>: leave EOF characters alone</li>
  187. <li><q>remove</q>: remove any EOF character found at the end</li>
  188. </ul>
  189. </td>
  190. <td colspan="2">No; default is platform-specific: <q>remove</q> for Unix platforms, <q>asis</q>
  191. for DOS based systems (including Windows)</td>
  192. </tr>
  193. <tr>
  194. <td>fixlast</td>
  195. <td>Whether to add a missing EOL to the last line of a processed file.<br/>Ignored
  196. if <var>eof</var> is <q>asis</q>.<br/><em>Since Ant 1.6.1</em></td>
  197. <td colspan="2">No; default is <q>true</q></td>
  198. </tr>
  199. </table>
  200. <h3>Examples</h3>
  201. <p>Replace EOLs with LF characters and remove EOF characters from the shell scripts. Tabs and spaces
  202. are left as is.</p>
  203. <pre>
  204. &lt;fixcrlf srcdir=&quot;${src}&quot; includes=&quot;**/*.sh&quot;
  205. eol=&quot;lf&quot; eof=&quot;remove&quot;/&gt;</pre>
  206. <p>Replace all EOLs with cr-lf pairs in the batch files. Tabs and spaces are left as is. EOF
  207. characters are left alone if run on DOS systems, and are removed if run on Unix systems.</p>
  208. <pre>
  209. &lt;fixcrlf srcdir=&quot;${src}&quot;
  210. includes=&quot;**/*.bat&quot; eol=&quot;crlf&quot;/&gt;</pre>
  211. <p>Set EOLs according to local OS conventions, and convert sequences of spaces and tabs into the
  212. minimal set of spaces and tabs which will preserve spacing within the line. Tabs are set at 8
  213. character intervals. EOF characters are left alone if run on DOS systems, and are removed if run on
  214. Unix systems. Many versions of make require tabs prior to commands.</p>
  215. <pre>
  216. &lt;fixcrlf srcdir=&quot;${src}&quot;
  217. includes=&quot;**/Makefile&quot; tab=&quot;add&quot;/&gt;</pre>
  218. <p>Convert all EOLs in the included Java source files to a single LF. Replace all tab characters
  219. except those in string or character constants with spaces, assuming a tab width of 3. If run on a
  220. Unix system, any CTRL-Z EOF characters at the end of the file are removed. On DOS/Windows, any such
  221. EOF characters will be left untouched.
  222. </p>
  223. <pre>
  224. &lt;fixcrlf srcdir=&quot;${src}&quot; includes=&quot;**/*.java&quot;
  225. tab=&quot;remove&quot; tablength=&quot;3&quot;
  226. eol=&quot;lf&quot; javafiles=&quot;yes&quot;/&gt;</pre>
  227. <p>Set EOLs according to local OS conventions, and convert all tabs to spaces, assuming a tab width
  228. of 8. EOF characters are left alone if run on DOS systems, and are removed if run on Unix
  229. systems. You never know what editor a user will use to browse READMEs.</p>
  230. <pre>
  231. &lt;fixcrlf srcdir=&quot;${src}&quot;
  232. includes=&quot;**/README*&quot; tab=&quot;remove&quot;/&gt;</pre>
  233. </body>
  234. </html>