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.

native2ascii.html 8.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  18. <title>Native2Ascii Task</title>
  19. </head>
  20. <body>
  21. <h2>Native2Ascii</h2>
  22. <h3>Description</h3>
  23. <p>Converts files from native encodings to ASCII with escaped Unicode. A common usage is to
  24. convert source files maintained in a native operating system encoding, to ASCII prior to
  25. compilation.</p>
  26. <p>Files in the directory <var>src</var> are converted from a native encoding to ASCII. By
  27. default, all files in the directory are converted. However, conversion may be limited to
  28. selected files using <var>includes</var> and <var>excludes</var> attributes. For more
  29. information on file matching patterns, see the section
  30. on <a href="../dirtasks.html#directorybasedtasks">directory based tasks</a>. If
  31. no <var>encoding</var> is specified, the default encoding for the JVM is used.
  32. If <var>ext</var> is specified, then output files are renamed to use it as a new extension.
  33. More sophisticated file name translations can be achieved using a
  34. nested <code>&lt;mapper&gt;</code> element. By default
  35. an <a href="../Types/mapper.html#identity-mapper">identity mapper</a> will be used.
  36. If <var>dest</var> and <var>src</var> point to the same directory, the <var>ext</var>
  37. attribute or a nested <code>&lt;mapper&gt;</code> is required.</p>
  38. <p>This task forms an implicit <a href="../Types/fileset.html">FileSet</a>, and supports most
  39. attributes of <code>&lt;fileset&gt;</code> (<var>dir</var> becomes <var>src</var>) as well as
  40. nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code>,
  41. and <code>&lt;patternset&gt;</code> elements.</p>
  42. <p id="implementationvalues">It is possible to use different converters. This can be selected
  43. with the <var>implementation</var> attribute or a nested element. Here are the choices of the
  44. attribute:</p>
  45. <ul>
  46. <li><q>default</q>&mdash;the default converter for the platform: kaffe when run on Kaffe,
  47. builtin otherwise.</li>
  48. <li><q>sun</q>&mdash;used to be the standard converter of the JDK &lt; 9</li>
  49. <li><q>kaffe</q>&mdash;the standard converter of <a href="http://www.kaffe.org"
  50. target="_top">Kaffe</a></li>
  51. <li><q>builtin</q>&mdash;Ant's internal implementation. <em>Since Ant 1.9.8</em></li>
  52. </ul>
  53. <table class="attr">
  54. <tr>
  55. <th>Attribute</th>
  56. <th>Description</th>
  57. <th>Required</th>
  58. </tr>
  59. <tr>
  60. <td>reverse</td>
  61. <td>Reverse the sense of the conversion, i.e. convert from ASCII to native <strong>only
  62. supported by the <q>sun</q> and <q>builtin</q> converters</strong></td>
  63. <td>No</td>
  64. </tr>
  65. <tr>
  66. <td>encoding</td>
  67. <td>The native encoding the files are in</td>
  68. <td>No; defaults to default JVM character encoding</td>
  69. </tr>
  70. <tr>
  71. <td>src</td>
  72. <td>The directory to find files in; default is <var>basedir</var></td>
  73. <td>No</td>
  74. </tr>
  75. <tr>
  76. <td>dest</td>
  77. <td>The directory to output file to</td>
  78. <td>Yes</td>
  79. </tr>
  80. <tr>
  81. <td>ext</td>
  82. <td>File extension to use in renaming output files</td>
  83. <td>No</td>
  84. </tr>
  85. <tr>
  86. <td>includes</td>
  87. <td>Comma- or space-separated list of patterns of files that must be included.</td>
  88. <td>No; defaults to all (<q>**</q>)</td>
  89. </tr>
  90. <tr>
  91. <td>includesfile</td>
  92. <td>Name of a file. Each line of this file is taken to be an include pattern</td>
  93. <td>No</td>
  94. </tr>
  95. <tr>
  96. <td>excludes</td>
  97. <td>Comma- or space-separated list of patterns of files that must be excluded.</td>
  98. <td>No; defaults to default excludes or none if <var>defaultexcludes</var> is <q>no</q></td>
  99. </tr>
  100. <tr>
  101. <td>excludesfile</td>
  102. <td>Name of a file. Each line of this file is taken to be an exclude pattern</td>
  103. <td>No</td>
  104. </tr>
  105. <tr>
  106. <td>defaultexcludes</td>
  107. <td>Indicates whether default excludes should be used or not (<q>yes|no</q>).</td>
  108. <td>No; defaults to <q>yes</q></td>
  109. </tr>
  110. <tr>
  111. <td>implementation</td>
  112. <td>The converter implementation to use. (See the
  113. above <a href="#implementationvalues">list</a> of valid converters.)</td>
  114. <td>No; defaults to default converter for the current JVM</td>
  115. </tr>
  116. </table>
  117. <h3>Parameters specified as nested elements</h3>
  118. <h4>arg</h4>
  119. <p>You can specify additional command line arguments for the converter with
  120. nested <code>&lt;arg&gt;</code> elements. These elements are specified
  121. like <a href="../using.html#arg">Command-line Arguments</a> but have an additional attribute that
  122. can be used to enable arguments only if a given converter implementation will be used.</p>
  123. <table class="attr">
  124. <tr>
  125. <th>Attribute</th>
  126. <th>Description</th>
  127. <th>Required</th>
  128. </tr>
  129. <tr>
  130. <td>value</td>
  131. <td rowspan="4">See <a href="../using.html#arg">Command-line Arguments</a>.</td>
  132. <td rowspan="4">Exactly one of these</td>
  133. </tr>
  134. <tr>
  135. <td class="var">line</td>
  136. </tr>
  137. <tr>
  138. <td class="var">file</td>
  139. </tr>
  140. <tr>
  141. <td class="var">path</td>
  142. </tr>
  143. <tr>
  144. <td>implementation</td>
  145. <td>Only pass the specified argument if the chosen converter implementation matches the value of
  146. this attribute. Legal values are the same as those in the
  147. above <a href="#implementationvalues">list</a> of valid compilers.)</td>
  148. <td>No</td>
  149. </tr>
  150. </table>
  151. <h4>implementationclasspath (<em>since Apache Ant 1.8.0</em>)</h4>
  152. <p>A <a href="../using.html#path">path-like structure</a> holding the classpath to use when loading
  153. the converter implementation if a custom class has been specified. Doesn't have any effect when
  154. using one of the built-in converters.</p>
  155. <h4>Any nested element of a type that implements Native2AsciiAdapter (<em>since Ant 1.8.0</em>)</h4>
  156. <p>If a defined type implements the <code>Native2AsciiAdapter</code> interface a nested element of
  157. that type can be used as an alternative to the <var>implementation</var> attribute.</p>
  158. <h3>Examples</h3>
  159. <pre>
  160. &lt;native2ascii encoding=&quot;EUCJIS&quot; src=&quot;srcdir&quot; dest=&quot;srcdir&quot;
  161. includes=&quot;**/*.eucjis&quot; ext=&quot;.java&quot;/&gt;</pre>
  162. <p>Converts all files in the directory <samp>srcdir</samp> ending in <samp>.eucjis</samp> from
  163. the EUCJIS encoding to ASCII and renames them to end in <samp>.java</samp>.</p>
  164. <pre>
  165. &lt;native2ascii encoding=&quot;EUCJIS&quot; src=&quot;native/japanese&quot; dest=&quot;src&quot;
  166. includes=&quot;**/*.java&quot;/&gt;</pre>
  167. <p>Converts all the files ending in <samp>.java</samp> in the directory <samp>native/japanese</samp>
  168. to ASCII, placing the results in the directory <samp>src</samp>. The names of the files remain the
  169. same.</p>
  170. <p>If you want to use a custom Native2AsciiAdapter <code>org.example.MyAdapter</code> you can either
  171. use the implementation attribute:</p>
  172. <pre>
  173. &lt;native2ascii encoding="EUCJIS" src="srcdir" dest="srcdir"
  174. includes="**/*.eucjis" ext=".java"
  175. implementation="org.example.MyAdapter"/&gt;</pre>
  176. <p>or a define a type and nest this into the task like in:</p>
  177. <pre>
  178. &lt;componentdef classname="org.example.MyAdapter"
  179. name="myadapter"/&gt;
  180. &lt;native2ascii encoding="EUCJIS" src="srcdir" dest="srcdir"
  181. includes="**/*.eucjis" ext=".java"&gt;
  182. &lt;myadapter/&gt;
  183. &lt;/native2ascii&gt;</pre>
  184. <p>in which case your native2ascii adapter can support attributes and nested elements of its
  185. own.</p>
  186. </body>
  187. </html>