org.apache.tools.ant.taskdefs

Class Recorder

Implemented Interfaces:
BuildListener, Cloneable, EventListener, SubBuildListener

public class Recorder
extends Task
implements SubBuildListener

Adds a listener to the current build process that records the output to a file.

Several recorders can exist at the same time. Each recorder is associated with a file. The filename is used as a unique identifier for the recorders. The first call to the recorder task with an unused filename will create a recorder (using the parameters provided) and add it to the listeners of the build. All subsequent calls to the recorder task using this filename will modify that recorders state (recording or not) or other properties (like logging level).

Some technical issues: the file's print stream is flushed for "finished" events (buildFinished, targetFinished and taskFinished), and is closed on a buildFinished event.

Version:
0.5
Since:
Ant 1.4
See Also:
RecorderEntry

Nested Class Summary

static class
Recorder.ActionChoices
A list of possible values for the setAction() method.
static class
Recorder.VerbosityLevelChoices
A list of possible values for the setLoglevel() method.

Field Summary

Fields inherited from class org.apache.tools.ant.Task

target, taskName, taskType, wrapper

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

description, location, project

Method Summary

void
buildFinished(BuildEvent event)
Cleans recorder registry.
void
buildStarted(BuildEvent event)
Empty implementation required by SubBuildListener interface.
void
execute()
The main execution.
protected RecorderEntry
getRecorder(String name, Project proj)
Gets the recorder that's associated with the passed in name.
void
init()
Overridden so we can add the task as build listener.
void
messageLogged(BuildEvent event)
Empty implementation required by SubBuildListener interface.
void
setAction(Recorder.ActionChoices action)
Sets the action for the associated recorder entry.
void
setAppend(boolean append)
Whether or not the logger should append to a previous file.
void
setEmacsMode(boolean emacsMode)
Set emacs mode.
void
setLoglevel(Recorder.VerbosityLevelChoices level)
Sets the level to which this recorder entry should log to.
void
setName(String fname)
Sets the name of the file to log to, and the name of the recorder entry.
void
subBuildFinished(BuildEvent event)
Cleans recorder registry, if this is the subbuild the task has been created in.
void
subBuildStarted(BuildEvent event)
Empty implementation required by SubBuildListener interface.
void
targetFinished(BuildEvent event)
Empty implementation required by SubBuildListener interface.
void
targetStarted(BuildEvent event)
Empty implementation required by SubBuildListener interface.
void
taskFinished(BuildEvent event)
Empty implementation required by SubBuildListener interface.
void
taskStarted(BuildEvent event)
Empty implementation required by SubBuildListener interface.

Methods inherited from class org.apache.tools.ant.Task

bindToOwner, execute, 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.ProjectComponent

clone, getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject

Method Details

buildFinished

public void buildFinished(BuildEvent event)
Cleans recorder registry.
Specified by:
buildFinished in interface BuildListener
Parameters:
event - ignored.
Since:
Ant 1.7

buildStarted

public void buildStarted(BuildEvent event)
Empty implementation required by SubBuildListener interface.
Specified by:
buildStarted in interface BuildListener
Parameters:
event - ignored.
Since:
Ant 1.7

execute

public void execute()
            throws BuildException
The main execution.
Overrides:
execute in interface Task
Throws:
BuildException - on error

getRecorder

protected RecorderEntry getRecorder(String name,
                                    Project proj)
            throws BuildException
Gets the recorder that's associated with the passed in name. If the recorder doesn't exist, then a new one is created.
Parameters:
name - the name of the recoder
proj - the current project
Returns:
a recorder
Throws:
BuildException - on error

init

public void init()
Overridden so we can add the task as build listener.
Overrides:
init in interface Task
Since:
Ant 1.7

messageLogged

public void messageLogged(BuildEvent event)
Empty implementation required by SubBuildListener interface.
Specified by:
messageLogged in interface BuildListener
Parameters:
event - ignored.
Since:
Ant 1.7

setAction

public void setAction(Recorder.ActionChoices action)
Sets the action for the associated recorder entry.
Parameters:
action - The action for the entry to take: start or stop.

setAppend

public void setAppend(boolean append)
Whether or not the logger should append to a previous file.
Parameters:
append - if true, append to a previous file.

setEmacsMode

public void setEmacsMode(boolean emacsMode)
Set emacs mode.
Parameters:
emacsMode - if true use emacs mode

setLoglevel

public void setLoglevel(Recorder.VerbosityLevelChoices level)
Sets the level to which this recorder entry should log to.
Parameters:
level - the level to set.

setName

public void setName(String fname)
Sets the name of the file to log to, and the name of the recorder entry.
Parameters:
fname - File name of logfile.

subBuildFinished

public void subBuildFinished(BuildEvent event)
Cleans recorder registry, if this is the subbuild the task has been created in.
Specified by:
subBuildFinished in interface SubBuildListener
Parameters:
event - ignored.
Since:
Ant 1.7

subBuildStarted

public void subBuildStarted(BuildEvent event)
Empty implementation required by SubBuildListener interface.
Specified by:
subBuildStarted in interface SubBuildListener
Parameters:
event - ignored.
Since:
Ant 1.7

targetFinished

public void targetFinished(BuildEvent event)
Empty implementation required by SubBuildListener interface.
Specified by:
targetFinished in interface BuildListener
Parameters:
event - ignored.
Since:
Ant 1.7

targetStarted

public void targetStarted(BuildEvent event)
Empty implementation required by SubBuildListener interface.
Specified by:
targetStarted in interface BuildListener
Parameters:
event - ignored.
Since:
Ant 1.7

taskFinished

public void taskFinished(BuildEvent event)
Empty implementation required by SubBuildListener interface.
Specified by:
taskFinished in interface BuildListener
Parameters:
event - ignored.
Since:
Ant 1.7

taskStarted

public void taskStarted(BuildEvent event)
Empty implementation required by SubBuildListener interface.
Specified by:
taskStarted in interface BuildListener
Parameters:
event - ignored.
Since:
Ant 1.7