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