2001-02-13 12:32:01 +00:00
< html >
2000-11-06 14:10:59 +00:00
< head >
< meta http-equiv = "Content-Language" content = "en-us" >
2001-10-30 10:05:39 +00:00
< title > Apache Ant PropertyFile Task< / title >
2000-11-06 14:10:59 +00:00
< / head >
< body >
< h1 > Ant PropertyFile Task User Manual< / h1 >
< p > by< / p >
<!-- Names are in alphabetical order, on last name -->
< ul >
2001-02-04 10:40:07 +00:00
< li > Thomas Christen (< a href = "mailto:chr@active.ch" > chr@active.ch< / a > )< / li >
2000-11-06 14:10:59 +00:00
< li > Jeremy Mawson (< a href = "mailto:jem@loftinspace.com.au" > jem@loftinspace.com/au< / a > )< / li >
< / ul >
2001-02-04 10:40:07 +00:00
< p > Version 1.1 - 2001/01/28< / p >
2000-11-06 14:10:59 +00:00
< hr >
< h2 > Table of Contents< / h2 >
< ul >
< li > < a href = "#introduction" > Introduction< / a > < / li >
< li > < a href = "#proptask" > PropertyFile Task< / a > < / li >
2001-02-13 12:32:01 +00:00
< li > < a href = "#entryElement" > Entry Task< / a > < / li >
2000-11-06 14:10:59 +00:00
< / ul >
< hr >
< h2 > < a name = "introduction" > Introduction< / a > < / h2 >
2001-02-13 12:32:01 +00:00
< p > Ant provides an optional task for editing property files. This is very useful
2000-11-06 14:10:59 +00:00
when wanting to make unattended modifications to configuration files for application
servers and applications. Currently, the task maintains a working property file with
the ability to add properties or make changes to existing ones. However, any comments
2001-02-13 12:32:01 +00:00
are lost. Work is being done to make this task a bit more " human friendly" .< / p >
2000-11-06 14:10:59 +00:00
< hr >
2001-02-13 12:32:01 +00:00
< h2 > < a name = "proptask" > PropertyFile Task< / a > < / h2 >
2000-11-06 14:10:59 +00:00
< h3 > Parameters< / h3 >
< table border = "1" cellpadding = "2" cellspacing = "0" >
< tr >
< td width = "12%" valign = "top" > < b > Attribute< / b > < / td >
< td width = "78%" valign = "top" > < b > Description< / b > < / td >
< td width = "10%" valign = "top" > < b > Required< / b > < / td >
< / tr >
< tr >
< td width = "12%" valign = "top" > file< / td >
< td width = "78%" valign = "top" > Location of the property file to be edited< / td >
< td width = "10%" valign = "top" > Yes< / td >
< / tr >
< tr >
< td width = "12%" valign = "top" > comment< / td >
< td width = "78%" valign = "top" > Header for the file itself< / td >
< td width = "10%" valign = "top" > no< / td >
< / tr >
< / table >
< h3 > Parameters specified as nested elements< / h3 >
2001-02-13 12:32:01 +00:00
< h4 > < a name = "entryElement" > Entry< / a > < / h4 >
2001-02-04 10:40:07 +00:00
< p > Use nested < code > < entry> < / code >
2002-02-03 21:26:18 +00:00
elements to specify actual modifications to the property file itself.< / p >
2000-11-06 14:10:59 +00:00
< table border = "1" cellpadding = "2" cellspacing = "0" >
< tr >
< td valign = "top" > < b > Attribute< / b > < / td >
< td valign = "top" > < b > Description< / b > < / td >
< td align = "center" valign = "top" > < b > Required< / b > < / td >
< / tr >
< tr >
< td valign = "top" > key< / td >
< td valign = "top" > Name of the property name/value pair< / td >
< td valign = "top" align = "center" > Yes< / td >
< / tr >
< tr >
< td valign = "top" > value< / td >
2001-02-04 10:40:07 +00:00
< td valign = "top" > Value to set (=), to add (+) or subtract (-)< / td >
2001-10-18 10:16:18 +00:00
< td valign = "top" align = "center" rowspan = "2" > At least one must be specified< / td >
2000-11-06 14:10:59 +00:00
< / tr >
2001-10-18 10:16:18 +00:00
< tr >
< td valign = "top" > default< / td >
< td valign = "top" > Initial value to set for a property if it is not
already defined in the property file.< br >
For type date, two additional keywords are allowed: " now" or " never" .< / td >
< / tr >
2000-11-06 14:10:59 +00:00
< tr >
< td valign = "top" > type< / td >
2001-02-04 10:40:07 +00:00
< td valign = "top" > Regard the value as : int, date or string (default)< / td >
< td valign = "top" align = "center" > No< / td >
2000-11-06 14:10:59 +00:00
< / tr >
< tr >
< td valign = "top" > operation< / td >
2001-02-13 12:32:01 +00:00
< td valign = "top" > " +" or " =" (default) for all datatypes< br > " -" (for date and int only).< br >
2001-02-04 10:40:07 +00:00
< / td >
< td valign = "top" align = "center" > No< / td >
< / tr >
< tr >
< td valign = "top" > pattern< / td >
< td valign = "top" > For int and date type only. If present, Values will
2001-02-13 12:32:01 +00:00
be parsed and formatted accordingly.< / td >
2000-11-06 14:10:59 +00:00
< td valign = "top" align = "center" > No< / td >
< / tr >
< / table >
2002-02-03 21:26:18 +00:00
< p > The rules used when setting a property value are shown below. The
2001-10-18 10:16:18 +00:00
operation occurs < b > after< / b > these rules are considered.< / p >
< ul >
2002-02-03 21:26:18 +00:00
< li > If only value is specified, the property is set to it regardless of its
2001-10-18 10:16:18 +00:00
previous value.< / li >
2002-02-03 21:26:18 +00:00
< li > If only default is specified and the property previously existed in the
2001-10-18 10:16:18 +00:00
property file, it is unchanged.< / li >
2002-02-03 21:26:18 +00:00
< li > If only default is specified and the property did not exist in the
2001-10-18 10:16:18 +00:00
property file, the property is set to default.< / li >
2002-02-03 21:26:18 +00:00
< li > If value and default are both specified and the property previously
2001-10-18 10:16:18 +00:00
existed in the property file, the property is set to value.< / li >
2002-02-03 21:26:18 +00:00
< li > If value and default are both specified and the property did not exist in
2001-10-18 10:16:18 +00:00
the property file, the property is set to default.< / li >
< / ul >
< p > < / p >
2000-11-06 14:10:59 +00:00
< h3 > Examples< / h3 >
2001-02-13 12:32:01 +00:00
< p > The following changes the my.properties file. Assume my.properties look like:< / p >
< pre > # A comment
akey=novalue< / pre >
< p > After running, the file would now look like
2000-11-06 14:10:59 +00:00
< / p >
2001-02-13 12:32:01 +00:00
< pre > #Thu Nov 02 23:41:47 EST 2000
akey=avalue
adate=2000/11/02 23\:41
anint=1
formated.int=0014
formated.date=028 17\:34
< / pre >
2000-11-06 14:10:59 +00:00
< p >
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.
< / p >
2001-02-13 12:32:01 +00:00
< blockquote > < pre > < propertyfile
file=" my.properties"
comment" My properties" >
< entry key=" akey" value=" avalue" />
< entry key=" adate" type=" date" value=" now" />
< entry key=" anint" type=" int" operation=" +" />
< entry key=" formated.int" type=" int" default=" 0013" operation=" +" pattern=" 0000" />
< entry key=" formated.date" type=" date" value=" now" pattern=" DDD HH:mm" />
2000-11-06 14:10:59 +00:00
< /propertyfile>
2001-02-13 12:32:01 +00:00
< / pre > < / blockquote >
2001-02-04 10:40:07 +00:00
< p >
2001-02-13 12:32:01 +00:00
To produce dates relative from today :< / p >
< blockquote > < pre > < propertyfile
file=" my.properties"
comment=" My properties" >
< entry key=" formated.date-1"
type=" date" default=" now" pattern=" DDD"
operation=" -" value=" 1" />
< entry key=" formated.tomorrow"
type=" date" default=" now" pattern=" DDD"
operation=" +" value=" 1" />
2001-02-04 10:40:07 +00:00
< /propertyfile>
2001-02-13 12:32:01 +00:00
< / pre > < / blockquote >
2001-02-04 10:40:07 +00:00
< p >
2001-02-13 12:32:01 +00:00
Concatenation of strings :< / p >
< blockquote > < pre > < propertyfile
file=" my.properties"
comment=" My properties" >
< entry key=" progress" default=" " operation=" +" value=" ." />
2001-02-04 10:40:07 +00:00
< /propertyfile>
2001-02-13 12:32:01 +00:00
< / pre > < / blockquote >
< p > Each time called, a " ." will be appended to " progress"
2001-02-04 10:40:07 +00:00
< / p >
2002-01-10 08:48:33 +00:00
< hr >
2002-02-03 21:26:18 +00:00
< p align = "center" > Copyright © 2001-2002 Apache Software Foundation. All rights
2002-01-10 08:48:33 +00:00
Reserved.< / p >
2000-11-06 14:10:59 +00:00
< / body >
2001-10-18 10:16:18 +00:00
< / html >