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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Ant PropertyFile Task</title>
  5. </head>
  6. <body>
  7. <h1>Ant PropertyFile Task User Manual</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. <p>Version 1.1 - 2001/01/28</p>
  15. <hr>
  16. <h2>Table of Contents</h2>
  17. <ul>
  18. <li><a href="#introduction">Introduction</a></li>
  19. <li><a href="#proptask">PropertyFile Task</a></li>
  20. <li><a href="#entryElement">Entry Task</a></li>
  21. </ul>
  22. <hr>
  23. <h2><a name="introduction">Introduction</a></h2>
  24. <p>Ant provides an optional task for editing property files. This is very useful
  25. when wanting to make unattended modifications to configuration files for application
  26. servers and applications. Currently, the task maintains a working property file with
  27. the ability to add properties or make changes to existing ones. However, any comments
  28. are lost. Work is being done to make this task a bit more &quot;human friendly&quot;.</p>
  29. <hr>
  30. <h2><a name="proptask">PropertyFile Task</a></h2>
  31. <h3>Parameters</h3>
  32. <table border="1" cellpadding="2" cellspacing="0">
  33. <tr>
  34. <td width="12%" valign="top"><b>Attribute</b></td>
  35. <td width="78%" valign="top"><b>Description</b></td>
  36. <td width="10%" valign="top"><b>Required</b></td>
  37. </tr>
  38. <tr>
  39. <td width="12%" valign="top">file</td>
  40. <td width="78%" valign="top">Location of the property file to be edited</td>
  41. <td width="10%" valign="top">Yes</td>
  42. </tr>
  43. <tr>
  44. <td width="12%" valign="top">comment</td>
  45. <td width="78%" valign="top">Header for the file itself</td>
  46. <td width="10%" valign="top">no</td>
  47. </tr>
  48. </table>
  49. <h3>Parameters specified as nested elements</h3>
  50. <h4><a name="entryElement">Entry</a></h4>
  51. <p>Use nested <code>&lt;entry&gt;</code>
  52. elements to specify actual modifcations to the property file itself</p>
  53. <table border="1" cellpadding="2" cellspacing="0">
  54. <tr>
  55. <td valign="top"><b>Attribute</b></td>
  56. <td valign="top"><b>Description</b></td>
  57. <td align="center" valign="top"><b>Required</b></td>
  58. </tr>
  59. <tr>
  60. <td valign="top">key</td>
  61. <td valign="top">Name of the property name/value pair</td>
  62. <td valign="top" align="center">Yes</td>
  63. </tr>
  64. <tr>
  65. <td valign="top">value</td>
  66. <td valign="top">Value to set (=), to add (+) or subtract (-)</td>
  67. <td valign="top" align="center">Yes</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">type</td>
  71. <td valign="top">Regard the value as : int, date or string (default)</td>
  72. <td valign="top" align="center">No</td>
  73. </tr>
  74. <tr>
  75. <td valign="top">operation</td>
  76. <td valign="top">&quot;+&quot; or &quot;=&quot; (default) for all datatypes<br>&quot;-&quot; (for date and int only).<br>
  77. </td>
  78. <td valign="top" align="center">No</td>
  79. </tr>
  80. <tr>
  81. <td valign="top">default</td>
  82. <td valign="top">Initial value to set for a property if it is not
  83. already defined in the property file.<br>
  84. For type date, two additional keywords are allowed: &quot;now&quot; or &quot;never&quot;.</td>
  85. <td valign="top" align="center">No</td>
  86. </tr>
  87. <tr>
  88. <td valign="top">pattern</td>
  89. <td valign="top">For int and date type only. If present, Values will
  90. be parsed and formatted accordingly.</td>
  91. <td valign="top" align="center">No</td>
  92. </tr>
  93. </table>
  94. <h3>Examples</h3>
  95. <p>The following changes the my.properties file. Assume my.properties look like:</p>
  96. <pre># A comment
  97. akey=novalue</pre>
  98. <p>After running, the file would now look like
  99. </p>
  100. <pre>#Thu Nov 02 23:41:47 EST 2000
  101. akey=avalue
  102. adate=2000/11/02 23\:41
  103. anint=1
  104. formated.int=0014
  105. formated.date=028 17\:34
  106. </pre>
  107. <p>
  108. 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.
  109. </p>
  110. <blockquote><pre>&lt;propertyfile
  111. file=&quot;my.properties&quot;
  112. comment&quot;My properties&quot; &gt;
  113. &lt;entry key=&quot;akey&quot; value=&quot;avalue&quot; /&gt;
  114. &lt;entry key=&quot;adate&quot; type=&quot;date&quot; value=&quot;now&quot;/&gt;
  115. &lt;entry key=&quot;anint&quot; type=&quot;int&quot; operation=&quot;+&quot;/&gt;
  116. &lt;entry key=&quot;formated.int&quot; type=&quot;int&quot; default=&quot;0013&quot; operation=&quot;+&quot; pattern=&quot;0000&quot;/&gt;
  117. &lt;entry key=&quot;formated.date&quot; type=&quot;date&quot; value=&quot;now&quot; pattern=&quot;DDD HH:mm&quot;/&gt;
  118. &lt;/propertyfile&gt;
  119. </pre></blockquote>
  120. <p>
  121. To produce dates relative from today :</p>
  122. <blockquote><pre>&lt;propertyfile
  123. file=&quot;my.properties&quot;
  124. comment=&quot;My properties&quot; &gt;
  125. &lt;entry key=&quot;formated.date-1&quot;
  126. type=&quot;date&quot; default=&quot;now&quot; pattern=&quot;DDD&quot;
  127. operation=&quot;-&quot; value=&quot;1&quot;/&gt;
  128. &lt;entry key=&quot;formated.tomorrow&quot;
  129. type=&quot;date&quot; default=&quot;now&quot; pattern=&quot;DDD&quot;
  130. operation=&quot;+&quot; value=&quot;1&quot;/&gt;
  131. &lt;/propertyfile&gt;
  132. </pre></blockquote>
  133. <p>
  134. Concatenation of strings :</p>
  135. <blockquote><pre>&lt;propertyfile
  136. file=&quot;my.properties&quot;
  137. comment=&quot;My properties&quot; &gt;
  138. &lt;entry key=&quot;progress&quot; default=&quot;&quot; operation=&quot;+&quot; value=&quot;.&quot;/&gt;
  139. &lt;/propertyfile&gt;
  140. </pre></blockquote>
  141. <p>Each time called, a &quot;.&quot; will be appended to &quot;progress&quot;
  142. </p>
  143. </body>
  144. </html>