source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/docs/manual/OptionalTasks/propertyfile.html@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

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