FileDocCategorySizeDatePackage
RecorderEntry.javaAPI DocApache Ant 1.7010205Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs

RecorderEntry

public class RecorderEntry extends Object implements org.apache.tools.ant.BuildLogger, org.apache.tools.ant.SubBuildListener
This is a class that represents a recorder. This is the listener to the build process.
since
Ant 1.4

Fields Summary
private String
filename
The name of the file associated with this recorder entry.
private boolean
record
The state of the recorder (recorder on or off).
private int
loglevel
The current verbosity level to record at.
private PrintStream
out
The output PrintStream to record to.
private long
targetStartTime
The start time of the last know target.
private boolean
emacsMode
Strip task banners if true.
private org.apache.tools.ant.Project
project
project instance the recorder is associated with
Constructors Summary
protected RecorderEntry(String name)

param
name The name of this recorder (used as the filename).


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

                    
       
        targetStartTime = System.currentTimeMillis();
        filename = name;
    
Methods Summary
public voidbuildFinished(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        log("< BUILD FINISHED", Project.MSG_DEBUG);

        if (record && out != null) {
            Throwable error = event.getException();

            if (error == null) {
                out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL");
            } else {
                out.println(StringUtils.LINE_SEP + "BUILD FAILED"
                            + StringUtils.LINE_SEP);
                error.printStackTrace(out);
            }
        }
        cleanup();
    
public voidbuildStarted(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        log("> BUILD STARTED", Project.MSG_DEBUG);
    
public voidcleanup()

since
1.6.2

        closeFile();
        if (project != null) {
            project.removeBuildListener(this);
        }
        project = null;
    
voidcloseFile()
Closes the file associated with this recorder. Used by Recorder.

since
1.6.3

        if (out != null) {
            out.close();
            out = null;
        }
    
private voidflush()

        if (record && out != null) {
            out.flush();
        }
    
private static java.lang.StringformatTime(long millis)

        long seconds = millis / 1000;
        long minutes = seconds / 60;


        if (minutes > 0) {
            return Long.toString(minutes) + " minute"
                 + (minutes == 1 ? " " : "s ")
                 + Long.toString(seconds % 60) + " second"
                 + (seconds % 60 == 1 ? "" : "s");
        } else {
            return Long.toString(seconds) + " second"
                 + (seconds % 60 == 1 ? "" : "s");
        }

    
public java.lang.StringgetFilename()

return
the name of the file the output is sent to.

        return filename;
    
private voidlog(java.lang.String mesg, int level)
The thing that actually sends the information to the output.

param
mesg The message to log.
param
level The verbosity level of the message.

        if (record && (level <= loglevel) && out != null) {
            out.println(mesg);
        }
    
public voidmessageLogged(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        log("--- MESSAGE LOGGED", Project.MSG_DEBUG);

        StringBuffer buf = new StringBuffer();

        if (event.getTask() != null) {
            String name = event.getTask().getTaskName();

            if (!emacsMode) {
                String label = "[" + name + "] ";
                int size = DefaultLogger.LEFT_COLUMN_SIZE - label.length();

                for (int i = 0; i < size; i++) {
                    buf.append(" ");
                }
                buf.append(label);
            }
        }
        buf.append(event.getMessage());

        log(buf.toString(), event.getPriority());
    
voidopenFile(boolean append)
Initially opens the file associated with this recorder. Used by Recorder.

param
append Indicates if output must be appended to the logfile or that the logfile should be overwritten.
throws
BuildException
since
1.6.3

        openFileImpl(append);
    
private voidopenFileImpl(boolean append)

        if (out == null) {
            try {
                out = new PrintStream(new FileOutputStream(filename, append));
            } catch (IOException ioe) {
                throw new BuildException("Problems opening file using a "
                                         + "recorder entry", ioe);
            }
        }
    
voidreopenFile()
Re-opens the file associated with this recorder. Used by Recorder.

throws
BuildException
since
1.6.3

        openFileImpl(true);
    
public voidsetEmacsMode(boolean emacsMode)
{@inheritDoc}.

        this.emacsMode = emacsMode;
    
public voidsetErrorPrintStream(java.io.PrintStream err)
{@inheritDoc}.

        setOutputPrintStream(err);
    
public voidsetMessageOutputLevel(int level)
{@inheritDoc}.

        if (level >= Project.MSG_ERR && level <= Project.MSG_DEBUG) {
            loglevel = level;
        }
    
public voidsetOutputPrintStream(java.io.PrintStream output)
{@inheritDoc}.

        closeFile();
        out = output;
    
public voidsetProject(org.apache.tools.ant.Project project)
Set the project associated with this recorder entry.

param
project the project instance
since
1.6.2

        this.project = project;
        if (project != null) {
            project.addBuildListener(this);
        }
    
public voidsetRecordState(java.lang.Boolean state)
Turns off or on this recorder.

param
state true for on, false for off, null for no change.

        if (state != null) {
            flush();
            record = state.booleanValue();
        }
    
public voidsubBuildFinished(org.apache.tools.ant.BuildEvent event)
Cleans up any resources held by this recorder entry at the end of a subbuild if it has been created for the subbuild's project instance.

param
event the buildFinished event
since
Ant 1.6.2

        if (event.getProject() == project) {
            cleanup();
        }
    
public voidsubBuildStarted(org.apache.tools.ant.BuildEvent event)
Empty implementation to satisfy the BuildListener interface.

param
event the buildStarted event
since
Ant 1.6.2

    
public voidtargetFinished(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        log("<< TARGET FINISHED -- " + event.getTarget(), Project.MSG_DEBUG);

        String time = formatTime(System.currentTimeMillis() - targetStartTime);

        log(event.getTarget() + ":  duration " + time, Project.MSG_VERBOSE);
        flush();
    
public voidtargetStarted(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        log(">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG);
        log(StringUtils.LINE_SEP + event.getTarget().getName() + ":",
            Project.MSG_INFO);
        targetStartTime = System.currentTimeMillis();
    
public voidtaskFinished(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        log("<<< TASK FINISHED -- " + event.getTask(), Project.MSG_DEBUG);
        flush();
    
public voidtaskStarted(org.apache.tools.ant.BuildEvent event)
{@inheritDoc}.

        log(">>> TASK STARTED -- " + event.getTask(), Project.MSG_DEBUG);