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.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. <td valign="top">setonempty</td>
  88. <td valign="top">Should the property be set, even if the result
  89. is the empty string?
  90. <td valign="top" align="center">No; default is &quot;true&quot;.
  91. </tr>
  92. </table>
  93. <h3>Parameters specified as nested elements</h3>
  94. <h4>map</h4>
  95. <p>Specifies the mapping of path prefixes between Unix and Windows.</p>
  96. <table border="1" cellpadding="2" cellspacing="0">
  97. <tr>
  98. <td valign="top"><b>Attribute</b></td>
  99. <td valign="top"><b>Description</b></td>
  100. <td align="center" valign="top"><b>Required</b></td>
  101. </tr>
  102. <tr>
  103. <td valign="top">from</td>
  104. <td valign="top">
  105. The prefix to match. Note that this value is case-insensitive when
  106. the build is running on a Windows platform and case-sensitive
  107. when running on a Unix platform.
  108. <em>Since Ant 1.7.0</em>, on Windows this value is also insensitive
  109. to the slash style used for directories, one can use '/' or '\'.
  110. </td>
  111. <td valign="top" align="center">Yes</td>
  112. </tr>
  113. <tr>
  114. <td valign="top">to</td>
  115. <td valign="top">The replacement text to use when <code>from</code> is matched.</td>
  116. <td valign="top" align="center">Yes</td>
  117. </tr>
  118. </table>
  119. <p>Each map element specifies a single replacement map to be applied to the elements of
  120. the path being processed. If no map entries are specified, then no path prefix mapping
  121. is performed.
  122. </p>
  123. <p><strong>Note</strong>: The map elements are applied in the order specified,
  124. and only the first matching map element is applied. So, the ordering of
  125. your map elements can be important, if any <code>from</code> values are
  126. prefixes of other <code>from</code> values.</i>
  127. </p>
  128. <h4>Resource Collections</h4>
  129. <p>If the <code>refid</code> attribute is not specified, then one or more
  130. nested <a href="../CoreTypes/resources.html#collection">Resource
  131. Collection</a>s must be supplied.</p>
  132. <h4>mapper</h4>
  133. <p>A single nested <a href="../CoreTypes/mapper.html">
  134. <code>&lt;mapper&gt;</code></a> element can be specified
  135. to perform any of various filename transformations (since Ant 1.6.2).
  136. </p>
  137. <h3>Examples</h3>
  138. <p>In the examples below, assume that the <code>${wl.home}</code> property
  139. has the value
  140. <code>d:\weblogic</code>, and <code>${wl.home.unix}</code> has the value
  141. <code>/weblogic</code>.</p>
  142. <h4>Example 1</h4>
  143. <pre>
  144. &lt;path id="wl.path"&gt;
  145. &lt;pathelement location=&quot;${wl.home}/lib/weblogicaux.jar&quot;/&gt;
  146. &lt;pathelement location=&quot;${wl.home}/classes&quot;/&gt;
  147. &lt;pathelement location=&quot;${wl.home}/mssqlserver4/classes&quot;/&gt;
  148. &lt;pathelement location=&quot;c:\winnt\System32&quot;/&gt;
  149. &lt;/path&gt;
  150. &lt;pathconvert targetos=&quot;unix&quot; property=&quot;wl.path.unix&quot; refid=&quot;wl.path&quot;&gt;
  151. &lt;map from=&quot;${wl.home}&quot; to=&quot;${wl.home.unix}&quot;/&gt;
  152. &lt;map from=&quot;c:&quot; to=&quot;&quot;/&gt;
  153. &lt;/pathconvert&gt;
  154. </pre>
  155. <p> will generate the path shown below
  156. and store it in the property named <code>wl.path.unix</code>.
  157. </p>
  158. <pre>
  159. /weblogic/lib/weblogicaux.jar:/weblogic/classes:/weblogic/mssqlserver4/classes:/WINNT/SYSTEM32
  160. </pre>
  161. <h4>Example 2</h4>
  162. Given a FileList defined as:
  163. <pre>
  164. &lt;filelist id=&quot;custom_tasks.jars&quot;
  165. dir=&quot;${env.HOME}/ant/lib&quot;
  166. files=&quot;njavac.jar,xproperty.jar&quot;/&gt;
  167. </pre>
  168. then:
  169. <pre>
  170. &lt;pathconvert targetos=&quot;unix&quot; property=&quot;custom_tasks.jars&quot; refid=&quot;custom_tasks.jars&quot;&gt;
  171. &lt;map from=&quot;${env.HOME}&quot; to=&quot;/usr/local&quot;/&gt;
  172. &lt;/pathconvert&gt;
  173. </pre>
  174. will convert the list of files to the following Unix path:
  175. <pre>
  176. /usr/local/ant/lib/njavac.jar:/usr/local/ant/lib/xproperty.jar
  177. </pre>
  178. <h4>Example 3</h4>
  179. <pre>
  180. &lt;fileset dir=&quot;${src.dir}&quot; id=&quot;src.files&quot;&gt;
  181. &lt;include name=&quot;**/*.java&quot;/&gt;
  182. &lt;/fileset&gt;
  183. &lt;pathconvert pathsep=&quot;,&quot; property=&quot;javafiles&quot; refid=&quot;src.files&quot;/&gt;
  184. </pre>
  185. <p>This example takes the set of files determined by the fileset (all files ending
  186. in <tt>.java</tt>), joins them together separated by commas, and places the resulting
  187. list into the property <tt>javafiles</tt>. The directory separator is not specified, so
  188. it defaults to the appropriate character for the current platform. Such a list could
  189. then be used in another task, like <tt>javadoc</tt>, that requires a comma separated
  190. list of files.
  191. </p>
  192. <h4>Example 4</h4>
  193. <pre>
  194. &lt;pathconvert property="prop" dirsep="|"&gt;
  195. &lt;map from="${basedir}/abc/" to=''/&gt;
  196. &lt;path location="abc/def/ghi"/&gt;
  197. &lt;/pathconvert&gt;
  198. </pre>
  199. <p>
  200. This example sets the property "prop" to "def|ghi" on
  201. Windows and on Unix.
  202. </p>
  203. </body>
  204. </html>