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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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
  26. very useful when wanting to make unattended modifications to
  27. configuration files for application servers and
  28. applications. Currently, the task maintains a working property file
  29. with the ability to add properties or make changes to existing
  30. ones. Since Ant 1.8.0 comments and layout of the original properties
  31. file are preserved.</p>
  32. <hr>
  33. <h2><a name="proptask">PropertyFile Task</a></h2>
  34. <h3>Parameters</h3>
  35. <table border="1" cellpadding="2" cellspacing="0">
  36. <tr>
  37. <td width="12%" valign="top"><b>Attribute</b></td>
  38. <td width="78%" valign="top"><b>Description</b></td>
  39. <td width="10%" valign="top"><b>Required</b></td>
  40. </tr>
  41. <tr>
  42. <td width="12%" valign="top">file</td>
  43. <td width="78%" valign="top">Location of the property file to be edited</td>
  44. <td width="10%" valign="top">Yes</td>
  45. </tr>
  46. <tr>
  47. <td width="12%" valign="top">comment</td>
  48. <td width="78%" valign="top">Header for the file itself</td>
  49. <td width="10%" valign="top">no</td>
  50. </tr>
  51. <tr>
  52. <td width="12%" valign="top">jdkproperties</td>
  53. <td width="78%" valign="top">Use java.lang.Properties, which will
  54. loose comments and layout of file (default is 'false'). <em>since
  55. Ant 1.8.0</em></td>
  56. <td width="10%" valign="top">no</td>
  57. </tr>
  58. </table>
  59. <p>The boolean attribute 'jdkproperties' is provided to recover the
  60. previous behaviour of the task, in which the layout and any comments
  61. in the properties file were lost by the task.</p>
  62. <h3>Parameters specified as nested elements</h3>
  63. <h4><a name="entryElement">Entry</a></h4>
  64. <p>Use nested <code>&lt;entry&gt;</code>
  65. elements to specify actual modifications to the property file itself.</p>
  66. <table border="1" cellpadding="2" cellspacing="0">
  67. <tr>
  68. <td valign="top"><b>Attribute</b></td>
  69. <td valign="top"><b>Description</b></td>
  70. <td align="center" valign="top"><b>Required</b></td>
  71. </tr>
  72. <tr>
  73. <td valign="top">key</td>
  74. <td valign="top">Name of the property name/value pair</td>
  75. <td valign="top" align="center">Yes</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">value</td>
  79. <td valign="top">Value to set (=), to add (+) or subtract (-)</td>
  80. <td valign="top" align="center" rowspan="2">At least one must be specified, if <i>operation</i> is not <i>delete</i></td>
  81. </tr>
  82. <tr>
  83. <td valign="top">default</td>
  84. <td valign="top">Initial value to set for a property if it is not
  85. already defined in the property file.<br>
  86. For type date, an additional keyword is allowed: &quot;now&quot;</td>
  87. </tr>
  88. <tr>
  89. <td valign="top">type</td>
  90. <td valign="top">Regard the value as : int, date or string (default)</td>
  91. <td valign="top" align="center">No</td>
  92. </tr>
  93. <tr>
  94. <td valign="top">operation</td>
  95. <td valign="top">One of the following operations:<br><br>
  96. <b>for all datatypes:</b><ul>
  97. <li>&quot;del&quot; : deletes an entry</li>
  98. <li>&quot;+&quot; : adds a value to the existing value</li>
  99. <li>&quot;=&quot; : sets a value instead of the existing value (default)</li>
  100. </ul><br><b>for date and int only:</b><ul>
  101. <li>&quot;-&quot; : subtracts a value from the existing value</li>
  102. </ul>
  103. </td>
  104. <td valign="top" align="center">No</td>
  105. </tr>
  106. <tr>
  107. <td valign="top">pattern</td>
  108. <td valign="top">For int and date type only. If present, Values will
  109. be parsed and formatted accordingly.</td>
  110. <td valign="top" align="center">No</td>
  111. </tr>
  112. <tr>
  113. <td valign="top">unit</td>
  114. <td valign="top">The unit of the value to be applied to date +/- operations.
  115. Valid Values are:
  116. <ul>
  117. <li>millisecond</li>
  118. <li>second</li>
  119. <li>minute</li>
  120. <li>hour</li>
  121. <li>day (default)</li>
  122. <li>week</li>
  123. <li>month</li>
  124. <li>year</li>
  125. </ul>
  126. This only applies to date types using a +/- operation.
  127. </td>
  128. <td align="center" valign="top">No</td>
  129. </tr>
  130. </table>
  131. <p>The rules used when setting a property value are shown below.&nbsp; The
  132. operation occurs <b>after</b> these rules are considered.</p>
  133. <ul>
  134. <li>If only value is specified, the property is set to it regardless of its
  135. previous value.</li>
  136. <li>If only default is specified and the property previously existed in the
  137. property file, it is unchanged.</li>
  138. <li>If only default is specified and the property did not exist in the
  139. property file, the property is set to default.</li>
  140. <li>If value and default are both specified and the property previously
  141. existed in the property file, the property is set to value.</li>
  142. <li>If value and default are both specified and the property did not exist in
  143. the property file, the property is set to default.</li>
  144. </ul>
  145. <p>&nbsp;</p>
  146. <h3>Examples</h3>
  147. <p>The following changes the my.properties file. Assume my.properties look like:</p>
  148. <pre># A string value
  149. akey=original value
  150. # The following is a counter, which will be incremented by 1 for
  151. # each time the build is run.
  152. anint=1</pre>
  153. <p>After running, the file would now look like
  154. </p>
  155. <pre>#My properties
  156. #Wed Aug 31 13:47:19 BST 2005
  157. # A string value
  158. akey=avalue
  159. # The following is a counter, which will be incremented by 1 for
  160. # each time the build is run.
  161. anint=2
  162. adate=2005/08/31 13\:47
  163. formated.int=0014
  164. formated.date=243 13\:47</pre>
  165. <p>
  166. 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.
  167. </p>
  168. <p>
  169. 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.
  170. </p>
  171. <blockquote><pre>&lt;propertyfile
  172. file=&quot;my.properties&quot;
  173. comment=&quot;My properties&quot;&gt;
  174. &lt;entry key=&quot;akey&quot; value=&quot;avalue&quot;/&gt;
  175. &lt;entry key=&quot;adate&quot; type=&quot;date&quot; value=&quot;now&quot;/&gt;
  176. &lt;entry key=&quot;anint&quot; type=&quot;int&quot; default=&quot;0&quot; operation=&quot;+&quot;/&gt;
  177. &lt;entry key=&quot;formated.int&quot; type=&quot;int&quot; default=&quot;0013&quot; operation=&quot;+&quot; pattern=&quot;0000&quot;/&gt;
  178. &lt;entry key=&quot;formated.date&quot; type=&quot;date&quot; value=&quot;now&quot; pattern=&quot;DDD HH:mm&quot;/&gt;
  179. &lt;/propertyfile&gt;
  180. </pre></blockquote>
  181. <p>
  182. To produce dates relative from today :</p>
  183. <blockquote><pre>&lt;propertyfile
  184. file=&quot;my.properties&quot;
  185. comment=&quot;My properties&quot;&gt;
  186. &lt;entry key=&quot;formated.date-1&quot;
  187. type=&quot;date&quot; default=&quot;now&quot; pattern=&quot;DDD&quot;
  188. operation=&quot;-&quot; value=&quot;1&quot;/&gt;
  189. &lt;entry key=&quot;formated.tomorrow&quot;
  190. type=&quot;date&quot; default=&quot;now&quot; pattern=&quot;DDD&quot;
  191. operation=&quot;+&quot; value=&quot;1&quot;/&gt;
  192. &lt;/propertyfile&gt;
  193. </pre></blockquote>
  194. <p>
  195. Concatenation 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. </body>
  205. </html>