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 8.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. <hr>
  24. <h2><a name="introduction">Introduction</a></h2>
  25. <p>Ant provides an optional task for editing property files. This is very useful
  26. when wanting to make unattended modifications to configuration files for application
  27. servers and applications. Currently, the task maintains a working property file with
  28. the ability to add properties or make changes to existing ones. Comments and layout
  29. of the original properties file are preserved.</p>
  30. <hr>
  31. <h2><a name="proptask">PropertyFile Task</a></h2>
  32. <h3>Parameters</h3>
  33. <table border="1" cellpadding="2" cellspacing="0">
  34. <tr>
  35. <td width="12%" valign="top"><b>Attribute</b></td>
  36. <td width="78%" valign="top"><b>Description</b></td>
  37. <td width="10%" valign="top"><b>Required</b></td>
  38. </tr>
  39. <tr>
  40. <td width="12%" valign="top">file</td>
  41. <td width="78%" valign="top">Location of the property file to be edited</td>
  42. <td width="10%" valign="top">Yes</td>
  43. </tr>
  44. <tr>
  45. <td width="12%" valign="top">comment</td>
  46. <td width="78%" valign="top">Header for the file itself</td>
  47. <td width="10%" valign="top">no</td>
  48. </tr>
  49. <tr>
  50. <td width="12%" valign="top">jdkproperties</td>
  51. <td width="78%" valign="top">Use java.lang.Properties, which will loose comments and layout of file (default is 'false')</td>
  52. <td width="10%" valign="top">no</td>
  53. </tr>
  54. </table>
  55. <p>The boolean attribute 'jdkproperties' is provided to recover the previous behaviour of the task, in which the layout and any comments in the properties file were lost by the task.</p>
  56. <h3>Parameters specified as nested elements</h3>
  57. <h4><a name="entryElement">Entry</a></h4>
  58. <p>Use nested <code>&lt;entry&gt;</code>
  59. elements to specify actual modifications to the property file itself.</p>
  60. <table border="1" cellpadding="2" cellspacing="0">
  61. <tr>
  62. <td valign="top"><b>Attribute</b></td>
  63. <td valign="top"><b>Description</b></td>
  64. <td align="center" valign="top"><b>Required</b></td>
  65. </tr>
  66. <tr>
  67. <td valign="top">key</td>
  68. <td valign="top">Name of the property name/value pair</td>
  69. <td valign="top" align="center">Yes</td>
  70. </tr>
  71. <tr>
  72. <td valign="top">value</td>
  73. <td valign="top">Value to set (=), to add (+) or subtract (-)</td>
  74. <td valign="top" align="center" rowspan="2">At least one must be specified, if <i>operation</i> is not <i>delete</i></td>
  75. </tr>
  76. <tr>
  77. <td valign="top">default</td>
  78. <td valign="top">Initial value to set for a property if it is not
  79. already defined in the property file.<br>
  80. For type date, an additional keyword is allowed: &quot;now&quot;</td>
  81. </tr>
  82. <tr>
  83. <td valign="top">type</td>
  84. <td valign="top">Regard the value as : int, date or string (default)</td>
  85. <td valign="top" align="center">No</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">operation</td>
  89. <td valign="top">One of the following operations:<br><br>
  90. <b>for all datatypes:</b><ul>
  91. <li>&quot;del&quot; : deletes an entry</li>
  92. <li>&quot;+&quot; : adds a value to the existing value</li>
  93. <li>&quot;=&quot; : sets a value instead of the existing value (default)</li>
  94. </ul><br><b>for date and int only:</b><ul>
  95. <li>&quot;-&quot; : subtracts a value from the existing value</li>
  96. </ul>
  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 string value
  143. akey=original value
  144. # The following is a counter, which will be incremented by 1 for
  145. # each time the build is run.
  146. anint=1</pre>
  147. <p>After running, the file would now look like
  148. </p>
  149. <pre>#My properties
  150. #Wed Aug 31 13:47:19 BST 2005
  151. # A string value
  152. akey=avalue
  153. # The following is a counter, which will be incremented by 1 for
  154. # each time the build is run.
  155. anint=2
  156. adate=2005/08/31 13\:47
  157. formated.int=0014
  158. formated.date=243 13\:47</pre>
  159. <p>
  160. 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.
  161. </p>
  162. <p>
  163. The layout and comment of the original file is preserved. New properties are added at the end of the file. Existing properties are overwritten in place.
  164. </p>
  165. <blockquote><pre>&lt;propertyfile
  166. file=&quot;my.properties&quot;
  167. comment=&quot;My properties&quot;&gt;
  168. &lt;entry key=&quot;akey&quot; value=&quot;avalue&quot;/&gt;
  169. &lt;entry key=&quot;adate&quot; type=&quot;date&quot; value=&quot;now&quot;/&gt;
  170. &lt;entry key=&quot;anint&quot; type=&quot;int&quot; default=&quot;0&quot; operation=&quot;+&quot;/&gt;
  171. &lt;entry key=&quot;formated.int&quot; type=&quot;int&quot; default=&quot;0013&quot; operation=&quot;+&quot; pattern=&quot;0000&quot;/&gt;
  172. &lt;entry key=&quot;formated.date&quot; type=&quot;date&quot; value=&quot;now&quot; pattern=&quot;DDD HH:mm&quot;/&gt;
  173. &lt;/propertyfile&gt;
  174. </pre></blockquote>
  175. <p>
  176. To produce dates relative from today :</p>
  177. <blockquote><pre>&lt;propertyfile
  178. file=&quot;my.properties&quot;
  179. comment=&quot;My properties&quot;&gt;
  180. &lt;entry key=&quot;formated.date-1&quot;
  181. type=&quot;date&quot; default=&quot;now&quot; pattern=&quot;DDD&quot;
  182. operation=&quot;-&quot; value=&quot;1&quot;/&gt;
  183. &lt;entry key=&quot;formated.tomorrow&quot;
  184. type=&quot;date&quot; default=&quot;now&quot; pattern=&quot;DDD&quot;
  185. operation=&quot;+&quot; value=&quot;1&quot;/&gt;
  186. &lt;/propertyfile&gt;
  187. </pre></blockquote>
  188. <p>
  189. Concatenation of strings :</p>
  190. <blockquote><pre>&lt;propertyfile
  191. file=&quot;my.properties&quot;
  192. comment=&quot;My properties&quot;&gt;
  193. &lt;entry key=&quot;progress&quot; default=&quot;&quot; operation=&quot;+&quot; value=&quot;.&quot;/&gt;
  194. &lt;/propertyfile&gt;
  195. </pre></blockquote>
  196. <p>Each time called, a &quot;.&quot; will be appended to &quot;progress&quot;
  197. </p>
  198. </body>
  199. </html>