Class EchoProperties
- java.lang.Object
- 
- org.apache.tools.ant.ProjectComponent
- 
- org.apache.tools.ant.Task
- 
- org.apache.tools.ant.taskdefs.optional.EchoProperties
 
 
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable
 
 public class EchoProperties extends Task Displays all the current properties in the build. The output can be sent to a file if desired.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.- Since:
- Ant 1.5
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classEchoProperties.FormatAttributeA enumerated type for the format attribute.
 - 
Field Summary- 
Fields inherited from class org.apache.tools.ant.ProjectComponentdescription, location, project
 
- 
 - 
Constructor SummaryConstructors Constructor Description EchoProperties()
 - 
Method SummaryModifier and Type Method Description voidaddPropertyset(PropertySet ps)A set of properties to write.voidexecute()Run the task.protected voidjdkSaveProperties(java.util.Properties props, java.io.OutputStream os, java.lang.String header)JDK 1.2 allows for the safer methodProperties.store(OutputStream, String), which throws anIOExceptionon an output error.protected voidsaveProperties(java.util.Hashtable<java.lang.Object,java.lang.Object> allProps, java.io.OutputStream os)Send the key/value pairs in the hashtable to the given output stream.voidsetDestfile(java.io.File destfile)Set a file to store the property output.voidsetFailOnError(boolean failonerror)If true, the task will fail if an error occurs writing the properties file, otherwise errors are just logged.voidsetFormat(EchoProperties.FormatAttribute ea)Set the output format - xml or text.voidsetPrefix(java.lang.String prefix)If the prefix is set, then only properties which start with this prefix string will be recorded.voidsetRegex(java.lang.String regex)If the regex is set, then only properties whose names match it will be recorded.voidsetSrcfile(java.io.File file)Sets the input file.protected voidxmlSaveProperties(java.util.Properties props, java.io.OutputStream os)Output the properties as xml output.- 
Methods inherited from class org.apache.tools.ant.TaskbindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 - 
Methods inherited from class org.apache.tools.ant.ProjectComponentclone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
 
- 
 
- 
- 
- 
Method Detail- 
setSrcfilepublic void setSrcfile(java.io.File file) Sets the input file.- Parameters:
- file- the input file
 
 - 
setDestfilepublic void setDestfile(java.io.File destfile) Set a file to store the property output. If this is never specified, then the output will be sent to the Ant log.- Parameters:
- destfile- file to store the property output
 
 - 
setFailOnErrorpublic void setFailOnError(boolean failonerror) If true, the task will fail if an error occurs writing the properties file, otherwise errors are just logged.- Parameters:
- failonerror-- trueif IO exceptions are reported as build exceptions, or- falseif IO exceptions are ignored.
 
 - 
setPrefixpublic void setPrefix(java.lang.String prefix) If the prefix is set, then only properties which start with this prefix string will be recorded. If regex is not set and if this is never set, or it is set to an empty string ornull, then all properties will be recorded.For example, if the attribute is set as: <echoproperties prefix="ant." /> then the property "ant.home" will be recorded, but "ant-example" will not.- Parameters:
- prefix- The new prefix value
 
 - 
setRegexpublic void setRegex(java.lang.String regex) If the regex is set, then only properties whose names match it will be recorded. If prefix is not set and if this is never set, or it is set to an empty string ornull, then all properties will be recorded.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.- Parameters:
- regex- The new regex value
- Since:
- Ant 1.7
 
 - 
addPropertysetpublic void addPropertyset(PropertySet ps) A set of properties to write.- Parameters:
- ps- the property set to write
- Since:
- Ant 1.6
 
 - 
setFormatpublic void setFormat(EchoProperties.FormatAttribute ea) Set the output format - xml or text.- Parameters:
- ea- an enumerated- FormatAttributevalue
 
 - 
executepublic void execute() throws BuildExceptionRun the task.- Overrides:
- executein class- Task
- Throws:
- BuildException- trouble, probably file IO
 
 - 
savePropertiesprotected void saveProperties(java.util.Hashtable<java.lang.Object,java.lang.Object> allProps, java.io.OutputStream os) throws java.io.IOException, BuildExceptionSend the key/value pairs in the hashtable to the given output stream. Only those properties matching theprefixconstraint will be sent to the output stream. The output stream will be closed when this method returns.- Parameters:
- allProps- propfile to save
- os- output stream
- Throws:
- java.io.IOException- on output errors
- BuildException- on other errors
 
 - 
xmlSavePropertiesprotected void xmlSaveProperties(java.util.Properties props, java.io.OutputStream os) throws java.io.IOExceptionOutput the properties as xml output.- Parameters:
- props- the properties to save
- os- the output stream to write to (Note this gets closed)
- Throws:
- java.io.IOException- on error in writing to the stream
 
 - 
jdkSavePropertiesprotected void jdkSaveProperties(java.util.Properties props, java.io.OutputStream os, java.lang.String header) throws java.io.IOExceptionJDK 1.2 allows for the safer methodProperties.store(OutputStream, String), which throws anIOExceptionon an output error.- Parameters:
- props- the properties to record
- os- record the properties to this output stream
- header- prepend this header to the property output
- Throws:
- java.io.IOException- on an I/O error during a write.
 
 
- 
 
-