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

public Class Property

extends Task
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, java.net.URL, java.nio.file.Files, java.util.HashMap, .Map, .Properties, org.apache.tools.ant.AntClassLoader, .BuildException, .Project, .PropertyHelper, .Task, org.apache.tools.ant.property.ResolvePropertyMap, org.apache.tools.ant.types.Path, .Reference, org.apache.tools.ant.util.FileUtils

Sets a property by name, or set of properties (from file or resource) in the project.

Properties are immutable: whoever sets a property first freezes it for the rest of the build; they are most definitely not variable.

There are seven ways to set properties:

Although combinations of these ways are possible, only one should be used at a time. Problems might occur with the order in which properties are set, for instance.

The value part of the properties being set, might contain references to other properties. These references are resolved at the time these properties are set. This also holds for properties loaded from a property file.

Properties are case sensitive.
Since
Ant 1.1

Field Summary

Modifier and TypeField and Description
private File
protected Path
protected String
private Project
protected File
protected String
protected String
private boolean
protected Reference
private boolean
protected String
private String
private Object
protected URL
protected boolean
protected String
private boolean
Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public
Property()

Constructor for Property.

protected
Property(boolean
if true this is a user property
userProperty
)

Constructor for Property.

protected
Property(boolean
if true this is a user property
userProperty
,
Project
a project to use to look for references if the reference is not in the current project
fallback
)

Constructor for Property.

Method Summary

Modifier and TypeMethod and Description
protected void
addProperties(Properties
the properties to iterate over
props
)

iterate through a set of properties, resolve them then assign them

protected void
addProperty(String
name of property
n
,
String
value to set
v
)

add a name value pair to the project property set

protected void
addProperty(String
name of property
n
,
Object
value to set
v
)

add a name value pair to the project property set

public void
addText(String
the text to append to the output text
msg
)

Set a (multiline) property as nested text.

public Path

Returns:

a path to be configured
createClasspath
()

The classpath to use when looking up a resource.

public void
execute()

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

set the property in the project to the value.
public Path

Returns:

the classpath
getClasspath
()

Get the classpath used when looking up a resource.

public String

Returns:

the environment attribute
getEnvironment
()

Get the environment attribute.

public File

Returns:

the file attribute
getFile
()

Get the file attribute.

public String

Returns:

the property name
getName
()

Get the property name.

public String

Returns:

the prefix attribute
getPrefix
()

Get the prefix attribute.

public boolean

Returns:

boolean
getPrefixValues
()

Whether to apply the prefix when expanding properties on the right hand side of a properties file as well.

public Reference

Returns:

the refid attribute
getRefid
()

Get the refid attribute.

public String

Returns:

the resource attribute
getResource
()

Get the resource attribute.

public String

Returns:

the runtime attribute
getRuntime
()

Get the runtime attribute.

public URL

Returns:

the url attribute
getUrl
()

Get the url attribute.

public String

Returns:

the property value
getValue
()

Get the property value.

private void
protected void
loadEnvironment(String
prefix to place before them
prefix
)

load the environment values

protected void
loadFile(File
file to load
file
)

load properties from a file

private void
loadProperties(Properties
The property object to load into
props
,
InputStream
The input stream from where to load
is
,
boolean
true if we should try to load from xml
isXml
)

Loads the properties defined in the InputStream into the given property.

protected void
loadResource(String
name of resource to load
name
)

load properties from a resource in the current classpath

protected void
loadRuntime(String
prefix to place before them
prefix
)

load the runtime values

protected void
loadUrl(URL
url to load from
url
)

load properties from a url

private void
resolveAllProperties(Map<String, Object>
properties object to resolve
props
)

resolve properties inside a properties hashtable

public void
setBasedir(File
new value
basedir
)

Sets 'basedir' attribute.

public void
setClasspath(Path
to add to any existing classpath
classpath
)

The classpath to use when looking up a resource.

public void
setClasspathRef(Reference
a reference to a classpath
r
)

the classpath to use when looking up a resource, given as reference to a <path> defined elsewhere

public void
setEnvironment(String
prefix
env
)

Prefix to use when retrieving environment variables.

public void
setFile(File
filename
file
)

Filename of a property file to load.

public void
setLocation(File
path to set
location
)

Sets the property to the absolute filename of the given file.

public void
setName(String
property name
name
)

The name of the property to set.

public void
setPrefix(String
prefix string
prefix
)

Prefix to apply to properties loaded using file or resource.

public void
setPrefixValues(boolean
boolean
b
)

Whether to apply the prefix when expanding properties on the right hand side of a properties file as well.

public void
setRefid(Reference
reference
ref
)

Sets a reference to an Ant datatype declared elsewhere.

public void
setRelative(boolean
new value
relative
)

Sets 'relative' attribute.

public void
setResource(String
resource on classpath
resource
)

The resource name of a property file to load

public void
setRuntime(String
prefix
prefix
)

Prefix to use when retrieving Runtime properties.

public void
setUrl(URL
url string
url
)

The url from which to load properties.

public void
setUserProperty(boolean
ignored
userProperty
)

Deprecated since 1.5.x. This was never a supported feature and has been deprecated without replacement.
public void
setValue(Object
the value to use.
value
)

Set the value of the property.

public void
setValue(String
value to assign
value
)

Set the value of the property as a String.

public String

Returns:

the current value or the empty string
toString
()

Overrides java.lang.Object.toString.

get the value of this property
Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

basedirback to summary
private File basedir
classpathback to summary
protected Path classpath
envback to summary
protected String env
fallbackback to summary
private Project fallback
fileback to summary
protected File file
nameback to summary
protected String name
prefixback to summary
protected String prefix
prefixValuesback to summary
private boolean prefixValues
refback to summary
protected Reference ref
relativeback to summary
private boolean relative
resourceback to summary
protected String resource
runtimeback to summary
private String runtime
untypedValueback to summary
private Object untypedValue
urlback to summary
protected URL url
userPropertyback to summary
protected boolean userProperty
valueback to summary
protected String value
valueAttributeUsedback to summary
private boolean valueAttributeUsed

Constructor Detail

Propertyback to summary
public Property()

Constructor for Property.

Propertyback to summary
protected Property(boolean userProperty)

Constructor for Property.

Parameters
userProperty:boolean

if true this is a user property

Since
Ant 1.5
Propertyback to summary
protected Property(boolean userProperty, Project fallback)

Constructor for Property.

Parameters
userProperty:boolean

if true this is a user property

fallback:Project

a project to use to look for references if the reference is not in the current project

Since
Ant 1.5

Method Detail

addPropertiesback to summary
protected void addProperties(Properties props)

iterate through a set of properties, resolve them then assign them

Parameters
props:Properties

the properties to iterate over

addPropertyback to summary
protected void addProperty(String n, String v)

add a name value pair to the project property set

Parameters
n:String

name of property

v:String

value to set

addPropertyback to summary
protected void addProperty(String n, Object v)

add a name value pair to the project property set

Parameters
n:String

name of property

v:Object

value to set

Since
Ant 1.8
addTextback to summary
public void addText(String msg)

Set a (multiline) property as nested text.

Parameters
msg:String

the text to append to the output text

Since
Ant 1.8.0
createClasspathback to summary
public Path createClasspath()

The classpath to use when looking up a resource.

Returns:Path

a path to be configured

executeback to summary
public void execute() throws BuildException

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

set the property in the project to the value. if the task was give a file, resource, env or runtime attribute here is where it is loaded

Annotations
@Override
Exceptions
BuildException:
on error
getClasspathback to summary
public Path getClasspath()

Get the classpath used when looking up a resource.

Returns:Path

the classpath

Since
Ant 1.5
getEnvironmentback to summary
public String getEnvironment()

Get the environment attribute.

Returns:String

the environment attribute

Since
Ant 1.5
getFileback to summary
public File getFile()

Get the file attribute.

Returns:File

the file attribute

getNameback to summary
public String getName()

Get the property name.

Returns:String

the property name

getPrefixback to summary
public String getPrefix()

Get the prefix attribute.

Returns:String

the prefix attribute

Since
Ant 1.5
getPrefixValuesback to summary
public boolean getPrefixValues()

Whether to apply the prefix when expanding properties on the right hand side of a properties file as well.

Returns:boolean

boolean

Since
Ant 1.8.2
getRefidback to summary
public Reference getRefid()

Get the refid attribute.

Returns:Reference

the refid attribute

getResourceback to summary
public String getResource()

Get the resource attribute.

Returns:String

the resource attribute

getRuntimeback to summary
public String getRuntime()

Get the runtime attribute.

Returns:String

the runtime attribute

Since
Ant 1.10.4
getUrlback to summary
public URL getUrl()

Get the url attribute.

Returns:URL

the url attribute

getValueback to summary
public String getValue()

Get the property value.

Returns:String

the property value

internalSetValueback to summary
private void internalSetValue(Object value)
loadEnvironmentback to summary
protected void loadEnvironment(String prefix)

load the environment values

Parameters
prefix:String

prefix to place before them

loadFileback to summary
protected void loadFile(File file) throws BuildException

load properties from a file

Parameters
file:File

file to load

Exceptions
BuildException:
on error
loadPropertiesback to summary
private void loadProperties(Properties props, InputStream is, boolean isXml) throws IOException

Loads the properties defined in the InputStream into the given property. On Java5+ it supports reading from XML based property definition.

Parameters
props:Properties

The property object to load into

is:InputStream

The input stream from where to load

isXml:boolean

true if we should try to load from xml

Exceptions
IOException:
if something goes wrong
Since
1.8.0
See Also
http://java.sun.com/dtd/properties.dtd, java.util.Properties#loadFromXML(InputStream)
loadResourceback to summary
protected void loadResource(String name)

load properties from a resource in the current classpath

Parameters
name:String

name of resource to load

loadRuntimeback to summary
protected void loadRuntime(String prefix)

load the runtime values

Parameters
prefix:String

prefix to place before them

Since
1.10.4
loadUrlback to summary
protected void loadUrl(URL url) throws BuildException

load properties from a url

Parameters
url:URL

url to load from

Exceptions
BuildException:
on error
resolveAllPropertiesback to summary
private void resolveAllProperties(Map<String, Object> props) throws BuildException

resolve properties inside a properties hashtable

Parameters
props:Map<String, Object>

properties object to resolve

setBasedirback to summary
public void setBasedir(File basedir)

Sets 'basedir' attribute.

Parameters
basedir:File

new value

Since
Ant 1.8.0
setClasspathback to summary
public void setClasspath(Path classpath)

The classpath to use when looking up a resource.

Parameters
classpath:Path

to add to any existing classpath

setClasspathRefback to summary
public void setClasspathRef(Reference r)

the classpath to use when looking up a resource, given as reference to a <path> defined elsewhere

Parameters
r:Reference

a reference to a classpath

setEnvironmentback to summary
public void setEnvironment(String env)

Prefix to use when retrieving environment variables. Thus if you specify environment="myenv" you will be able to access OS-specific environment variables via property names "myenv.PATH" or "myenv.TERM".

Note that if you supply a property name with a final "." it will not be doubled. ie environment="myenv." will still allow access of environment variables through "myenv.PATH" and "myenv.TERM". This functionality is currently only implemented on select platforms. Feel free to send patches to increase the number of platforms this functionality is supported on ;).

Note also that properties are case sensitive, even if the environment variables on your operating system are not, e.g. it will be ${env.Path} not ${env.PATH} on Windows 2000.
Parameters
env:String

prefix

setFileback to summary
public void setFile(File file)

Filename of a property file to load.

Parameters
file:File

filename

setLocationback to summary
public void setLocation(File location)

Sets the property to the absolute filename of the given file. If the value of this attribute is an absolute path, it is left unchanged (with / and \ characters converted to the current platforms conventions). Otherwise it is taken as a path relative to the project's basedir and expanded.

Parameters
location:File

path to set

setNameback to summary
public void setName(String name)

The name of the property to set.

Parameters
name:String

property name

setPrefixback to summary
public void setPrefix(String prefix)

Prefix to apply to properties loaded using file or resource. A "." is appended to the prefix if not specified.

Parameters
prefix:String

prefix string

Since
Ant 1.5
setPrefixValuesback to summary
public void setPrefixValues(boolean b)

Whether to apply the prefix when expanding properties on the right hand side of a properties file as well.

Parameters
b:boolean

boolean

Since
Ant 1.8.2
setRefidback to summary
public void setRefid(Reference ref)

Sets a reference to an Ant datatype declared elsewhere. Only yields reasonable results for references PATH like structures or properties.

Parameters
ref:Reference

reference

setRelativeback to summary
public void setRelative(boolean relative)

Sets 'relative' attribute.

Parameters
relative:boolean

new value

Since
Ant 1.8.0
setResourceback to summary
public void setResource(String resource)

The resource name of a property file to load

Parameters
resource:String

resource on classpath

setRuntimeback to summary
public void setRuntime(String prefix)

Prefix to use when retrieving Runtime properties.

Properties prefix.availableProcessors, prefix.freeMemory, prefix.totalMemory and prefix.maxMemory will be defined with values that correspond to the corresponding methods of the Runtime class.

Note that if you supply a prefix name with a final "." it will not be doubled. ie runtime="myrt." will still allow access of property through "myrt.availableProcessors" and "myrt.freeMemory".

The property values are snapshots taken at the point in time when the property has been executed.

Parameters
prefix:String

prefix

Since
Ant 1.10.4
setUrlback to summary
public void setUrl(URL url)

The url from which to load properties.

Parameters
url:URL

url string

setUserPropertyback to summary
public void setUserProperty(boolean userProperty)

Deprecated

since 1.5.x. This was never a supported feature and has been deprecated without replacement.

Parameters
userProperty:boolean

ignored

Annotations
@Deprecated
setValueback to summary
public void setValue(Object value)

Set the value of the property.

Parameters
value:Object

the value to use.

setValueback to summary
public void setValue(String value)

Set the value of the property as a String.

Parameters
value:String

value to assign

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

get the value of this property

Returns:String

the current value or the empty string

Annotations
@Override