FileDocCategorySizeDatePackage
Recorder.javaAPI DocApache Ant 1.709298Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs

Recorder

public class Recorder extends org.apache.tools.ant.Task implements org.apache.tools.ant.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.

see
RecorderEntry
version
0.5
since
Ant 1.4
ant.task
name="record" category="utility"

Fields Summary
private String
filename
The name of the file to record to.
private Boolean
append
Whether or not to append. Need Boolean to record an unset state (null).
private Boolean
start
Whether to start or stop recording. Need Boolean to record an unset state (null).
private int
loglevel
The level to log at. A level of -1 means not initialized yet.
private boolean
emacsMode
Strip task banners if true.
private static Hashtable
recorderEntries
The list of recorder entries.
Constructors Summary
Methods Summary
public voidbuildFinished(org.apache.tools.ant.BuildEvent event)
Cleans recorder registry.

param
event ignored.
since
Ant 1.7

        cleanup();
    
public voidbuildStarted(org.apache.tools.ant.BuildEvent event)
Empty implementation required by SubBuildListener interface.

param
event ignored.
since
Ant 1.7

    
private voidcleanup()
cleans recorder registry and removes itself from BuildListener list.

since
Ant 1.7

        recorderEntries.clear();
        getProject().removeBuildListener(this);
    
public voidexecute()
The main execution.

throws
BuildException on error

        if (filename == null) {
            throw new BuildException("No filename specified");
        }

        getProject().log("setting a recorder for name " + filename,
            Project.MSG_DEBUG);

        // get the recorder entry
        RecorderEntry recorder = getRecorder(filename, getProject());
        // set the values on the recorder
        recorder.setMessageOutputLevel(loglevel);
        recorder.setEmacsMode(emacsMode);
        if (start != null) {
            if (start.booleanValue()) {
                recorder.reopenFile();
                recorder.setRecordState(start);
            } else {
                recorder.setRecordState(start);
                recorder.closeFile();
            }
        }
    
protected RecorderEntrygetRecorder(java.lang.String name, org.apache.tools.ant.Project proj)
Gets the recorder that's associated with the passed in name. If the recorder doesn't exist, then a new one is created.

param
name the name of the recoder
param
proj the current project
return
a recorder
throws
BuildException on error

        Object o = recorderEntries.get(name);
        RecorderEntry entry;

        if (o == null) {
            // create a recorder entry
            entry = new RecorderEntry(name);

            if (append == null) {
                entry.openFile(false);
            } else {
                entry.openFile(append.booleanValue());
            }
            entry.setProject(proj);
            recorderEntries.put(name, entry);
        } else {
            entry = (RecorderEntry) o;
        }
        return entry;
    
public voidinit()
Overridden so we can add the task as build listener.

since
Ant 1.7


    //////////////////////////////////////////////////////////////////////
    // CONSTRUCTORS / INITIALIZERS

                      
       
        getProject().addBuildListener(this);
    
public voidmessageLogged(org.apache.tools.ant.BuildEvent event)
Empty implementation required by SubBuildListener interface.

param
event ignored.
since
Ant 1.7

    
public voidsetAction(org.apache.tools.ant.taskdefs.Recorder$ActionChoices action)
Sets the action for the associated recorder entry.

param
action The action for the entry to take: start or stop.

        if (action.getValue().equalsIgnoreCase("start")) {
            start = Boolean.TRUE;
        } else {
            start = Boolean.FALSE;
        }
    
public voidsetAppend(boolean append)
Whether or not the logger should append to a previous file.

param
append if true, append to a previous file.

        this.append = (append ? Boolean.TRUE : Boolean.FALSE);
    
public voidsetEmacsMode(boolean emacsMode)
Set emacs mode.

param
emacsMode if true use emacs mode

        this.emacsMode = emacsMode;
    
public voidsetLoglevel(org.apache.tools.ant.taskdefs.Recorder$VerbosityLevelChoices level)
Sets the level to which this recorder entry should log to.

param
level the level to set.
see
VerbosityLevelChoices

        loglevel = level.getLevel();
    
public voidsetName(java.lang.String fname)
Sets the name of the file to log to, and the name of the recorder entry.

param
fname File name of logfile.

        filename = fname;
    
public voidsubBuildFinished(org.apache.tools.ant.BuildEvent event)
Cleans recorder registry, if this is the subbuild the task has been created in.

param
event ignored.
since
Ant 1.7

        if (event.getProject() == getProject()) {
            cleanup();
        }
    
public voidsubBuildStarted(org.apache.tools.ant.BuildEvent event)
Empty implementation required by SubBuildListener interface.

param
event ignored.
since
Ant 1.7

    
public voidtargetFinished(org.apache.tools.ant.BuildEvent event)
Empty implementation required by SubBuildListener interface.

param
event ignored.
since
Ant 1.7

    
public voidtargetStarted(org.apache.tools.ant.BuildEvent event)
Empty implementation required by SubBuildListener interface.

param
event ignored.
since
Ant 1.7

    
public voidtaskFinished(org.apache.tools.ant.BuildEvent event)
Empty implementation required by SubBuildListener interface.

param
event ignored.
since
Ant 1.7

    
public voidtaskStarted(org.apache.tools.ant.BuildEvent event)
Empty implementation required by SubBuildListener interface.

param
event ignored.
since
Ant 1.7