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

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

initial import of LiRK3

File size: 7.9 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<head>
19<meta http-equiv="Content-Language" content="en-us">
20<link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
21<title>PropertyFile Task</title>
22</head>
23
24<body>
25
26<h1>PropertyFile</h1>
27<p>by</p>
28<!-- Names are in alphabetical order, on last name -->
29<ul>
30 <li>Thomas Christen (<a href="mailto:[email protected]">[email protected]</a>)</li>
31 <li>Jeremy Mawson (<a href="mailto:[email protected]">[email protected]/au</a>)</li>
32</ul>
33
34<hr>
35<h2>Table of Contents</h2>
36<ul>
37 <li><a href="#introduction">Introduction</a></li>
38 <li><a href="#proptask">PropertyFile Task</a></li>
39 <li><a href="#entryElement">Entry Task</a></li>
40</ul>
41
42<hr>
43<h2><a name="introduction">Introduction</a></h2>
44<p>Ant provides an optional task for editing property files. This is very useful
45when wanting to make unattended modifications to configuration files for application
46servers and applications. Currently, the task maintains a working property file with
47the ability to add properties or make changes to existing ones. However, any comments
48are lost.</p>
49
50<hr>
51<h2><a name="proptask">PropertyFile Task</a></h2>
52<h3>Parameters</h3>
53<table border="1" cellpadding="2" cellspacing="0">
54<tr>
55 <td width="12%" valign="top"><b>Attribute</b></td>
56 <td width="78%" valign="top"><b>Description</b></td>
57 <td width="10%" valign="top"><b>Required</b></td>
58</tr>
59<tr>
60 <td width="12%" valign="top">file</td>
61 <td width="78%" valign="top">Location of the property file to be edited</td>
62 <td width="10%" valign="top">Yes</td>
63</tr>
64<tr>
65 <td width="12%" valign="top">comment</td>
66 <td width="78%" valign="top">Header for the file itself</td>
67 <td width="10%" valign="top">no</td>
68</tr>
69</table>
70
71<h3>Parameters specified as nested elements</h3>
72<h4><a name="entryElement">Entry</a></h4>
73<p>Use nested <code>&lt;entry&gt;</code>
74elements to specify actual modifications to the property file itself.</p>
75<table border="1" cellpadding="2" cellspacing="0">
76 <tr>
77 <td valign="top"><b>Attribute</b></td>
78 <td valign="top"><b>Description</b></td>
79 <td align="center" valign="top"><b>Required</b></td>
80 </tr>
81 <tr>
82 <td valign="top">key</td>
83 <td valign="top">Name of the property name/value pair</td>
84 <td valign="top" align="center">Yes</td>
85 </tr>
86 <tr>
87 <td valign="top">value</td>
88 <td valign="top">Value to set (=), to add (+) or subtract (-)</td>
89 <td valign="top" align="center" rowspan="2">At least one must be specified</td>
90 </tr>
91 <tr>
92 <td valign="top">default</td>
93 <td valign="top">Initial value to set for a property if it is not
94 already defined in the property file.<br>
95 For type date, an additional keyword is allowed: &quot;now&quot;</td>
96 </tr>
97 <tr>
98 <td valign="top">type</td>
99 <td valign="top">Regard the value as : int, date or string (default)</td>
100 <td valign="top" align="center">No</td>
101 </tr>
102 <tr>
103 <td valign="top">operation</td>
104 <td valign="top">&quot;+&quot; or &quot;=&quot; (default) for all datatypes<br>&quot;-&quot; (for date and int only).<br>
105 </td>
106 <td valign="top" align="center">No</td>
107 </tr>
108 <tr>
109 <td valign="top">pattern</td>
110 <td valign="top">For int and date type only. If present, Values will
111 be parsed and formatted accordingly.</td>
112 <td valign="top" align="center">No</td>
113 </tr>
114 <tr>
115 <td valign="top">unit</td>
116 <td valign="top">The unit of the value to be applied to date +/- operations.
117 Valid Values are:
118 <ul>
119 <li>millisecond</li>
120 <li>second</li>
121 <li>minute</li>
122 <li>hour</li>
123 <li>day (default)</li>
124 <li>week</li>
125 <li>month</li>
126 <li>year</li>
127 </ul>
128 This only applies to date types using a +/- operation.
129 </td>
130 <td align="center" valign="top">No</td>
131 </tr>
132</table>
133<p>The rules used when setting a property value are shown below.&nbsp; The
134operation occurs <b>after</b> these rules are considered.</p>
135
136<ul>
137 <li>If only value is specified, the property is set to it regardless of its
138 previous value.</li>
139 <li>If only default is specified and the property previously existed in the
140 property file, it is unchanged.</li>
141 <li>If only default is specified and the property did not exist in the
142 property file, the property is set to default.</li>
143 <li>If value and default are both specified and the property previously
144 existed in the property file, the property is set to value.</li>
145 <li>If value and default are both specified and the property did not exist in
146 the property file, the property is set to default.</li>
147</ul>
148<p>&nbsp;</p>
149
150<h3>Examples</h3>
151
152<p>The following changes the my.properties file. Assume my.properties look like:</p>
153
154<pre># A comment
155akey=novalue</pre>
156
157<p>After running, the file would now look like
158</p>
159<pre>#Thu Nov 02 23:41:47 EST 2000
160akey=avalue
161adate=2000/11/02 23\:41
162anint=1
163formated.int=0014
164formated.date=028 17\:34
165</pre>
166<p>
167The slashes conform to the expectations of the Properties class. The file will be stored in a manner so that each character is examined and escaped if necessary. Note that the original comment is now lost. Please keep this in mind when running this task against heavily commented properties files. It may be best to have a commented version in the source tree, copy it to a deployment area, and then run the modifications on the copy. Future versions of PropertyFile will hopefully eliminate this shortcoming.
168</p>
169
170<blockquote><pre>&lt;propertyfile
171 file=&quot;my.properties&quot;
172 comment=&quot;My properties&quot;&gt;
173 &lt;entry key=&quot;akey&quot; value=&quot;avalue&quot;/&gt;
174 &lt;entry key=&quot;adate&quot; type=&quot;date&quot; value=&quot;now&quot;/&gt;
175 &lt;entry key=&quot;anint&quot; type=&quot;int&quot; operation=&quot;+&quot;/&gt;
176 &lt;entry key=&quot;formated.int&quot; type=&quot;int&quot; default=&quot;0013&quot; operation=&quot;+&quot; pattern=&quot;0000&quot;/&gt;
177 &lt;entry key=&quot;formated.date&quot; type=&quot;date&quot; value=&quot;now&quot; pattern=&quot;DDD HH:mm&quot;/&gt;
178&lt;/propertyfile&gt;
179</pre></blockquote>
180<p>
181To produce dates relative from today :</p>
182<blockquote><pre>&lt;propertyfile
183 file=&quot;my.properties&quot;
184 comment=&quot;My properties&quot;&gt;
185 &lt;entry key=&quot;formated.date-1&quot;
186 type=&quot;date&quot; default=&quot;now&quot; pattern=&quot;DDD&quot;
187 operation=&quot;-&quot; value=&quot;1&quot;/&gt;
188 &lt;entry key=&quot;formated.tomorrow&quot;
189 type=&quot;date&quot; default=&quot;now&quot; pattern=&quot;DDD&quot;
190 operation=&quot;+&quot; value=&quot;1&quot;/&gt;
191&lt;/propertyfile&gt;
192</pre></blockquote>
193
194<p>
195Concatenation of strings :</p>
196<blockquote><pre>&lt;propertyfile
197 file=&quot;my.properties&quot;
198 comment=&quot;My properties&quot;&gt;
199 &lt;entry key=&quot;progress&quot; default=&quot;&quot; operation=&quot;+&quot; value=&quot;.&quot;/&gt;
200&lt;/propertyfile&gt;
201</pre></blockquote>
202<p>Each time called, a &quot;.&quot; will be appended to &quot;progress&quot;
203</p>
204
205</body>
206</html>
Note: See TracBrowser for help on using the repository browser.