public class EchoProperties extends Task
Attribute "destfile" defines a file to send the properties to. This can be processed as a standard property file later.
Attribute "prefix" defines a prefix which is used to filter the properties only those properties starting with this prefix will be echoed.
By default, the "failonerror" attribute is enabled. If an error occurs while writing the properties to a file, and this attribute is enabled, then a BuildException will be thrown. If disabled, then IO errors will be reported as a log statement, but no error will be thrown.
Examples:
<echoproperties />Report the current properties to the log.
<echoproperties destfile="my.properties" />Report the current properties to the file "my.properties", and will fail the build if the file could not be created or written to.
<echoproperties destfile="my.properties" failonerror="false" prefix="ant" />Report all properties beginning with 'ant' to the file "my.properties", and will log a message if the file could not be created or written to, but will still allow the build to continue.
Modifier and Type | Class and Description |
---|---|
static class |
EchoProperties.FormatAttribute
A enumerated type for the format attribute.
|
Constructor and Description |
---|
EchoProperties() |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyset(PropertySet ps)
A set of properties to write.
|
void |
execute()
Run the task.
|
protected void |
jdkSaveProperties(Properties props,
OutputStream os,
String header)
JDK 1.2 allows for the safer method
Properties.store(OutputStream, String), which throws an
IOException on an output error.
|
protected void |
saveProperties(Hashtable allProps,
OutputStream os)
Send the key/value pairs in the hashtable to the given output stream.
|
void |
setDestfile(File destfile)
Set a file to store the property output.
|
void |
setFailOnError(boolean failonerror)
If true, the task will fail if an error occurs writing the properties
file, otherwise errors are just logged.
|
void |
setFormat(EchoProperties.FormatAttribute ea)
Set the output format - xml or text.
|
void |
setPrefix(String prefix)
If the prefix is set, then only properties which start with this
prefix string will be recorded.
|
void |
setRegex(String regex)
If the regex is set, then only properties whose names match it
will be recorded.
|
void |
setSrcfile(File file)
Sets the input file.
|
protected void |
xmlSaveProperties(Properties props,
OutputStream os)
Output the properties as xml output.
|
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
public void addPropertyset(PropertySet ps)
ps
- the property set to writepublic void execute() throws BuildException
execute
in class Task
BuildException
- trouble, probably file IOprotected void jdkSaveProperties(Properties props, OutputStream os, String header) throws IOException
props
- the properties to recordos
- record the properties to this output streamheader
- prepend this header to the property outputIOException
- on an I/O error during a write.protected void saveProperties(Hashtable allProps, OutputStream os) throws IOException, BuildException
allProps
- propfile to saveos
- output streamIOException
- on output errorsBuildException
- on other errorspublic void setDestfile(File destfile)
destfile
- file to store the property outputpublic void setFailOnError(boolean failonerror)
failonerror
- true if IO exceptions are reported as build
exceptions, or false if IO exceptions are ignored.public void setFormat(EchoProperties.FormatAttribute ea)
ea
- an enumerated FormatAttribute
valuepublic void setPrefix(String prefix)
For example, if the attribute is set as:
<echoproperties prefix="ant." />then the property "ant.home" will be recorded, but "ant-example" will not.
prefix
- The new prefix valuepublic void setRegex(String regex)
For example, if the attribute is set as:
<echoproperties prefix=".*ant.*" />then the properties "ant.home" and "user.variant" will be recorded, but "ant-example" will not.
regex
- The new regex valuepublic void setSrcfile(File file)
file
- the input fileprotected void xmlSaveProperties(Properties props, OutputStream os) throws IOException
props
- the properties to saveos
- the output stream to write to (Note this gets closed)IOException
- on error in writing to the stream