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.

pathconvert.html 8.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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>PathConvert Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="pathconvert">Pathconvert</a></h2>
  23. <h3>Description</h3>
  24. <p>Converts nested <a href="../CoreTypes/resources.html#collection">
  25. ResourceCollection</a>s, or a reference to just one, into a path
  26. form for a particular platform, optionally storing the result into
  27. a given property. It can also be used when you need
  28. to convert a Resource Collection into a list, separated by a given
  29. character, such as a comma or space, or, conversely, e.g. to convert a list
  30. of files in a FileList into a path.
  31. </p>
  32. <p>Nested <code>&lt;map&gt;</code> elements can be specified to map Windows
  33. drive letters to Unix paths, and vice-versa.</p>
  34. <p>More complex transformations can be achieved using a nested
  35. <a href="../CoreTypes/mapper.html"><code>&lt;mapper&gt;</code></a>
  36. (since Ant 1.6.2).
  37. </p>
  38. <h3>Parameters</h3>
  39. <table border="1" cellpadding="2" cellspacing="0">
  40. <tr>
  41. <td valign="top"><b>Attribute</b></td>
  42. <td valign="top"><b>Description</b></td>
  43. <td align="center" valign="top"><b>Required</b></td>
  44. </tr>
  45. <tr>
  46. <td valign="top">targetos</td>
  47. <td valign="top">
  48. The target architecture. Must be one of 'unix', 'windows',
  49. 'netware', 'tandem' or 'os/2'.
  50. This is a shorthand mechanism for specifying both
  51. <code>pathsep</code> and <code>dirsep</code>
  52. according to the specified target architecture.
  53. </td>
  54. <td valign="top" align="center">No</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">dirsep</td>
  58. <td valign="top">
  59. The character(s) to use as the directory separator in the
  60. generated paths.
  61. </td>
  62. <td valign="top" align="center">No, defaults to current JVM <tt>File.separator</tt></td>
  63. </tr>
  64. <tr>
  65. <td valign="top">pathsep</td>
  66. <td valign="top">
  67. The character(s) to use as the path-element separator in the
  68. generated paths.
  69. </td>
  70. <td valign="top" align="center">No, defaults to current JVM <tt>File.pathSeparator</tt></td>
  71. </tr>
  72. <tr>
  73. <td valign="top">property</td>
  74. <td valign="top">The name of the property in which to place the converted path.</td>
  75. <td valign="top" align="center">No, result will be logged if unset</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">refid</td>
  79. <td valign="top">What to convert, given as a
  80. <a href="../using.html#references">reference</a> to a
  81. <code>&lt;path&gt;</code>, <code>&lt;fileset&gt;</code>,
  82. <code>&lt;dirset&gt;</code>, or <code>&lt;filelist&gt;</code>
  83. defined elsewhere</td>
  84. <td valign="top" align="center">No; if omitted, a nested
  85. <code>&lt;path&gt;</code> element must be supplied.</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">setonempty</td>
  89. <td valign="top">Should the property be set, even if the result
  90. is the empty string?
  91. <td valign="top" align="center">No; default is &quot;true&quot;.
  92. </tr>
  93. <tr>
  94. <td valign="top">preserveduplicates</td>
  95. <td valign="top">Whether to preserve duplicate resources. <b>Since Ant 1.8</b></td>
  96. <td valign="top" align="center">No; default &quot;false&quot;.
  97. </tr>
  98. </table>
  99. <h3>Parameters specified as nested elements</h3>
  100. <h4>map</h4>
  101. <p>Specifies the mapping of path prefixes between Unix and Windows.</p>
  102. <table border="1" cellpadding="2" cellspacing="0">
  103. <tr>
  104. <td valign="top"><b>Attribute</b></td>
  105. <td valign="top"><b>Description</b></td>
  106. <td align="center" valign="top"><b>Required</b></td>
  107. </tr>
  108. <tr>
  109. <td valign="top">from</td>
  110. <td valign="top">
  111. The prefix to match. Note that this value is case-insensitive when
  112. the build is running on a Windows platform and case-sensitive
  113. when running on a Unix platform.
  114. <em>Since Ant 1.7.0</em>, on Windows this value is also insensitive
  115. to the slash style used for directories, one can use '/' or '\'.
  116. </td>
  117. <td valign="top" align="center">Yes</td>
  118. </tr>
  119. <tr>
  120. <td valign="top">to</td>
  121. <td valign="top">The replacement text to use when <code>from</code> is matched.</td>
  122. <td valign="top" align="center">Yes</td>
  123. </tr>
  124. </table>
  125. <p>Each map element specifies a single replacement map to be applied to the elements of
  126. the path being processed. If no map entries are specified, then no path prefix mapping
  127. is performed.
  128. </p>
  129. <p><strong>Note</strong>: The map elements are applied in the order specified,
  130. and only the first matching map element is applied. So, the ordering of
  131. your map elements can be important, if any <code>from</code> values are
  132. prefixes of other <code>from</code> values.</i>
  133. </p>
  134. <h4>Resource Collections</h4>
  135. <p>If the <code>refid</code> attribute is not specified, then one or more
  136. nested <a href="../CoreTypes/resources.html#collection">Resource
  137. Collection</a>s must be supplied.</p>
  138. <h4>mapper</h4>
  139. <p>A single nested <a href="../CoreTypes/mapper.html">
  140. <code>&lt;mapper&gt;</code></a> element can be specified
  141. to perform any of various filename transformations (since Ant 1.6.2).
  142. </p>
  143. <h3>Examples</h3>
  144. <p>In the examples below, assume that the <code>${wl.home}</code> property
  145. has the value
  146. <code>d:\weblogic</code>, and <code>${wl.home.unix}</code> has the value
  147. <code>/weblogic</code>.</p>
  148. <h4>Example 1</h4>
  149. <pre>
  150. &lt;path id="wl.path"&gt;
  151. &lt;pathelement location=&quot;${wl.home}/lib/weblogicaux.jar&quot;/&gt;
  152. &lt;pathelement location=&quot;${wl.home}/classes&quot;/&gt;
  153. &lt;pathelement location=&quot;${wl.home}/mssqlserver4/classes&quot;/&gt;
  154. &lt;pathelement location=&quot;c:\winnt\System32&quot;/&gt;
  155. &lt;/path&gt;
  156. &lt;pathconvert targetos=&quot;unix&quot; property=&quot;wl.path.unix&quot; refid=&quot;wl.path&quot;&gt;
  157. &lt;map from=&quot;${wl.home}&quot; to=&quot;${wl.home.unix}&quot;/&gt;
  158. &lt;map from=&quot;c:&quot; to=&quot;&quot;/&gt;
  159. &lt;/pathconvert&gt;
  160. </pre>
  161. <p> will generate the path shown below
  162. and store it in the property named <code>wl.path.unix</code>.
  163. </p>
  164. <pre>
  165. /weblogic/lib/weblogicaux.jar:/weblogic/classes:/weblogic/mssqlserver4/classes:/WINNT/SYSTEM32
  166. </pre>
  167. <h4>Example 2</h4>
  168. Given a FileList defined as:
  169. <pre>
  170. &lt;filelist id=&quot;custom_tasks.jars&quot;
  171. dir=&quot;${env.HOME}/ant/lib&quot;
  172. files=&quot;njavac.jar,xproperty.jar&quot;/&gt;
  173. </pre>
  174. then:
  175. <pre>
  176. &lt;pathconvert targetos=&quot;unix&quot; property=&quot;custom_tasks.jars&quot; refid=&quot;custom_tasks.jars&quot;&gt;
  177. &lt;map from=&quot;${env.HOME}&quot; to=&quot;/usr/local&quot;/&gt;
  178. &lt;/pathconvert&gt;
  179. </pre>
  180. will convert the list of files to the following Unix path:
  181. <pre>
  182. /usr/local/ant/lib/njavac.jar:/usr/local/ant/lib/xproperty.jar
  183. </pre>
  184. <h4>Example 3</h4>
  185. <pre>
  186. &lt;fileset dir=&quot;${src.dir}&quot; id=&quot;src.files&quot;&gt;
  187. &lt;include name=&quot;**/*.java&quot;/&gt;
  188. &lt;/fileset&gt;
  189. &lt;pathconvert pathsep=&quot;,&quot; property=&quot;javafiles&quot; refid=&quot;src.files&quot;/&gt;
  190. </pre>
  191. <p>This example takes the set of files determined by the fileset (all files ending
  192. in <tt>.java</tt>), joins them together separated by commas, and places the resulting
  193. list into the property <tt>javafiles</tt>. The directory separator is not specified, so
  194. it defaults to the appropriate character for the current platform. Such a list could
  195. then be used in another task, like <tt>javadoc</tt>, that requires a comma separated
  196. list of files.
  197. </p>
  198. <h4>Example 4</h4>
  199. <pre>
  200. &lt;pathconvert property="prop" dirsep="|"&gt;
  201. &lt;map from="${basedir}/abc/" to=''/&gt;
  202. &lt;path location="abc/def/ghi"/&gt;
  203. &lt;/pathconvert&gt;
  204. </pre>
  205. <p>
  206. This example sets the property "prop" to "def|ghi" on
  207. Windows and on Unix.
  208. </p>
  209. </body>
  210. </html>