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.

replace.html 7.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apache Ant User Manual</title>
  5. </head>
  6. <body>
  7. <h2><a name="replace">Replace</a></h2>
  8. <h3>Description</h3>
  9. <p>Replace is a directory based task for replacing the occurrence of a given string with another string
  10. in selected file.</p>
  11. <p>If you want to replace a text that crosses line boundaries, you
  12. must use a nested <code>&lt;replacetoken&gt;</code> element.</p>
  13. <h3>Parameters</h3>
  14. <table border="1" cellpadding="2" cellspacing="0">
  15. <tr>
  16. <td valign="top"><b>Attribute</b></td>
  17. <td valign="top"><b>Description</b></td>
  18. <td align="center" valign="top"><b>Required</b></td>
  19. </tr>
  20. <tr>
  21. <td valign="top">file</td>
  22. <td valign="top">file for which the token should be replaced.</td>
  23. <td align="center" rowspan="2">Exactly one of the two.</td>
  24. </tr>
  25. <tr>
  26. <td valign="top">dir</td>
  27. <td valign="top">The base directory to use when replacing a token in
  28. multiple files.</td>
  29. </tr>
  30. <tr>
  31. <td valign="top">encoding</td>
  32. <td valign="top">The encoding of the files upon which replace operates.</td>
  33. <td align="center">No - defaults to default JVM encoding</td>
  34. </tr>
  35. <tr>
  36. <td valign="top">token</td>
  37. <td valign="top">the token which must be replaced.</td>
  38. <td valign="top" align="center">Yes, unless a nested <code>replacetoken</code>
  39. element is used.</td>
  40. </tr>
  41. <tr>
  42. <td valign="top">value</td>
  43. <td valign="top">the new value for the token. When omitted, an empty string
  44. (&quot;&quot;) is used.</td>
  45. <td valign="top" align="center">No</td>
  46. </tr>
  47. <tr>
  48. <td valign="top">summary</td>
  49. <td valign="top">Indicates whether a summary of the replace operation
  50. should be produced, detailing how many token occurrences
  51. and files were processed
  52. </td>
  53. <td valign="top" align="center">No, by default no summary is produced</td>
  54. </tr>
  55. <tr>
  56. <td valign="top">propertyFile</td>
  57. <td valign="top">valid property file from which properties specified using nested <code>&lt;replacefilter&gt;</code> elements are drawn.</td>
  58. <td valign="top" align="center">Yes only if <i>property</i> attribute of <code>&lt;replacefilter&gt;</code> is used.</td>
  59. </tr>
  60. <tr>
  61. <td valign="top">includes</td>
  62. <td valign="top">comma separated list of patterns of files that must be
  63. included. All files are included when omitted.</td>
  64. <td valign="top" align="center">No</td>
  65. </tr>
  66. <tr>
  67. <td valign="top">includesfile</td>
  68. <td valign="top">the name of a file. Each line of this file is
  69. taken to be an include pattern</td>
  70. <td valign="top" align="center">No</td>
  71. </tr>
  72. <tr>
  73. <td valign="top">excludes</td>
  74. <td valign="top">comma separated list of patterns of files that must be
  75. excluded. No files (except default excludes) are excluded when omitted.</td>
  76. <td valign="top" align="center">No</td>
  77. </tr>
  78. <tr>
  79. <td valign="top">excludesfile</td>
  80. <td valign="top">the name of a file. Each line of this file is
  81. taken to be an exclude pattern</td>
  82. <td valign="top" align="center">No</td>
  83. </tr>
  84. <tr>
  85. <td valign="top">defaultexcludes</td>
  86. <td valign="top">indicates whether default excludes should be used or not
  87. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  88. <td valign="top" align="center">No</td>
  89. </tr>
  90. </table>
  91. <h3>Examples</h3>
  92. <pre> &lt;replace file=&quot;${src}/index.html&quot; token=&quot;@@@&quot; value=&quot;wombat&quot;/&gt;</pre>
  93. <p>replaces occurrences of the string &quot;@@@&quot; with the string
  94. &quot;wombat&quot;, in the file <code>${src}/index.html</code>.</p>
  95. <h3>Parameters specified as nested elements</h3>
  96. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  97. supports all attributes of <code>&lt;fileset&gt;</code> as well as the
  98. nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  99. <code>&lt;patternset&gt;</code> elements.</p>
  100. <p>If either the text you want to replace or the replacement text
  101. cross line boundaries, you can use nested elements to specify
  102. them.</p>
  103. <h3>Examples</h3>
  104. <blockquote><pre>
  105. &lt;replace dir=&quot;${src}&quot; value=&quot;wombat&quot;&gt;
  106. &lt;include name=&quot;**/*.html&quot;/&gt;
  107. &lt;replacetoken&gt;&lt;![CDATA[multi line
  108. token]]>&lt;/replacetoken&gt;
  109. &lt;/replace&gt;
  110. </pre></blockquote>
  111. <p>replaces occurrences of the string &quot;multi
  112. line<i>\n</i>token&quot; with the string &quot;wombat&quot;, in all
  113. HTML files in the directory <code>${src}</code>.Where <i>\n</i> is
  114. the platform specific line separator.</p>
  115. <blockquote><pre>
  116. &lt;replace file=&quot;${src}/index.html&quot;&gt;
  117. &lt;replacetoken&gt;&lt;![CDATA[two line
  118. token]]>&lt;/replacetoken&gt;
  119. &lt;replacevalue&gt;&lt;![CDATA[two line
  120. token]]>&lt;/replacevalue&gt;
  121. &lt;/replace&gt;
  122. </pre></blockquote>
  123. <h4>replacefilter</h4>
  124. <p>In addition to allowing for multiple replacements, optional nested <code>&lt;replacefilter&gt;</code> elements allow replacement values to be extracted from a property file. The name of this file is specified using the <code>&lt;replace&gt;</code> attribute <i>propertyFile</i>.
  125. </p>
  126. <table border="1" cellpadding="2" cellspacing="0">
  127. <tr>
  128. <td valign="top"><b>Attribute</b></td>
  129. <td valign="top"><b>Description</b></td>
  130. <td align="center" valign="top"><b>Required</b></td>
  131. </tr>
  132. <tr>
  133. <td valign="top">token</td>
  134. <td valign="top">The string to search for.</td>
  135. <td align="center" valign="top">Yes</td>
  136. </tr>
  137. <tr>
  138. <td valign="top">value</td>
  139. <td valign="top">The replacement string.</td>
  140. <td align="center" rowspan="2">Either may be specified, but not both. Both can be omitted, if desired.</td>
  141. </tr>
  142. <tr>
  143. <td valign="top">property</td>
  144. <td valign="top">Name of the property whose value is to serve as the replacement value.</td>
  145. </tr>
  146. </table>
  147. <p>If neither <i>value</i> nor <i>property</i> is used, the value provided using the <code>&lt;replace&gt;</code> attribute <i>value</i> and/or the <code>&lt;replacevalue&gt;</code> element is used. If no value was specified using either of these options, the token is replaced with an empty string.
  148. </p>
  149. <h3>Examples</h3>
  150. <blockquote><pre>
  151. &lt;replace
  152. file=&quot;configure.sh&quot;
  153. value=&quot;defaultvalue&quot;
  154. propertyFile=&quot;source/name.properties&quot; &gt;
  155. &lt;replacefilter
  156. token=&quot;@token1@&quot; /&gt;
  157. &lt;replacefilter
  158. token=&quot;@token2@&quot;
  159. value=&quot;value2&quot;/&gt;
  160. &lt;replacefilter
  161. token=&quot;@token3@&quot;
  162. property=&quot;property.key&quot;/&gt;
  163. &lt;/replace&gt;
  164. </pre></blockquote>
  165. <p>In file <code>configure.sh</code>, replace all instances of &quot;@token1@&quot; with &quot;defaultvalue&quot;, all instances of &quot;@token2@&quot; with &quot;value2&quot;, and all instances of &quot;@token3@&quot; with the value of the property &quot;property.key&quot;, as it appears in property file <code>src/name.properties</code>.</p>
  166. <p><b>Note:</b> It is possible to use either the <i>token</i>/<code>&lt;replacetoken&gt;</code> and <i>value</i>/<code>&lt;replacevalue&gt;</code> attributes/elements, the nested replacefilter elements, or both in the same operation.
  167. </p>
  168. <hr>
  169. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  170. Reserved.</p>
  171. </body>
  172. </html>