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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>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">token</td>
  32. <td valign="top">the token which must be replaced.</td>
  33. <td valign="top" align="center">Yes, unless a nested <code>replacetoken</code>
  34. element is used.</td>
  35. </tr>
  36. <tr>
  37. <td valign="top">value</td>
  38. <td valign="top">the new value for the token. When omitted, an empty string
  39. (&quot;&quot;) is used.</td>
  40. <td valign="top" align="center">No</td>
  41. </tr>
  42. <tr>
  43. <td valign="top">propertyFile</td>
  44. <td valign="top">valid property file from which properties specified using nested <code>&lt;replacefilter&gt;</code> elements are drawn.</td>
  45. <td valign="top" align="center">Yes only if <i>property</i> attribute of <code>&lt;replacefilter&gt;</code> is used.</td>
  46. </tr>
  47. <tr>
  48. <td valign="top">includes</td>
  49. <td valign="top">comma separated list of patterns of files that must be
  50. included. All files are included when omitted.</td>
  51. <td valign="top" align="center">No</td>
  52. </tr>
  53. <tr>
  54. <td valign="top">includesfile</td>
  55. <td valign="top">the name of a file. Each line of this file is
  56. taken to be an include pattern</td>
  57. <td valign="top" align="center">No</td>
  58. </tr>
  59. <tr>
  60. <td valign="top">excludes</td>
  61. <td valign="top">comma separated list of patterns of files that must be
  62. excluded. No files (except default excludes) are excluded when omitted.</td>
  63. <td valign="top" align="center">No</td>
  64. </tr>
  65. <tr>
  66. <td valign="top">excludesfile</td>
  67. <td valign="top">the name of a file. Each line of this file is
  68. taken to be an exclude pattern</td>
  69. <td valign="top" align="center">No</td>
  70. </tr>
  71. <tr>
  72. <td valign="top">defaultexcludes</td>
  73. <td valign="top">indicates whether default excludes should be used or not
  74. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  75. <td valign="top" align="center">No</td>
  76. </tr>
  77. </table>
  78. <h3>Examples</h3>
  79. <pre> &lt;replace file=&quot;${src}/index.html&quot; token=&quot;@@@&quot; value=&quot;wombat&quot;/&gt;</pre>
  80. <p>replaces occurrences of the string &quot;@@@&quot; with the string
  81. &quot;wombat&quot;, in the file <code>${src}/index.html</code>.</p>
  82. <h3>Parameters specified as nested elements</h3>
  83. <p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
  84. supports all attributes of <code>&lt;fileset&gt;</code> as well as the
  85. nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
  86. <code>&lt;patternset&gt;</code> elements.</p>
  87. <p>If either the text you want to replace or the replacement text
  88. cross line boundaries, you can use nested elements to specify
  89. them.</p>
  90. <h3>Examples</h3>
  91. <blockquote><pre>
  92. &lt;replace dir=&quot;${src}&quot; value=&quot;wombat&quot;&gt;
  93. &lt;include name=&quot;**/*.html&quot;/&gt;
  94. &lt;replacetoken&gt;&lt;![CDATA[multi line
  95. token]]>&lt;/replacetoken&gt;
  96. &lt;/replace&gt;
  97. </pre></blockquote>
  98. <p>replaces occurrences of the string &quot;multi
  99. line<i>\n</i>token&quot; with the string &quot;wombat&quot;, in all
  100. HTML files in the directory <code>${src}</code>.Where <i>\n</i> is
  101. the platform specific line separator.</p>
  102. <blockquote><pre>
  103. &lt;replace file=&quot;${src}/index.html&quot;&gt;
  104. &lt;replacetoken&gt;&lt;![CDATA[two line
  105. token]]>&lt;/replacetoken&gt;
  106. &lt;replacevalue&gt;&lt;![CDATA[two line
  107. token]]>&lt;/replacevalue&gt;
  108. &lt;/replace&gt;
  109. </pre></blockquote>
  110. <h4>replacefilter</h4>
  111. <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>.
  112. </p>
  113. <table border="1" cellpadding="2" cellspacing="0">
  114. <tr>
  115. <td valign="top"><b>Attribute</b></td>
  116. <td valign="top"><b>Description</b></td>
  117. <td align="center" valign="top"><b>Required</b></td>
  118. </tr>
  119. <tr>
  120. <td valign="top">token</td>
  121. <td valign="top">The string to search for.</td>
  122. <td align="center" valign="top">Yes</td>
  123. </tr>
  124. <tr>
  125. <td valign="top">value</td>
  126. <td valign="top">The replacement string.</td>
  127. <td align="center" rowspan="2">Either may be specified, but not both. Both can be omitted, if desired.</td>
  128. </tr>
  129. <tr>
  130. <td valign="top">property</td>
  131. <td valign="top">Name of the property whose value is to serve as the replacement value.</td>
  132. </tr>
  133. </table>
  134. <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.
  135. </p>
  136. <h3>Examples</h3>
  137. <blockquote><pre>
  138. &lt;replace
  139. file=&quot;configure.sh&quot;
  140. value=&quot;defaultvalue&quot;
  141. propertyFile=&quot;source/name.properties&quot; &gt;
  142. &lt;replacefilter
  143. token=&quot;@token1@&quot; /&gt;
  144. &lt;replacefilter
  145. token=&quot;@token2@&quot;
  146. value=&quot;value2&quot;/&gt;
  147. &lt;replacefilter
  148. token=&quot;@token3@&quot;
  149. property=&quot;property.key&quot;/&gt;
  150. &lt;/replace&gt;
  151. </pre></blockquote>
  152. <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>
  153. <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.
  154. </p>
  155. <hr>
  156. <p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  157. Reserved.</p>
  158. </body>
  159. </html>