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:
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 String |
env |
protected File |
file |
protected String |
name |
protected String |
prefix |
protected Reference |
ref |
protected String |
resource |
protected URL |
url |
protected boolean |
userProperty |
protected String |
value |
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(Properties props)
iterate through a set of properties,
resolve them then assign them
|
protected void |
addProperty(String n,
Object v)
add a name value pair to the project property set
|
protected void |
addProperty(String n,
String v)
add a name value pair to the project property set
|
void |
addText(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.
|
String |
getEnvironment()
Get the environment attribute.
|
File |
getFile()
Get the file attribute.
|
String |
getName()
Get the property name.
|
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.
|
String |
getResource()
Get the resource attribute.
|
URL |
getUrl()
Get the url attribute.
|
String |
getValue()
Get the property value.
|
protected void |
loadEnvironment(String prefix)
load the environment values
|
protected void |
loadFile(File file)
load properties from a file
|
protected void |
loadResource(String name)
load properties from a resource in the current classpath
|
protected void |
loadUrl(URL url)
load properties from a url
|
void |
setBasedir(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(String env)
Prefix to use when retrieving environment variables.
|
void |
setFile(File file)
Filename of a property file to load.
|
void |
setLocation(File location)
Sets the property to the absolute filename of the
given file.
|
void |
setName(String name)
The name of the property to set.
|
void |
setPrefix(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(String resource)
The resource name of a property file to load
|
void |
setUrl(URL url)
The url from which to load properties.
|
void |
setValue(Object value)
Set the value of the property.
|
void |
setValue(String value)
Set the value of the property as a String.
|
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 Path classpath
protected String env
protected File file
protected String name
protected String prefix
protected Reference ref
protected String resource
protected URL url
protected boolean userProperty
protected String value
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 projectprotected void addProperties(Properties props)
props
- the properties to iterate overprotected void addProperty(String n, Object v)
n
- name of propertyv
- value to setprotected void addProperty(String n, String v)
n
- name of propertyv
- value to setpublic void addText(String msg)
msg
- the text to append to the output textpublic Path createClasspath()
public void execute() throws BuildException
execute
in class Task
BuildException
- on errorpublic Path getClasspath()
public String getEnvironment()
public File getFile()
public String getName()
public String getPrefix()
public boolean getPrefixValues()
public Reference getRefid()
public String getResource()
public URL getUrl()
public String getValue()
protected void loadEnvironment(String prefix)
prefix
- prefix to place before themprotected void loadFile(File file) throws BuildException
file
- file to loadBuildException
- on errorprotected void loadResource(String name)
name
- name of resource to loadprotected void loadUrl(URL url) throws BuildException
url
- url to load fromBuildException
- on errorpublic void setBasedir(File basedir)
basedir
- new valuepublic void setClasspath(Path classpath)
classpath
- to add to any existing classpathpublic void setClasspathRef(Reference r)
r
- a reference to a classpathpublic void setEnvironment(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 void setFile(File file)
file
- filenamepublic void setLocation(File location)
location
- path to setpublic void setName(String name)
name
- property namepublic void setPrefix(String prefix)
file
or resource
.
A "." is appended to the prefix if not specified.prefix
- prefix stringpublic void setPrefixValues(boolean b)
public void setRefid(Reference ref)
ref
- referencepublic void setRelative(boolean relative)
relative
- new valuepublic void setResource(String resource)
resource
- resource on classpathpublic void setUrl(URL url)
url
- url stringpublic void setValue(Object value)
value
- the value to use.public void setValue(String value)
value
- value to assign