public class Property extends Task
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:
prefix.availableProcessors
,
prefix.freeMemory
, prefix.totalMemory
and prefix.maxMemory
will be defined with values
that correspond to the corresponding methods of the Runtime
class.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.Modifier and Type | Field and Description |
---|---|
protected Path |
classpath |
protected java.lang.String |
env |
protected java.io.File |
file |
protected java.lang.String |
name |
protected java.lang.String |
prefix |
protected Reference |
ref |
protected java.lang.String |
resource |
protected java.net.URL |
url |
protected boolean |
userProperty |
protected java.lang.String |
value |
description, location, project
Modifier | Constructor and Description |
---|---|
|
Property()
Constructor for Property.
|
protected |
Property(boolean userProperty)
Constructor for Property.
|
protected |
Property(boolean userProperty,
Project fallback)
Constructor for Property.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addProperties(java.util.Properties props)
iterate through a set of properties,
resolve them then assign them
|
protected void |
addProperty(java.lang.String n,
java.lang.Object v)
add a name value pair to the project property set
|
protected void |
addProperty(java.lang.String n,
java.lang.String v)
add a name value pair to the project property set
|
void |
addText(java.lang.String msg)
Set a (multiline) property as nested text.
|
Path |
createClasspath()
The classpath to use when looking up a resource.
|
void |
execute()
set the property in the project to the value.
|
Path |
getClasspath()
Get the classpath used when looking up a resource.
|
java.lang.String |
getEnvironment()
Get the environment attribute.
|
java.io.File |
getFile()
Get the file attribute.
|
java.lang.String |
getName()
Get the property name.
|
java.lang.String |
getPrefix()
Get the prefix attribute.
|
boolean |
getPrefixValues()
Whether to apply the prefix when expanding properties on the
right hand side of a properties file as well.
|
Reference |
getRefid()
Get the refid attribute.
|
java.lang.String |
getResource()
Get the resource attribute.
|
java.lang.String |
getRuntime()
Get the runtime attribute.
|
java.net.URL |
getUrl()
Get the url attribute.
|
java.lang.String |
getValue()
Get the property value.
|
protected void |
loadEnvironment(java.lang.String prefix)
load the environment values
|
protected void |
loadFile(java.io.File file)
load properties from a file
|
protected void |
loadResource(java.lang.String name)
load properties from a resource in the current classpath
|
protected void |
loadRuntime(java.lang.String prefix)
load the runtime values
|
protected void |
loadUrl(java.net.URL url)
load properties from a url
|
void |
setBasedir(java.io.File basedir)
Sets 'basedir' attribute.
|
void |
setClasspath(Path classpath)
The classpath to use when looking up a resource.
|
void |
setClasspathRef(Reference r)
the classpath to use when looking up a resource,
given as reference to a <path> defined elsewhere
|
void |
setEnvironment(java.lang.String env)
Prefix to use when retrieving environment variables.
|
void |
setFile(java.io.File file)
Filename of a property file to load.
|
void |
setLocation(java.io.File location)
Sets the property to the absolute filename of the
given file.
|
void |
setName(java.lang.String name)
The name of the property to set.
|
void |
setPrefix(java.lang.String prefix)
Prefix to apply to properties loaded using
file
or resource . |
void |
setPrefixValues(boolean b)
Whether to apply the prefix when expanding properties on the
right hand side of a properties file as well.
|
void |
setRefid(Reference ref)
Sets a reference to an Ant datatype
declared elsewhere.
|
void |
setRelative(boolean relative)
Sets 'relative' attribute.
|
void |
setResource(java.lang.String resource)
The resource name of a property file to load
|
void |
setRuntime(java.lang.String prefix)
Prefix to use when retrieving Runtime properties.
|
void |
setUrl(java.net.URL url)
The url from which to load properties.
|
void |
setUserProperty(boolean userProperty)
Deprecated.
since 1.5.x.
This was never a supported feature and has been
deprecated without replacement.
|
void |
setValue(java.lang.Object value)
Set the value of the property.
|
void |
setValue(java.lang.String value)
Set the value of the property as a String.
|
java.lang.String |
toString()
get the value of this property
|
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
protected java.lang.String name
protected java.lang.String value
protected java.io.File file
protected java.net.URL url
protected java.lang.String resource
protected Path classpath
protected java.lang.String env
protected Reference ref
protected java.lang.String prefix
protected boolean userProperty
public Property()
protected Property(boolean userProperty)
userProperty
- if true this is a user propertyprotected Property(boolean userProperty, Project fallback)
userProperty
- if true this is a user propertyfallback
- a project to use to look for references if the reference is
not in the current projectpublic void setRelative(boolean relative)
relative
- new valuepublic void setBasedir(java.io.File basedir)
basedir
- new valuepublic void setName(java.lang.String name)
name
- property namepublic java.lang.String getName()
public void setLocation(java.io.File location)
location
- path to setpublic void setValue(java.lang.Object value)
value
- the value to use.public void setValue(java.lang.String value)
value
- value to assignpublic void addText(java.lang.String msg)
msg
- the text to append to the output textpublic java.lang.String getValue()
public void setFile(java.io.File file)
file
- filenamepublic java.io.File getFile()
public void setUrl(java.net.URL url)
url
- url stringpublic java.net.URL getUrl()
public void setPrefix(java.lang.String prefix)
file
or resource
.
A "." is appended to the prefix if not specified.prefix
- prefix stringpublic java.lang.String getPrefix()
public void setPrefixValues(boolean b)
b
- booleanpublic boolean getPrefixValues()
public void setRefid(Reference ref)
ref
- referencepublic Reference getRefid()
public void setResource(java.lang.String resource)
resource
- resource on classpathpublic java.lang.String getResource()
public void setEnvironment(java.lang.String env)
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.env
- prefixpublic java.lang.String getEnvironment()
public void setRuntime(java.lang.String prefix)
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.
prefix
- prefixpublic java.lang.String getRuntime()
public void setClasspath(Path classpath)
classpath
- to add to any existing classpathpublic Path createClasspath()
public void setClasspathRef(Reference r)
r
- a reference to a classpathpublic Path getClasspath()
@Deprecated public void setUserProperty(boolean userProperty)
userProperty
- ignoredpublic java.lang.String toString()
toString
in class java.lang.Object
public void execute() throws BuildException
execute
in class Task
BuildException
- on errorprotected void loadUrl(java.net.URL url) throws BuildException
url
- url to load fromBuildException
- on errorprotected void loadFile(java.io.File file) throws BuildException
file
- file to loadBuildException
- on errorprotected void loadResource(java.lang.String name)
name
- name of resource to loadprotected void loadEnvironment(java.lang.String prefix)
prefix
- prefix to place before themprotected void loadRuntime(java.lang.String prefix)
prefix
- prefix to place before themprotected void addProperties(java.util.Properties props)
props
- the properties to iterate overprotected void addProperty(java.lang.String n, java.lang.String v)
n
- name of propertyv
- value to setprotected void addProperty(java.lang.String n, java.lang.Object v)
n
- name of propertyv
- value to set