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.

propertyfile.html 7.9 KiB

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