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 five ways to set properties:
- By supplying both the name and value attribute.
- By supplying both the name and refid attribute.
- By setting the file attribute with the filename of the property
file to load. This property file has the format as defined by the file used
in the class java.util.Properties.
- By setting the resource attribute with the resource name of the
property file to load. This property file has the format as defined by the
file used in the class java.util.Properties.
- By setting the environment attribute with a prefix to use.
Properties will be defined for every environment variable by
prefixing the supplied name and a period to the name of the variable.
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.
addProperties
protected void addProperties(Properties props)
iterate through a set of properties,
resolve them then assign them
addProperty
protected void addProperty(String n,
String v)
add a name value pair to the project property set
n
- name of propertyv
- value to set
createClasspath
public Path createClasspath()
The classpath to use when looking up a resource.
execute
public void execute()
throws BuildException
set the property in the project to the value.
if the task was give a file, resource or env attribute
here is where it is loaded
- execute in interface Task
getClasspath
public Path getClasspath()
- Ant 1.5
getEnvironment
public String getEnvironment()
- Ant 1.5
getFile
public File getFile()
getName
public String getName()
getPrefix
public String getPrefix()
- Ant 1.5
getResource
public String getResource()
getUrl
public URL getUrl()
getValue
public String getValue()
loadEnvironment
protected void loadEnvironment(String prefix)
load the environment values
prefix
- prefix to place before them
loadFile
protected void loadFile(File file)
throws BuildException
load properties from a file
file
- file to load
loadResource
protected void loadResource(String name)
load properties from a resource in the current classpath
name
- name of resource to load
loadUrl
protected void loadUrl(URL url)
throws BuildException
load properties from a url
url
- url to load from
setClasspath
public void setClasspath(Path classpath)
The classpath to use when looking up a resource.
classpath
- to add to any existing classpath
setClasspathRef
public void setClasspathRef(Reference r)
the classpath to use when looking up a resource,
given as reference to a <path> defined elsewhere
setEnvironment
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.
env
- prefix
setFile
public void setFile(File file)
Filename of a property file to load.
file
- filename
setLocation
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.
location
- path to set
setName
public void setName(String name)
The name of the property to set.
name
- property name
setPrefix
public void setPrefix(String prefix)
Prefix to apply to properties loaded using file
or resource
.
A "." is appended to the prefix if not specified.
prefix
- prefix string
- Ant 1.5
setRefid
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.
ref
- reference
setResource
public void setResource(String resource)
The resource name of a property file to load
resource
- resource on classpath
setUrl
public void setUrl(URL url)
The url from which to load properties.
url
- url string
setUserProperty
public void setUserProperty(boolean userProperty)
This was never a supported feature and has been
deprecated without replacement
setValue
public void setValue(String value)
The value of the property.
value
- value to assign
toString
public String toString()
get the value of this property
- the current value or the empty string