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

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