Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tools.ant.taskdefs.optional
Class EchoProperties

    java.lang.Object
      org.apache.tools.ant.ProjectComponent
          org.apache.tools.ant.Task
              org.apache.tools.ant.taskdefs.optional.EchoProperties

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
Author:
  Matt Albrecht groboclown@users.sourceforge.net

Field Summary

Fields inherited from class org.apache.tools.ant.Task
`description, location, target, taskName, taskType, wrapper`

Fields inherited from class org.apache.tools.ant.ProjectComponent
`project`

Constructor Summary
`EchoProperties()`

Method Summary
`void` | `execute()` Run the task.
`protected void` | `jdk10SaveProperties(java.util.Properties props, java.io.OutputStream os, java.lang.String header)` Save the properties to the output stream using the JDK 1.0 compatible method.
`protected void` | `jdkSaveProperties(java.util.Properties props, java.io.OutputStream os, java.lang.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(java.util.Hashtable allProps, java.io.OutputStream os)` Send the key/value pairs in the hashtable to the given output stream.
`void` | `setDestfile(java.io.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` | `setPrefix(java.lang.String prefix)` If the prefix is set, then only properties which start with this prefix string will be recorded.

Methods inherited from class org.apache.tools.ant.Task
`getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, handleErrorFlush, handleErrorOutput, handleFlush, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName`

Methods inherited from class org.apache.tools.ant.ProjectComponent
`getProject, setProject`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### EchoProperties

    public EchoProperties()

Method Detail

### setDestfile

    public 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

### 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` - `true` if IO exceptions are reported as build exceptions, or `false` if IO exceptions are ignored.

### setPrefix

    public void setPrefix(java.lang.String prefix)

  If the prefix is set, then only properties which start with this prefix string will be recorded. 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 property 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

### execute

    public void execute()
                 throws BuildException

  Run the task.

  Overrides:
    `execute` in class `Task`
  Throws:
    `BuildException` - trouble, probably file IO

### saveProperties

    protected void saveProperties(java.util.Hashtable allProps,
                                  java.io.OutputStream os)
                           throws java.io.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` - propfile to save
    `os` - output stream
  Throws:
    `java.io.IOException` - trouble
    `BuildException`

### jdkSaveProperties

    protected void jdkSaveProperties(java.util.Properties props,
                                     java.io.OutputStream os,
                                     java.lang.String header)
                              throws java.io.IOException

  JDK 1.2 allows for the safer method `Properties.store( OutputStream, String )`, which throws an `IOException` on an output error. This method attempts to use the JDK 1.2 method first, and if that does not exist, then the JDK 1.0 compatible method `Properties.save( OutputStream, String )` is used instead.

  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. Only thrown for JDK 1.2+.

### jdk10SaveProperties

    protected void jdk10SaveProperties(java.util.Properties props,
                                       java.io.OutputStream os,
                                       java.lang.String header)

  Save the properties to the output stream using the JDK 1.0 compatible method. This won't throw an `IOException` on 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

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.