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.2 KiB

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