Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs.optional

public Class EchoProperties

extends Task
Class Inheritance
Imports
java.io.File, .FileNotFoundException, .IOException, .InputStream, .OutputStream, .OutputStreamWriter, .Writer, java.nio.charset.StandardCharsets, java.nio.file.Files, java.util.ArrayList, .Collections, .Comparator, .Enumeration, .Hashtable, .List, .Map, .Objects, .Properties, .Set, .TreeSet, .Vector, java.util.function.Function, java.util.stream.Collectors, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory, org.apache.tools.ant.BuildException, .Project, .Task, org.apache.tools.ant.taskdefs.LogOutputStream, org.apache.tools.ant.types.EnumeratedAttribute, .PropertySet, org.apache.tools.ant.util.DOMElementWriter, .JavaEnvUtils, org.w3c.dom.Document, .Element

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
EchoProperties.FormatAttribute

A enumerated type for the format attribute.

private static class
EchoProperties.Tuple

a tuple for the sort list.

Field Summary

Modifier and TypeField and Description
private static final String
ATTR_NAME

name attribute for property, testcase and testsuite elements.

private static final String
ATTR_VALUE

value attribute for property elements.

private File
destfile

File object pointing to the output file.

private boolean
failonerror

If this is true, then errors generated during file output will become build errors, and if false, then such errors will be logged, but not thrown.

private String
private File
inFile

the input file.

private String
private static final String
PROPERTIES

the properties element.

private static final String
PROPERTY

the property element.

private List<PropertySet>
private String
Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addPropertyset(PropertySet
the property set to write
ps
)

A set of properties to write.

private OutputStream
public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Run the task.
private static DocumentBuilder

Returns:

The DocumentBuilder instance
getDocumentBuilder
()

Uses the DocumentBuilderFactory to get a DocumentBuilder instance.

protected void
jdkSaveProperties(Properties
the properties to record
props
,
OutputStream
record the properties to this output stream
os
,
String
prepend this header to the property output
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<Object, Object>
propfile to save
allProps
,
OutputStream
output stream
os
)

Send the key/value pairs in the hashtable to the given output stream.

public void
setDestfile(File
file to store the property output
destfile
)

Set a file to store the property output.

public void
setFailOnError(boolean
true if IO exceptions are reported as build exceptions, or false if IO exceptions are ignored.
failonerror
)

If true, the task will fail if an error occurs writing the properties file, otherwise errors are just logged.

public void
setFormat(EchoProperties.FormatAttribute
an enumerated FormatAttribute value
ea
)

Set the output format - xml or text.

public void
setPrefix(String
The new prefix value
prefix
)

If the prefix is set, then only properties which start with this prefix string will be recorded.

public void
setRegex(String
The new regex value
regex
)

If the regex is set, then only properties whose names match it will be recorded.

public void
setSrcfile(File
the input file
file
)

Sets the input file.

private List<EchoProperties.Tuple>
protected void
xmlSaveProperties(Properties
the properties to save
props
,
OutputStream
the output stream to write to (Note this gets closed)
os
)

Output the properties as xml output.

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

ATTR_NAMEback to summary
private static final String ATTR_NAME

name attribute for property, testcase and testsuite elements.

ATTR_VALUEback to summary
private static final String ATTR_VALUE

value attribute for property elements.

destfileback to summary
private File destfile

File object pointing to the output file. If this is null, then we output to the project log, not to a file.

failonerrorback to summary
private boolean failonerror

If this is true, then errors generated during file output will become build errors, and if false, then such errors will be logged, but not thrown.

formatback to summary
private String format
inFileback to summary
private File inFile

the input file.

prefixback to summary
private String prefix
PROPERTIESback to summary
private static final String PROPERTIES

the properties element.

PROPERTYback to summary
private static final String PROPERTY

the property element.

propertySetsback to summary
private List<PropertySet> propertySets
regexback to summary
private String regex
Since
Ant 1.7

Constructor Detail

EchoPropertiesback to summary
public EchoProperties()

Method Detail

addPropertysetback to summary
public void addPropertyset(PropertySet ps)

A set of properties to write.

Parameters
ps:PropertySet

the property set to write

Since
Ant 1.6
createOutputStreamback to summary
private OutputStream createOutputStream() throws IOException
executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

Run the task.

Annotations
@Override
Exceptions
BuildException:
trouble, probably file IO
getDocumentBuilderback to summary
private static DocumentBuilder getDocumentBuilder()

Uses the DocumentBuilderFactory to get a DocumentBuilder instance.

Returns:DocumentBuilder

The DocumentBuilder instance

jdkSavePropertiesback to summary
protected void jdkSaveProperties(Properties props, OutputStream os, String header) throws IOException

JDK 1.2 allows for the safer method Properties.store(OutputStream, String), which throws an IOException on an output error.

Parameters
props:Properties

the properties to record

os:OutputStream

record the properties to this output stream

header:String

prepend this header to the property output

Exceptions
IOException:
on an I/O error during a write.
savePropertiesback to summary
protected void saveProperties(Hashtable<Object, Object> allProps, OutputStream os) throws IOException, BuildException

Send the key/value pairs in the hashtable to the given output stream. Only those properties matching the prefix constraint will be sent to the output stream. The output stream will be closed when this method returns.

Parameters
allProps:Hashtable<Object, Object>

propfile to save

os:OutputStream

output stream

Exceptions
IOException:
on output errors
BuildException:
on other errors
setDestfileback to summary
public void setDestfile(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

file to store the property output

setFailOnErrorback to summary
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:boolean

true if IO exceptions are reported as build exceptions, or false if IO exceptions are ignored.

setFormatback to summary
public void setFormat(EchoProperties.FormatAttribute ea)

Set the output format - xml or text.

Parameters
ea:EchoProperties.FormatAttribute

an enumerated FormatAttribute value

setPrefixback to summary
public void setPrefix(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 or null, 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:String

The new prefix value

setRegexback to summary
public void setRegex(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 or null, 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:String

The new regex value

Since
Ant 1.7
setSrcfileback to summary
public void setSrcfile(File file)

Sets the input file.

Parameters
file:File

the input file

sortPropertiesback to summary
private List<EchoProperties.Tuple> sortProperties(Properties props)
xmlSavePropertiesback to summary
protected void xmlSaveProperties(Properties props, OutputStream os) throws IOException

Output the properties as xml output.

Parameters
props:Properties

the properties to save

os:OutputStream

the output stream to write to (Note this gets closed)

Exceptions
IOException:
on error in writing to the stream
org.apache.tools.ant.taskdefs.optional back to summary

public Class EchoProperties.FormatAttribute

extends EnumeratedAttribute
Class Inheritance

A enumerated type for the format attribute. The values are "xml" and "text".

Field Summary

Modifier and TypeField and Description
private String[]
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String[]

Returns:

accepted values
getValues
()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Field Detail

formatsback to summary
private String[] formats

Constructor Detail

FormatAttributeback to summary
public FormatAttribute()

Method Detail

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

Doc from org.apache.tools.ant.types.EnumeratedAttribute.getValues.

This is the only method a subclass needs to implement.

Returns:String[]

accepted values

Annotations
@Override
See Also
EnumeratedAttribute#getValues()
org.apache.tools.ant.taskdefs.optional back to summary

private final Class EchoProperties.Tuple

extends Object
implements Comparable<EchoProperties.Tuple>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable

a tuple for the sort list.

Field Summary

Modifier and TypeField and Description
private String
private String

Constructor Summary

AccessConstructor and Description
private
Tuple(String key, String value)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
compareTo
(EchoProperties.Tuple
the Object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

keyback to summary
private String key
valueback to summary
private String value

Constructor Detail

Tupleback to summary
private Tuple(String key, String value)

Method Detail

compareToback to summary
public int compareTo(EchoProperties.Tuple o)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

Parameters
o:EchoProperties.Tuple

the Object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
Exceptions
ClassCastException:
if the specified object's type prevents it from being compared to this Object.
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override