Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs.optional

public Class PropertyFile

extends Task
Class Inheritance
Imports
java.io.BufferedInputStream, .ByteArrayOutputStream, .File, .IOException, .InputStream, .OutputStream, java.nio.file.Files, java.text.DateFormat, .DecimalFormat, .ParseException, .SimpleDateFormat, java.util.Calendar, .Date, .HashMap, .Map, .Properties, .Vector, org.apache.tools.ant.BuildException, .Task, org.apache.tools.ant.types.EnumeratedAttribute, org.apache.tools.ant.util.FileUtils, .LayoutPreservingProperties

Modifies settings in a property file.

The following is an example of its usage:

   <target name="setState">
     <property
       name="header"
       value="##Generated file - do not modify!"/>
     <propertyfile file="apropfile.properties" comment="${header}">
       <entry key="product.version.major" type="int"  value="5"/>
       <entry key="product.version.minor" type="int"  value="0"/>
       <entry key="product.build.major"   type="int"  value="0" />
       <entry key="product.build.minor"   type="int"  operation="+"/>
       <entry key="product.build.date"    type="date" value="now"/>
       <entry key="intSet" type="int" operation="=" value="681"/>
       <entry key="intDec" type="int" operation="-"/>
       <entry key="StringEquals" type="string" value="testValue"/>
    </propertyfile>
  </target>

The <propertyfile> task must have:

Other parameters are:

The <entry> task must have:

Other parameters are:

If type is unspecified, it defaults to string.

Parameter values:
operation:
  • "=" (set -- default)
  • "-" (dec)
  • "+" (inc)
type:
  • "int"
  • "date"
  • "string"
value:
  • holds the default value, if the property was not found in property file
  • "now" In case of type "date", the value "now" will be replaced by the current date/time and used even if a valid date was found in the property file.

String property types can only use the "=" operation. Int property types can only use the "=", "-" or "+" operations.

The message property is used for the property file header, with "\\" being a newline delimiter character.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
PropertyFile.Entry

Instance of this class represents nested elements of a task propertyfile.

public static class
PropertyFile.Unit

Borrowed from Tstamp

Field Summary

Modifier and TypeField and Description
private String
private Vector<PropertyFile.Entry>
private Properties
private File
private boolean
Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private boolean
private void
public PropertyFile.Entry

Returns:

an entry nested element to be configured.
createEntry
()

The entry nested element.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Execute the task.
private void
private void
public void
setComment(String
the string to use for the comment.
hdr
)

optional header comment for the file

public void
setFile(File
the property file.
file
)

Location of the property file to be edited; required.

public void
setJDKProperties(boolean
boolean
val
)

optional flag to use original Java properties (as opposed to layout preserving properties)

private void
Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

commentback to summary
private String comment
entriesback to summary
private Vector<PropertyFile.Entry> entries
propertiesback to summary
private Properties properties
propertyfileback to summary
private File propertyfile
useJDKPropertiesback to summary
private boolean useJDKProperties

Constructor Detail

PropertyFileback to summary
public PropertyFile()

Method Detail

checkParamback to summary
private boolean checkParam(File param)
checkParametersback to summary
private void checkParameters() throws BuildException
createEntryback to summary
public PropertyFile.Entry createEntry()

The entry nested element.

Returns:PropertyFile.Entry

an entry nested element to be configured.

executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

Execute the task.

Annotations
@Override
Exceptions
BuildException:
on error.
executeOperationback to summary
private void executeOperation() throws BuildException
readFileback to summary
private void readFile() throws BuildException
setCommentback to summary
public void setComment(String hdr)

optional header comment for the file

Parameters
hdr:String

the string to use for the comment.

setFileback to summary
public void setFile(File file)

Location of the property file to be edited; required.

Parameters
file:File

the property file.

setJDKPropertiesback to summary
public void setJDKProperties(boolean val)

optional flag to use original Java properties (as opposed to layout preserving properties)

Parameters
val:boolean

boolean

writeFileback to summary
private void writeFile() throws BuildException
org.apache.tools.ant.taskdefs.optional back to summary

public Class PropertyFile.Entry

extends Object
Class Inheritance

Instance of this class represents nested elements of a task propertyfile.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
PropertyFile.Entry.Operation

Enumerated attribute with the values "+", "-", "="

public static class
PropertyFile.Entry.Type

Enumerated attribute with the values "int", "date" and "string".

Field Summary

Modifier and TypeField and Description
private static final String
private static final int
private static final String
private String
private int
private String
private String
private int
private String
private int
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
checkParameters()

Check if parameter combinations can be supported

private void
executeDate(String
the current value read from the property file or null if the key was not contained in the property file.
oldValue
)

Handle operations for type date.

private void
executeInteger(String
the current value read from the property file or null if the key was not contained in the property file.
oldValue
)

Handle operations for type int.

protected void
executeOn(Properties
the properties to apply the entry on.
props
)

Apply the nested element to the properties.

private void
executeString(String
the current value read from the property file or null if the key was not contained in the property file.
oldValue
)

Handle operations for type string.

private String
public void
setDefault(String
the default value.
value
)

Initial value to set for a property if it is not already defined in the property file.

public void
setKey(String
the key.
value
)

Name of the property name/value pair

public void
setOperation(PropertyFile.Entry.Operation
the operation enumerated value.
value
)

operation to apply.

public void
setPattern(String
the pattern to use.
value
)

For int and date type only.

public void
setType(PropertyFile.Entry.Type
the type enumerated value.
value
)

Regard the value as : int, date or string (default)

public void
setUnit(PropertyFile.Unit
the unit enumerated value.
unit
)

The unit of the value to be applied to date +/- operations.

public void
setValue(String
the value.
value
)

Value to set (=), to add (+) or subtract (-)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_DATE_VALUEback to summary
private static final String DEFAULT_DATE_VALUE
DEFAULT_INT_VALUEback to summary
private static final int DEFAULT_INT_VALUE
DEFAULT_STRING_VALUEback to summary
private static final String DEFAULT_STRING_VALUE
defaultValueback to summary
private String defaultValue
fieldback to summary
private int field
keyback to summary
private String key
newValueback to summary
private String newValue
operationback to summary
private int operation
patternback to summary
private String pattern
typeback to summary
private int type
valueback to summary
private String value

Constructor Detail

Entryback to summary
public Entry()

Method Detail

checkParametersback to summary
private void checkParameters() throws BuildException

Check if parameter combinations can be supported

executeDateback to summary
private void executeDate(String oldValue) throws BuildException

Handle operations for type date.

Parameters
oldValue:String

the current value read from the property file or null if the key was not contained in the property file.

executeIntegerback to summary
private void executeInteger(String oldValue) throws BuildException

Handle operations for type int.

Parameters
oldValue:String

the current value read from the property file or null if the key was not contained in the property file.

executeOnback to summary
protected void executeOn(Properties props) throws BuildException

Apply the nested element to the properties.

Parameters
props:Properties

the properties to apply the entry on.

Exceptions
BuildException:
if there is an error.
executeStringback to summary
private void executeString(String oldValue) throws BuildException

Handle operations for type string.

Parameters
oldValue:String

the current value read from the property file or null if the key was not contained in the property file.

getCurrentValueback to summary
private String getCurrentValue(String oldValue)
setDefaultback to summary
public void setDefault(String value)

Initial value to set for a property if it is not already defined in the property file. For type date, an additional keyword is allowed: "now"

Parameters
value:String

the default value.

setKeyback to summary
public void setKey(String value)

Name of the property name/value pair

Parameters
value:String

the key.

setOperationback to summary
public void setOperation(PropertyFile.Entry.Operation value)

operation to apply. "+" or "=" (default) for all datatypes; "-" for date and int only)\.

Parameters
value:PropertyFile.Entry.Operation

the operation enumerated value.

setPatternback to summary
public void setPattern(String value)

For int and date type only. If present, Values will be parsed and formatted accordingly.

Parameters
value:String

the pattern to use.

setTypeback to summary
public void setType(PropertyFile.Entry.Type value)

Regard the value as : int, date or string (default)

Parameters
value:PropertyFile.Entry.Type

the type enumerated value.

setUnitback to summary
public void setUnit(PropertyFile.Unit unit)

The unit of the value to be applied to date +/- operations. Valid Values are:

  • millisecond
  • second
  • minute
  • hour
  • day (default)
  • week
  • month
  • year
This only applies to date types using a +/- operation.
Parameters
unit:PropertyFile.Unit

the unit enumerated value.

Since
Ant 1.5
setValueback to summary
public void setValue(String value)

Value to set (=), to add (+) or subtract (-)

Parameters
value:String

the value.

org.apache.tools.ant.taskdefs.optional back to summary

public Class PropertyFile.Entry.Operation

extends EnumeratedAttribute
Class Inheritance

Enumerated attribute with the values "+", "-", "="

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String[]
getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement..
public static int

Returns:

the index.
toOperation
(String
the string to convert.
oper
)

Convert string to index.

Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Field Detail

DECREMENT_OPERback to summary
public static final int DECREMENT_OPER

-

DELETE_OPERback to summary
public static final int DELETE_OPER

del

EQUALS_OPERback to summary
public static final int EQUALS_OPER

=

INCREMENT_OPERback to summary
public static final int INCREMENT_OPER

+

Constructor Detail

Operationback to summary
public Operation()

Method Detail

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Doc from org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement..

Returns:String[]

an array holding all possible values of the enumeration. The order of elements must be fixed so that indexOfValue(String) always return the same index for the same value.

Annotations
@Override
toOperationback to summary
public static int toOperation(String oper)

Convert string to index.

Parameters
oper:String

the string to convert.

Returns:int

the index.

org.apache.tools.ant.taskdefs.optional back to summary

public Class PropertyFile.Entry.Type

extends EnumeratedAttribute
Class Inheritance

Enumerated attribute with the values "int", "date" and "string".

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public
Type()

Method Summary

Modifier and TypeMethod and Description
public String[]
getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.
public static int

Returns:

the index.
toType
(String
the string to convert.
type
)

Convert string to index.

Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Field Detail

DATE_TYPEback to summary
public static final int DATE_TYPE

date

INTEGER_TYPEback to summary
public static final int INTEGER_TYPE

int

STRING_TYPEback to summary
public static final int STRING_TYPE

string

Constructor Detail

Typeback to summary
public Type()

Method Detail

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Doc from org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.

Returns:String[]

an array holding all possible values of the enumeration. The order of elements must be fixed so that indexOfValue(String) always return the same index for the same value.

Annotations
@Override
toTypeback to summary
public static int toType(String type)

Convert string to index.

Parameters
type:String

the string to convert.

Returns:int

the index.

org.apache.tools.ant.taskdefs.optional back to summary

public Class PropertyFile.Unit

extends EnumeratedAttribute
Class Inheritance

Borrowed from Tstamp
Since
Ant 1.5

Field Summary

Modifier and TypeField and Description
private Map<String, Integer>
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String[]
private static final String
private static final String
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public
Unit()

no arg constructor

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the calendar value.
getCalendarField
()

Convert the value to a Calendar field index.

public String[]
getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement..
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Field Detail

calendarFieldsback to summary
private Map<String, Integer> calendarFields
DAYback to summary
private static final String DAY
HOURback to summary
private static final String HOUR
MILLISECONDback to summary
private static final String MILLISECOND
MINUTEback to summary
private static final String MINUTE
MONTHback to summary
private static final String MONTH
SECONDback to summary
private static final String SECOND
UNITSback to summary
private static final String[] UNITS
WEEKback to summary
private static final String WEEK
YEARback to summary
private static final String YEAR

Constructor Detail

Unitback to summary
public Unit()

no arg constructor

Method Detail

getCalendarFieldback to summary
public int getCalendarField()

Convert the value to a Calendar field index.

Returns:int

the calendar value.

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Doc from org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement..

Returns:String[]

an array holding all possible values of the enumeration. The order of elements must be fixed so that indexOfValue(String) always return the same index for the same value.

Annotations
@Override