source: release-kits/lirk3/bin/ant-installer/web/manual/manual/CoreTasks/replace.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 8.5 KB
Line 
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
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17<html>
18
19<head>
20<meta http-equiv="Content-Language" content="en-us">
21<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
22<title>Replace Task</title>
23</head>
24
25<body>
26
27<h2><a name="replace">Replace</a></h2>
28<h3>Description</h3>
29<p>Replace is a directory based task for replacing the occurrence of a given string with another string
30in selected file.</p>
31<p>If you want to replace a text that crosses line boundaries, you
32must use a nested <code>&lt;replacetoken&gt;</code> element.</p>
33
34<p>The output file is only written if it differs from the existing
35file. This prevents spurious rebuilds based on unchanged files which
36have been regenerated by this task.</p>
37
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">file</td>
47 <td valign="top">file for which the token should be replaced.</td>
48 <td align="center" rowspan="2">Exactly one of the two.</td>
49 </tr>
50 <tr>
51 <td valign="top">dir</td>
52 <td valign="top">The base directory to use when replacing a token in
53 multiple files.</td>
54 </tr>
55 <tr>
56 <td valign="top">encoding</td>
57 <td valign="top">The encoding of the files upon which replace operates.</td>
58 <td align="center">No - defaults to default JVM encoding</td>
59 </tr>
60 <tr>
61 <td valign="top">token</td>
62 <td valign="top">the token which must be replaced.</td>
63 <td valign="top" align="center">Yes, unless a nested
64 <code>replacetoken</code> element or the replacefilterfile
65 attribute is used.</td>
66 </tr>
67 <tr>
68 <td valign="top">value</td>
69 <td valign="top">the new value for the token. When omitted, an empty string
70 (&quot;&quot;) is used.</td>
71 <td valign="top" align="center">No</td>
72 </tr>
73 <tr>
74 <td valign="top">summary</td>
75 <td valign="top">Indicates whether a summary of the replace operation
76 should be produced, detailing how many token occurrences
77 and files were processed
78 </td>
79 <td valign="top" align="center">No, by default no summary is produced</td>
80 </tr>
81 <tr>
82 <td valign="top">propertyFile</td>
83 <td valign="top">valid property file from which properties specified using nested <code>&lt;replacefilter&gt;</code> elements are drawn.</td>
84 <td valign="top" align="center">Yes only if <i>property</i> attribute of <code>&lt;replacefilter&gt;</code> is used.</td>
85 </tr>
86 <tr>
87 <td valign="top">replacefilterfile</td>
88 <td valign="top">valid property file. Each property will be
89 treated as a replacefilter where <code>token</code> is the name of
90 the property and <code>value</code> is the properties value.
91 <td valign="top" align="center">No.</td>
92 </tr>
93 <tr>
94 <td valign="top">includes</td>
95 <td valign="top">comma- or space-separated list of patterns of files that must be
96 included. All files are included when omitted.</td>
97 <td valign="top" align="center">No</td>
98 </tr>
99 <tr>
100 <td valign="top">includesfile</td>
101 <td valign="top">the name of a file. Each line of this file is
102 taken to be an include pattern</td>
103 <td valign="top" align="center">No</td>
104 </tr>
105 <tr>
106 <td valign="top">excludes</td>
107 <td valign="top">comma- or space-separated list of patterns of files that must be
108 excluded. No files (except default excludes) are excluded when omitted.</td>
109 <td valign="top" align="center">No</td>
110 </tr>
111 <tr>
112 <td valign="top">excludesfile</td>
113 <td valign="top">the name of a file. Each line of this file is
114 taken to be an exclude pattern</td>
115 <td valign="top" align="center">No</td>
116 </tr>
117 <tr>
118 <td valign="top">defaultexcludes</td>
119 <td valign="top">indicates whether default excludes should be used or not
120 (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
121 <td valign="top" align="center">No</td>
122 </tr>
123</table>
124<h3>Examples</h3>
125<pre> &lt;replace file=&quot;${src}/index.html&quot; token=&quot;@@@&quot; value=&quot;wombat&quot;/&gt;</pre>
126<p>replaces occurrences of the string &quot;@@@&quot; with the string
127&quot;wombat&quot;, in the file <code>${src}/index.html</code>.</p>
128<h3>Parameters specified as nested elements</h3>
129<p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and
130supports all attributes of <code>&lt;fileset&gt;</code> as well as the
131nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
132<code>&lt;patternset&gt;</code> elements.</p>
133<p>If either the text you want to replace or the replacement text
134cross line boundaries, you can use nested elements to specify
135them.</p>
136<h3>Examples</h3>
137<blockquote><pre>
138&lt;replace dir=&quot;${src}&quot; value=&quot;wombat&quot;&gt;
139 &lt;include name=&quot;**/*.html&quot;/&gt;
140 &lt;replacetoken&gt;&lt;![CDATA[multi line
141token]]&gt;&lt;/replacetoken&gt;
142&lt;/replace&gt;
143</pre></blockquote>
144<p>replaces occurrences of the string &quot;multi
145line<i>\n</i>token&quot; with the string &quot;wombat&quot;, in all
146HTML files in the directory <code>${src}</code>.Where <i>\n</i> is
147the platform specific line separator.</p>
148<blockquote><pre>
149&lt;replace file=&quot;${src}/index.html&quot;&gt;
150 &lt;replacetoken&gt;&lt;![CDATA[two line
151token]]&gt;&lt;/replacetoken&gt;
152 &lt;replacevalue&gt;&lt;![CDATA[two line
153token]]&gt;&lt;/replacevalue&gt;
154&lt;/replace&gt;
155</pre></blockquote>
156<h4>replacefilter</h4>
157<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>.
158</p>
159<table border="1" cellpadding="2" cellspacing="0">
160 <tr>
161 <td valign="top"><b>Attribute</b></td>
162 <td valign="top"><b>Description</b></td>
163 <td align="center" valign="top"><b>Required</b></td>
164 </tr>
165 <tr>
166 <td valign="top">token</td>
167 <td valign="top">The string to search for.</td>
168 <td align="center" valign="top">Yes</td>
169 </tr>
170 <tr>
171 <td valign="top">value</td>
172 <td valign="top">The replacement string.</td>
173 <td align="center" rowspan="2">Either may be specified, but not both. Both can be omitted, if desired.</td>
174 </tr>
175 <tr>
176 <td valign="top">property</td>
177 <td valign="top">Name of the property whose value is to serve as the replacement value.</td>
178 </tr>
179</table>
180<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.
181</p>
182<h3>Examples</h3>
183<blockquote><pre>
184&lt;replace
185 file=&quot;configure.sh&quot;
186 value=&quot;defaultvalue&quot;
187 propertyFile=&quot;source/name.properties&quot;&gt;
188 &lt;replacefilter
189 token=&quot;@token1@&quot;/&gt;
190 &lt;replacefilter
191 token=&quot;@token2@&quot;
192 value=&quot;value2&quot;/&gt;
193 &lt;replacefilter
194 token=&quot;@token3@&quot;
195 property=&quot;property.key&quot;/&gt;
196&lt;/replace&gt;
197</pre></blockquote>
198<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>
199<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.
200</p>
201
202
203</body>
204</html>
205
Note: See TracBrowser for help on using the repository browser.