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:
Cloneable
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 Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA enumerated type for the format attribute. -
Field Summary
Fields inherited from class ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidA set of properties to write.voidexecute()Run the task.protected voidjdkSaveProperties(Properties props, OutputStream os, String header) JDK 1.2 allows for the safer methodProperties.store(OutputStream, String), which throws anIOExceptionon an output error.protected voidsaveProperties(Hashtable<Object, Object> allProps, OutputStream os) Send the key/value pairs in the hashtable to the given output stream.voidsetDestfile(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.voidSet the output format - xml or text.voidIf the prefix is set, then only properties which start with this prefix string will be recorded.voidIf the regex is set, then only properties whose names match it will be recorded.voidsetSrcfile(File file) Sets the input file.protected voidxmlSaveProperties(Properties props, OutputStream os) Output the properties as xml output.Methods inherited from class Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeModifier and TypeMethodDescriptionfinal voidbindToOwner(Task owner) Bind a task to another; use this when configuring a newly created task to do work on behalf of another.Returns the container target of this task.Returns the wrapper used for runtime configuration.Returns the name to use in logging messages.Return the type of task.protected RuntimeConfigurableReturn the runtime configurable structure for this task.protected voidhandleErrorFlush(String output) Handles an error line by logging it with the WARN priority.protected voidhandleErrorOutput(String output) Handles an error output by logging it with the WARN priority.protected voidhandleFlush(String output) Handles output by logging it with the INFO priority.protected inthandleInput(byte[] buffer, int offset, int length) Handle an input request by this task.protected voidhandleOutput(String output) Handles output by logging it with the INFO priority.voidinit()Called by the project to let the task initialize properly.protected final booleanHas this task been marked invalid?voidLogs a message with the default (INFO) priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidConfigures this task - if it hasn't been done already.final voidperform()Performs this task if it's still valid, or gets a replacement version and performs that otherwise.voidForce the task to be reconfigured from its RuntimeConfigurable.voidsetOwningTarget(Target target) Sets the target container of this task.voidSets the wrapper to be used for runtime configuration.voidsetTaskName(String name) Sets the name to use in logging messages.voidsetTaskType(String type) Sets the name with which the task has been invoked.Methods inherited from class ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProjectModifier and TypeMethodDescriptionclone()Returns the description of the current action.Returns the file/location where this task was defined.Returns the project to which this component belongs.voidsetDescription(String desc) Sets a description of the current action.voidsetLocation(Location location) Sets the file/location where this task was defined.voidsetProject(Project project) Sets the project object of this component.
-
Constructor Details
-
EchoProperties
public EchoProperties()
-
-
Method Details
-
setSrcfile
-
setDestfile
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
-
setFailOnError
public 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, orfalseif IO exceptions are ignored.
-
setPrefix
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
-
setRegex
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
-
addPropertyset
A set of properties to write.- Parameters:
ps- the property set to write- Since:
- Ant 1.6
-
setFormat
Set the output format - xml or text.- Parameters:
ea- an enumeratedFormatAttributevalue
-
execute
Run the task.- Overrides:
executein classTask- Throws:
BuildException- trouble, probably file IO
-
saveProperties
protected void saveProperties(Hashtable<Object, Object> allProps, OutputStream os) throws 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 saveos- output stream- Throws:
IOException- on output errorsBuildException- on other errors
-
xmlSaveProperties
Output the properties as xml output.- Parameters:
props- the properties to saveos- the output stream to write to (Note this gets closed)- Throws:
IOException- on error in writing to the stream
-
jdkSaveProperties
protected void jdkSaveProperties(Properties props, OutputStream os, String header) throws IOException JDK 1.2 allows for the safer methodProperties.store(OutputStream, String), which throws anIOExceptionon an output error.- Parameters:
props- the properties to recordos- record the properties to this output streamheader- prepend this header to the property output- Throws:
IOException- on an I/O error during a write.
-