Browse Source

Remove old BuildListener architecture and replace with ProjectListener

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270474 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
07382b400a
16 changed files with 456 additions and 904 deletions
  1. +0
    -100
      proposal/myrmidon/src/main/org/apache/tools/ant/BuildEvent.java
  2. +0
    -80
      proposal/myrmidon/src/main/org/apache/tools/ant/BuildListener.java
  3. +0
    -55
      proposal/myrmidon/src/main/org/apache/tools/ant/BuildLogger.java
  4. +2
    -7
      proposal/myrmidon/src/main/org/apache/tools/ant/Project.java
  5. +25
    -0
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/ActionChoices.java
  6. +57
    -97
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Recorder.java
  7. +118
    -113
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java
  8. +26
    -0
      proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/VerbosityLevelChoices.java
  9. +0
    -100
      proposal/myrmidon/src/todo/org/apache/tools/ant/BuildEvent.java
  10. +0
    -80
      proposal/myrmidon/src/todo/org/apache/tools/ant/BuildListener.java
  11. +0
    -55
      proposal/myrmidon/src/todo/org/apache/tools/ant/BuildLogger.java
  12. +2
    -7
      proposal/myrmidon/src/todo/org/apache/tools/ant/Project.java
  13. +25
    -0
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/ActionChoices.java
  14. +57
    -97
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Recorder.java
  15. +118
    -113
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/RecorderEntry.java
  16. +26
    -0
      proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/VerbosityLevelChoices.java

+ 0
- 100
proposal/myrmidon/src/main/org/apache/tools/ant/BuildEvent.java View File

@@ -1,100 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant;

import java.util.EventObject;

public class BuildEvent
extends EventObject
{
private int m_priority = Project.MSG_VERBOSE;
private Throwable m_exception;
private String m_message;
private String m_target;
private String m_task;

/**
* Construct a BuildEvent for a target level event
*
* @param target the target that emitted the event.
*/
public BuildEvent( String target )
{
super( target );
m_target = target;
}

public void setException( Throwable exception )
{
m_exception = exception;
}

public void setMessage( String message, int priority )
{
m_message = message;
m_priority = priority;
}

/**
* Returns the exception that was thrown, if any. This field will only be
* set for "taskFinished", "targetFinished", and "buildFinished" events.
*
* @return The Exception value
* @see BuildListener#taskFinished(BuildEvent)
* @see BuildListener#targetFinished(BuildEvent)
* @see BuildListener#buildFinished(BuildEvent)
*/
public Throwable getException()
{
return m_exception;
}

/**
* Returns the logging message. This field will only be set for
* "messageLogged" events.
*
* @return The Message value
* @see BuildListener#messageLogged(BuildEvent)
*/
public String getMessage()
{
return m_message;
}

/**
* Returns the priority of the logging message. This field will only be set
* for "messageLogged" events.
*
* @return The Priority value
* @see BuildListener#messageLogged(BuildEvent)
*/
public int getPriority()
{
return m_priority;
}

/**
* Returns the target that fired this event.
*
* @return The Target value
*/
public String getTarget()
{
return m_target;
}

/**
* Returns the task that fired this event.
*
* @return The Task value
*/
public String getTask()
{
return m_task;
}
}

+ 0
- 80
proposal/myrmidon/src/main/org/apache/tools/ant/BuildListener.java View File

@@ -1,80 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant;

import java.util.EventListener;

/**
* Classes that implement this interface will be notified when things happend
* during a build.
*
* @see BuildEvent
* @see Project#addBuildListener(BuildListener)
*/
public interface BuildListener
extends EventListener
{
/**
* Fired before any targets are started.
*
* @param event Description of Parameter
*/
void buildStarted( BuildEvent event );

/**
* Fired after the last target has finished. This event will still be thrown
* if an error occured during the build.
*
* @param event Description of Parameter
* @see BuildEvent#getException()
*/
void buildFinished( BuildEvent event );

/**
* Fired when a target is started.
*
* @param event Description of Parameter
* @see BuildEvent#getTarget()
*/
void targetStarted( BuildEvent event );

/**
* Fired when a target has finished. This event will still be thrown if an
* error occured during the build.
*
* @param event Description of Parameter
* @see BuildEvent#getException()
*/
void targetFinished( BuildEvent event );

/**
* Fired when a task is started.
*
* @param event Description of Parameter
* @see BuildEvent#getTask()
*/
void taskStarted( BuildEvent event );

/**
* Fired when a task has finished. This event will still be throw if an
* error occured during the build.
*
* @param event Description of Parameter
* @see BuildEvent#getException()
*/
void taskFinished( BuildEvent event );

/**
* Fired whenever a message is logged.
*
* @param event Description of Parameter
* @see BuildEvent#getMessage()
* @see BuildEvent#getPriority()
*/
void messageLogged( BuildEvent event );
}

+ 0
- 55
proposal/myrmidon/src/main/org/apache/tools/ant/BuildLogger.java View File

@@ -1,55 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant;

import java.io.PrintStream;

/**
* Interface used by Ant to log the build output. A build logger is a build
* listener which has the 'right' to send output to the ant log, which is
* usually System.out unles redirected by the -logfile option.
*
* @author Conor MacNeill
*/
public interface BuildLogger extends BuildListener
{
/**
* Set the msgOutputLevel this logger is to respond to. Only messages with a
* message level lower than or equal to the given level are output to the
* log. <P>
*
* Constants for the message levels are in Project.java. The order of the
* levels, from least to most verbose, is MSG_ERR, MSG_WARN, MSG_INFO,
* MSG_VERBOSE, MSG_DEBUG.
*
* @param level the logging level for the logger.
*/
void setMessageOutputLevel( int level );

/**
* Set the output stream to which this logger is to send its output.
*
* @param output the output stream for the logger.
*/
void setOutputPrintStream( PrintStream output );

/**
* Set this logger to produce emacs (and other editor) friendly output.
*
* @param emacsMode true if output is to be unadorned so that emacs and
* other editors can parse files names, etc.
*/
void setEmacsMode( boolean emacsMode );

/**
* Set the output stream to which this logger is to send error messages.
*
* @param err the error stream for the logger.
*/
void setErrorPrintStream( PrintStream err );
}

+ 2
- 7
proposal/myrmidon/src/main/org/apache/tools/ant/Project.java View File

@@ -8,15 +8,11 @@
package org.apache.tools.ant;

import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.listeners.ProjectListener;
import org.apache.tools.ant.types.FilterSet;
import org.apache.tools.ant.types.FilterSetCollection;

/**
* Central representation of an Ant project. This class defines a Ant project
@@ -125,9 +121,8 @@ public class Project
return null;
}

public void addBuildListener( BuildListener listener )
public void addProjectListener( final ProjectListener listener )
{

}

/**


+ 25
- 0
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/ActionChoices.java View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* A list of possible values for the <code>setAction()</code> method.
* Possible values include: start and stop.
*/
public class ActionChoices
extends EnumeratedAttribute
{
private final static String[] values = {"start", "stop"};

public String[] getValues()
{
return values;
}
}

+ 57
- 97
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Recorder.java View File

@@ -7,6 +7,7 @@
*/
package org.apache.tools.ant.taskdefs;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@@ -14,7 +15,6 @@ import java.util.Hashtable;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* This task is the manager for RecorderEntry's. It is this class that holds all
@@ -25,29 +25,30 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
* @version 0.5
* @see RecorderEntry
*/
public class Recorder extends Task
public class Recorder
extends Task
{
/**
* The list of recorder entries.
*/
private static Hashtable recorderEntries = new Hashtable();

//////////////////////////////////////////////////////////////////////
// ATTRIBUTES
private final static Hashtable c_recorderEntries = new Hashtable();

/**
* The name of the file to record to.
*/
private String filename = null;
private String m_filename;

/**
* Whether or not to append. Need Boolean to record an unset state (null).
*/
private Boolean append = null;
private Boolean m_append;

/**
* Whether to start or stop recording. Need Boolean to record an unset state
* (null).
*/
private Boolean start = null;
private Boolean m_start;

/**
* What level to log? -1 means not initialized yet.
*/
@@ -58,15 +59,15 @@ public class Recorder extends Task
*
* @param action The action for the entry to take: start or stop.
*/
public void setAction( ActionChoices action )
public void setAction( final ActionChoices action )
{
if( action.getValue().equalsIgnoreCase( "start" ) )
{
start = Boolean.TRUE;
m_start = Boolean.TRUE;
}
else
{
start = Boolean.FALSE;
m_start = Boolean.FALSE;
}
}

@@ -75,9 +76,9 @@ public class Recorder extends Task
*
* @param append The new Append value
*/
public void setAppend( boolean append )
public void setAppend( final boolean append )
{
this.append = new Boolean( append );
m_append = new Boolean( append );
}

/**
@@ -86,7 +87,7 @@ public class Recorder extends Task
* @param level The new Loglevel value
* @see VerbosityLevelChoices
*/
public void setLoglevel( VerbosityLevelChoices level )
public void setLoglevel( final VerbosityLevelChoices level )
{
//I hate cascading if/elseif clauses !!!
String lev = level.getValue();
@@ -112,12 +113,6 @@ public class Recorder extends Task
}
}

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

//////////////////////////////////////////////////////////////////////
// ACCESSOR METHODS

/**
* Sets the name of the file to log to, and the name of the recorder entry.
*
@@ -125,12 +120,9 @@ public class Recorder extends Task
*/
public void setName( String fname )
{
filename = fname;
m_filename = fname;
}

//////////////////////////////////////////////////////////////////////
// CORE / MAIN BODY

/**
* The main execution.
*
@@ -139,101 +131,69 @@ public class Recorder extends Task
public void execute()
throws TaskException
{
if( filename == null )
if( m_filename == null )
{
throw new TaskException( "No filename specified" );
}

getLogger().debug( "setting a recorder for name " + filename );
getLogger().debug( "setting a recorder for name " + m_filename );

// get the recorder entry
RecorderEntry recorder = getRecorder( filename, getProject() );
final RecorderEntry recorder = getRecorder( m_filename );

getProject().addProjectListener( recorder );

// set the values on the recorder
recorder.setMessageOutputLevel( loglevel );
recorder.setRecordState( start );
recorder.setLogLevel( loglevel );

if( null != m_start )
{
recorder.setRecordState( m_start.booleanValue() );
}
}

/**
* 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 Description of Parameter
* @param proj Description of Parameter
* @return The Recorder value
* @exception TaskException Description of Exception
*/
protected RecorderEntry getRecorder( String name, Project proj )
protected RecorderEntry getRecorder( final String name )
throws TaskException
{
Object o = recorderEntries.get( name );
RecorderEntry entry;
if( o == null )
final Object o = c_recorderEntries.get( name );
if( null == o )
{
// create a recorder entry
try
{
entry = new RecorderEntry( name );
PrintStream out = null;
if( append == null )
{
out = new PrintStream(
new FileOutputStream( name ) );
}
else
{
out = new PrintStream(
new FileOutputStream( name, append.booleanValue() ) );
}
entry.setErrorPrintStream( out );
entry.setOutputPrintStream( out );
}
catch( IOException ioe )
{
throw new TaskException( "Problems creating a recorder entry",
ioe );
}
proj.addBuildListener( entry );
recorderEntries.put( name, entry );
return (RecorderEntry)o;
}
else

// create a recorder entry
try
{
entry = (RecorderEntry)o;
final PrintStream output = createOutput( name );
final RecorderEntry entry = new RecorderEntry( output );
c_recorderEntries.put( name, entry );
return entry;
}
return entry;
}

//////////////////////////////////////////////////////////////////////
// INNER CLASSES

/**
* A list of possible values for the <code>setAction()</code> method.
* Possible values include: start and stop.
*
* @author RT
*/
public static class ActionChoices extends EnumeratedAttribute
{
private final static String[] values = {"start", "stop"};

public String[] getValues()
catch( final IOException ioe )
{
return values;
throw new TaskException( "Problems creating a recorder entry",
ioe );
}
}

/**
* A list of possible values for the <code>setLoglevel()</code> method.
* Possible values include: error, warn, info, verbose, debug.
*
* @author RT
*/
public static class VerbosityLevelChoices extends EnumeratedAttribute
private PrintStream createOutput( final String name )
throws FileNotFoundException
{
private final static String[] values = {"error", "warn", "info",
"verbose", "debug"};

public String[] getValues()
FileOutputStream outputStream = null;
if( m_append == null )
{
return values;
outputStream = new FileOutputStream( name );
}
else
{
outputStream = new FileOutputStream( name, m_append.booleanValue() );
}
}

final PrintStream out = new PrintStream( outputStream );
return out;
}
}

+ 118
- 113
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java View File

@@ -8,9 +8,10 @@
package org.apache.tools.ant.taskdefs;

import java.io.PrintStream;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildLogger;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.excalibur.util.StringUtil;
import org.apache.myrmidon.listeners.AbstractProjectListener;
import org.apache.tools.ant.Project;

/**
@@ -18,50 +19,54 @@ import org.apache.tools.ant.Project;
* process.
*
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
* @version 0.5
*/
public class RecorderEntry
extends AbstractLogEnabled
implements BuildLogger
extends AbstractProjectListener
implements LogEnabled
{
/**
* the line separator for this OS
*/
private final static String LINE_SEP = System.getProperty( "line.separator" );

//////////////////////////////////////////////////////////////////////
// ATTRIBUTES

/**
* The name of the file associated with this recorder entry.
*/
private String filename = null;
/**
* The state of the recorder (recorder on or off).
*/
private boolean record = true;
private boolean m_record;

/**
* The current verbosity level to record at.
*/
private int loglevel = Project.MSG_INFO;
private int m_loglevel = Project.MSG_INFO;

/**
* The output PrintStream to record to.
*/
private PrintStream out = null;
private final PrintStream m_output;

/**
* The start time of the last know target.
*/
private long targetStartTime = 0l;
private long m_targetStartTime = 0l;

//////////////////////////////////////////////////////////////////////
// CONSTRUCTORS / INITIALIZERS
private Logger m_logger;

/**
* @param name The name of this recorder (used as the filename).
*/
protected RecorderEntry( String name )
protected RecorderEntry( final PrintStream output )
{
m_output = output;
}

/**
* Provide component with a logger.
*
* @param logger the logger
*/
public void enableLogging( final Logger logger )
{
filename = name;
m_logger = logger;
}

protected final Logger getLogger()
{
return m_logger;
}

private static String formatTime( long millis )
@@ -71,38 +76,18 @@ public class RecorderEntry

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

}

public void setEmacsMode( boolean emacsMode )
{
throw new java.lang.RuntimeException( "Method setEmacsMode() not yet implemented." );
}

public void setErrorPrintStream( PrintStream err )
public void setLogLevel( final int loglevel )
{
out = err;
}

public void setMessageOutputLevel( int level )
{
if( level >= Project.MSG_ERR && level <= Project.MSG_DEBUG )
loglevel = level;
}

public void setOutputPrintStream( PrintStream output )
{
out = output;
m_loglevel = loglevel;
}

/**
@@ -110,105 +95,125 @@ public class RecorderEntry
*
* @param state true for on, false for off, null for no change.
*/
public void setRecordState( Boolean state )
public void setRecordState( final boolean record )
{
if( state != null )
record = state.booleanValue();
m_record = record;
}

//////////////////////////////////////////////////////////////////////
// ACCESSOR METHODS
/**
* Notify listener of log message event.
*
* @param message the message
* @param throwable the throwable
*/
public void log( final String message, final Throwable throwable )
{
m_output.println( StringUtil.LINE_SEPARATOR + "BUILD FAILED" + StringUtil.LINE_SEPARATOR );
throwable.printStackTrace( m_output );
finishRecording();
}

/**
* @return the name of the file the output is sent to.
* Notify listener of projectFinished event.
*/
public String getFilename()
public void projectFinished()
{
return filename;
m_output.println( StringUtil.LINE_SEPARATOR + "BUILD SUCCESSFUL" );
finishRecording();
}

public void buildFinished( BuildEvent event )
private void finishRecording()
{
getLogger().debug( "< BUILD FINISHED" );

Throwable error = event.getException();
if( error == null )
{
out.println( LINE_SEP + "BUILD SUCCESSFUL" );
}
else
{
out.println( LINE_SEP + "BUILD FAILED" + LINE_SEP );
error.printStackTrace( out );
}
out.flush();
out.close();
m_output.flush();
m_output.close();
}

public void buildStarted( BuildEvent event )
/**
* Notify listener of projectStarted event.
*/
public void projectStarted()
{
getLogger().debug( "> BUILD STARTED" );
}

public void messageLogged( BuildEvent event )
/**
* Notify listener of log message event.
*
* @param message the message
*/
public void log( final String message )
{
getLogger().debug( "--- MESSAGE LOGGED" );

StringBuffer buf = new StringBuffer();
if( event.getTask() != null )
final StringBuffer sb = new StringBuffer();

final String task = getTask();
if( task != null )
{
String name = "[" + event.getTask() + "]";
/**
* @todo replace 12 with DefaultLogger.LEFT_COLUMN_SIZE
*/
for( int i = 0; i < ( 12 - name.length() ); i++ )
final String name = "[" + task + "]";
final int padding = 12 - name.length();
for( int i = 0; i < padding; i++ )
{
buf.append( " " );
}// for
buf.append( name );
}// if
buf.append( event.getMessage() );
sb.append( " " );
}
sb.append( name );
}

log( buf.toString(), event.getPriority() );
}
sb.append( message );

public void targetFinished( BuildEvent event )
{
getLogger().debug( "<< TARGET FINISHED -- " + event.getTarget() );
String time = formatTime( System.currentTimeMillis() - targetStartTime );
getLogger().debug( event.getTarget() + ": duration " + time );
out.flush();
//FIXME: Check log level here
if( m_record )
{
m_output.println( sb.toString() );
}
}

public void targetStarted( final BuildEvent event )
/**
* Notify listener of targetFinished event.
*/
public void targetFinished()
{
getLogger().debug( ">> TARGET STARTED -- " + event.getTarget() );
getLogger().info( LINE_SEP + event.getTarget() + ":" );
targetStartTime = System.currentTimeMillis();
getLogger().debug( "<< TARGET FINISHED -- " + getTarget() );
final long millis = System.currentTimeMillis() - m_targetStartTime;
final String duration = formatTime( millis );
getLogger().debug( getTarget() + ": duration " + duration );
m_output.flush();
super.targetFinished();
}

public void taskFinished( BuildEvent event )
/**
* Notify listener of targetStarted event.
*
* @param target the name of target
*/
public void targetStarted( final String target )
{
getLogger().debug( "<<< TASK FINISHED -- " + event.getTask() );
out.flush();
super.targetStarted( target );
getLogger().debug( ">> TARGET STARTED -- " + getTarget() );
getLogger().info( StringUtil.LINE_SEPARATOR + getTarget() + ":" );
m_targetStartTime = System.currentTimeMillis();

}

public void taskStarted( BuildEvent event )
/**
* Notify listener of taskStarted event.
*
* @param task the name of task
*/
public void taskStarted( String task )
{
getLogger().debug( ">>> TASK STARTED -- " + event.getTask() );
super.taskStarted( task );
getLogger().debug( ">>> TASK STARTED -- " + getTask() );
}

/**
* The thing that actually sends the information to the output.
*
* @param mesg The message to log.
* @param level The verbosity level of the message.
* Notify listener of taskFinished event.
*/
private void log( String mesg, int level )
public void taskFinished()
{
if( record && ( level <= loglevel ) )
{
out.println( mesg );
}
getLogger().debug( "<<< TASK FINISHED -- " + getTask() );
m_output.flush();
super.taskFinished();
}
}

+ 26
- 0
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/VerbosityLevelChoices.java View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* A list of possible values for the <code>setLoglevel()</code> method.
* Possible values include: error, warn, info, verbose, debug.
*/
public class VerbosityLevelChoices
extends EnumeratedAttribute
{
private final static String[] values =
{"error", "warn", "info", "verbose", "debug"};

public String[] getValues()
{
return values;
}
}

+ 0
- 100
proposal/myrmidon/src/todo/org/apache/tools/ant/BuildEvent.java View File

@@ -1,100 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant;

import java.util.EventObject;

public class BuildEvent
extends EventObject
{
private int m_priority = Project.MSG_VERBOSE;
private Throwable m_exception;
private String m_message;
private String m_target;
private String m_task;

/**
* Construct a BuildEvent for a target level event
*
* @param target the target that emitted the event.
*/
public BuildEvent( String target )
{
super( target );
m_target = target;
}

public void setException( Throwable exception )
{
m_exception = exception;
}

public void setMessage( String message, int priority )
{
m_message = message;
m_priority = priority;
}

/**
* Returns the exception that was thrown, if any. This field will only be
* set for "taskFinished", "targetFinished", and "buildFinished" events.
*
* @return The Exception value
* @see BuildListener#taskFinished(BuildEvent)
* @see BuildListener#targetFinished(BuildEvent)
* @see BuildListener#buildFinished(BuildEvent)
*/
public Throwable getException()
{
return m_exception;
}

/**
* Returns the logging message. This field will only be set for
* "messageLogged" events.
*
* @return The Message value
* @see BuildListener#messageLogged(BuildEvent)
*/
public String getMessage()
{
return m_message;
}

/**
* Returns the priority of the logging message. This field will only be set
* for "messageLogged" events.
*
* @return The Priority value
* @see BuildListener#messageLogged(BuildEvent)
*/
public int getPriority()
{
return m_priority;
}

/**
* Returns the target that fired this event.
*
* @return The Target value
*/
public String getTarget()
{
return m_target;
}

/**
* Returns the task that fired this event.
*
* @return The Task value
*/
public String getTask()
{
return m_task;
}
}

+ 0
- 80
proposal/myrmidon/src/todo/org/apache/tools/ant/BuildListener.java View File

@@ -1,80 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant;

import java.util.EventListener;

/**
* Classes that implement this interface will be notified when things happend
* during a build.
*
* @see BuildEvent
* @see Project#addBuildListener(BuildListener)
*/
public interface BuildListener
extends EventListener
{
/**
* Fired before any targets are started.
*
* @param event Description of Parameter
*/
void buildStarted( BuildEvent event );

/**
* Fired after the last target has finished. This event will still be thrown
* if an error occured during the build.
*
* @param event Description of Parameter
* @see BuildEvent#getException()
*/
void buildFinished( BuildEvent event );

/**
* Fired when a target is started.
*
* @param event Description of Parameter
* @see BuildEvent#getTarget()
*/
void targetStarted( BuildEvent event );

/**
* Fired when a target has finished. This event will still be thrown if an
* error occured during the build.
*
* @param event Description of Parameter
* @see BuildEvent#getException()
*/
void targetFinished( BuildEvent event );

/**
* Fired when a task is started.
*
* @param event Description of Parameter
* @see BuildEvent#getTask()
*/
void taskStarted( BuildEvent event );

/**
* Fired when a task has finished. This event will still be throw if an
* error occured during the build.
*
* @param event Description of Parameter
* @see BuildEvent#getException()
*/
void taskFinished( BuildEvent event );

/**
* Fired whenever a message is logged.
*
* @param event Description of Parameter
* @see BuildEvent#getMessage()
* @see BuildEvent#getPriority()
*/
void messageLogged( BuildEvent event );
}

+ 0
- 55
proposal/myrmidon/src/todo/org/apache/tools/ant/BuildLogger.java View File

@@ -1,55 +0,0 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant;

import java.io.PrintStream;

/**
* Interface used by Ant to log the build output. A build logger is a build
* listener which has the 'right' to send output to the ant log, which is
* usually System.out unles redirected by the -logfile option.
*
* @author Conor MacNeill
*/
public interface BuildLogger extends BuildListener
{
/**
* Set the msgOutputLevel this logger is to respond to. Only messages with a
* message level lower than or equal to the given level are output to the
* log. <P>
*
* Constants for the message levels are in Project.java. The order of the
* levels, from least to most verbose, is MSG_ERR, MSG_WARN, MSG_INFO,
* MSG_VERBOSE, MSG_DEBUG.
*
* @param level the logging level for the logger.
*/
void setMessageOutputLevel( int level );

/**
* Set the output stream to which this logger is to send its output.
*
* @param output the output stream for the logger.
*/
void setOutputPrintStream( PrintStream output );

/**
* Set this logger to produce emacs (and other editor) friendly output.
*
* @param emacsMode true if output is to be unadorned so that emacs and
* other editors can parse files names, etc.
*/
void setEmacsMode( boolean emacsMode );

/**
* Set the output stream to which this logger is to send error messages.
*
* @param err the error stream for the logger.
*/
void setErrorPrintStream( PrintStream err );
}

+ 2
- 7
proposal/myrmidon/src/todo/org/apache/tools/ant/Project.java View File

@@ -8,15 +8,11 @@
package org.apache.tools.ant;

import java.io.File;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.myrmidon.api.TaskException;
import org.apache.myrmidon.listeners.ProjectListener;
import org.apache.tools.ant.types.FilterSet;
import org.apache.tools.ant.types.FilterSetCollection;

/**
* Central representation of an Ant project. This class defines a Ant project
@@ -125,9 +121,8 @@ public class Project
return null;
}

public void addBuildListener( BuildListener listener )
public void addProjectListener( final ProjectListener listener )
{

}

/**


+ 25
- 0
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/ActionChoices.java View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* A list of possible values for the <code>setAction()</code> method.
* Possible values include: start and stop.
*/
public class ActionChoices
extends EnumeratedAttribute
{
private final static String[] values = {"start", "stop"};

public String[] getValues()
{
return values;
}
}

+ 57
- 97
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Recorder.java View File

@@ -7,6 +7,7 @@
*/
package org.apache.tools.ant.taskdefs;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@@ -14,7 +15,6 @@ import java.util.Hashtable;
import org.apache.myrmidon.api.TaskException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* This task is the manager for RecorderEntry's. It is this class that holds all
@@ -25,29 +25,30 @@ import org.apache.tools.ant.types.EnumeratedAttribute;
* @version 0.5
* @see RecorderEntry
*/
public class Recorder extends Task
public class Recorder
extends Task
{
/**
* The list of recorder entries.
*/
private static Hashtable recorderEntries = new Hashtable();

//////////////////////////////////////////////////////////////////////
// ATTRIBUTES
private final static Hashtable c_recorderEntries = new Hashtable();

/**
* The name of the file to record to.
*/
private String filename = null;
private String m_filename;

/**
* Whether or not to append. Need Boolean to record an unset state (null).
*/
private Boolean append = null;
private Boolean m_append;

/**
* Whether to start or stop recording. Need Boolean to record an unset state
* (null).
*/
private Boolean start = null;
private Boolean m_start;

/**
* What level to log? -1 means not initialized yet.
*/
@@ -58,15 +59,15 @@ public class Recorder extends Task
*
* @param action The action for the entry to take: start or stop.
*/
public void setAction( ActionChoices action )
public void setAction( final ActionChoices action )
{
if( action.getValue().equalsIgnoreCase( "start" ) )
{
start = Boolean.TRUE;
m_start = Boolean.TRUE;
}
else
{
start = Boolean.FALSE;
m_start = Boolean.FALSE;
}
}

@@ -75,9 +76,9 @@ public class Recorder extends Task
*
* @param append The new Append value
*/
public void setAppend( boolean append )
public void setAppend( final boolean append )
{
this.append = new Boolean( append );
m_append = new Boolean( append );
}

/**
@@ -86,7 +87,7 @@ public class Recorder extends Task
* @param level The new Loglevel value
* @see VerbosityLevelChoices
*/
public void setLoglevel( VerbosityLevelChoices level )
public void setLoglevel( final VerbosityLevelChoices level )
{
//I hate cascading if/elseif clauses !!!
String lev = level.getValue();
@@ -112,12 +113,6 @@ public class Recorder extends Task
}
}

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

//////////////////////////////////////////////////////////////////////
// ACCESSOR METHODS

/**
* Sets the name of the file to log to, and the name of the recorder entry.
*
@@ -125,12 +120,9 @@ public class Recorder extends Task
*/
public void setName( String fname )
{
filename = fname;
m_filename = fname;
}

//////////////////////////////////////////////////////////////////////
// CORE / MAIN BODY

/**
* The main execution.
*
@@ -139,101 +131,69 @@ public class Recorder extends Task
public void execute()
throws TaskException
{
if( filename == null )
if( m_filename == null )
{
throw new TaskException( "No filename specified" );
}

getLogger().debug( "setting a recorder for name " + filename );
getLogger().debug( "setting a recorder for name " + m_filename );

// get the recorder entry
RecorderEntry recorder = getRecorder( filename, getProject() );
final RecorderEntry recorder = getRecorder( m_filename );

getProject().addProjectListener( recorder );

// set the values on the recorder
recorder.setMessageOutputLevel( loglevel );
recorder.setRecordState( start );
recorder.setLogLevel( loglevel );

if( null != m_start )
{
recorder.setRecordState( m_start.booleanValue() );
}
}

/**
* 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 Description of Parameter
* @param proj Description of Parameter
* @return The Recorder value
* @exception TaskException Description of Exception
*/
protected RecorderEntry getRecorder( String name, Project proj )
protected RecorderEntry getRecorder( final String name )
throws TaskException
{
Object o = recorderEntries.get( name );
RecorderEntry entry;
if( o == null )
final Object o = c_recorderEntries.get( name );
if( null == o )
{
// create a recorder entry
try
{
entry = new RecorderEntry( name );
PrintStream out = null;
if( append == null )
{
out = new PrintStream(
new FileOutputStream( name ) );
}
else
{
out = new PrintStream(
new FileOutputStream( name, append.booleanValue() ) );
}
entry.setErrorPrintStream( out );
entry.setOutputPrintStream( out );
}
catch( IOException ioe )
{
throw new TaskException( "Problems creating a recorder entry",
ioe );
}
proj.addBuildListener( entry );
recorderEntries.put( name, entry );
return (RecorderEntry)o;
}
else

// create a recorder entry
try
{
entry = (RecorderEntry)o;
final PrintStream output = createOutput( name );
final RecorderEntry entry = new RecorderEntry( output );
c_recorderEntries.put( name, entry );
return entry;
}
return entry;
}

//////////////////////////////////////////////////////////////////////
// INNER CLASSES

/**
* A list of possible values for the <code>setAction()</code> method.
* Possible values include: start and stop.
*
* @author RT
*/
public static class ActionChoices extends EnumeratedAttribute
{
private final static String[] values = {"start", "stop"};

public String[] getValues()
catch( final IOException ioe )
{
return values;
throw new TaskException( "Problems creating a recorder entry",
ioe );
}
}

/**
* A list of possible values for the <code>setLoglevel()</code> method.
* Possible values include: error, warn, info, verbose, debug.
*
* @author RT
*/
public static class VerbosityLevelChoices extends EnumeratedAttribute
private PrintStream createOutput( final String name )
throws FileNotFoundException
{
private final static String[] values = {"error", "warn", "info",
"verbose", "debug"};

public String[] getValues()
FileOutputStream outputStream = null;
if( m_append == null )
{
return values;
outputStream = new FileOutputStream( name );
}
else
{
outputStream = new FileOutputStream( name, m_append.booleanValue() );
}
}

final PrintStream out = new PrintStream( outputStream );
return out;
}
}

+ 118
- 113
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/RecorderEntry.java View File

@@ -8,9 +8,10 @@
package org.apache.tools.ant.taskdefs;

import java.io.PrintStream;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.BuildLogger;
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.excalibur.util.StringUtil;
import org.apache.myrmidon.listeners.AbstractProjectListener;
import org.apache.tools.ant.Project;

/**
@@ -18,50 +19,54 @@ import org.apache.tools.ant.Project;
* process.
*
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
* @version 0.5
*/
public class RecorderEntry
extends AbstractLogEnabled
implements BuildLogger
extends AbstractProjectListener
implements LogEnabled
{
/**
* the line separator for this OS
*/
private final static String LINE_SEP = System.getProperty( "line.separator" );

//////////////////////////////////////////////////////////////////////
// ATTRIBUTES

/**
* The name of the file associated with this recorder entry.
*/
private String filename = null;
/**
* The state of the recorder (recorder on or off).
*/
private boolean record = true;
private boolean m_record;

/**
* The current verbosity level to record at.
*/
private int loglevel = Project.MSG_INFO;
private int m_loglevel = Project.MSG_INFO;

/**
* The output PrintStream to record to.
*/
private PrintStream out = null;
private final PrintStream m_output;

/**
* The start time of the last know target.
*/
private long targetStartTime = 0l;
private long m_targetStartTime = 0l;

//////////////////////////////////////////////////////////////////////
// CONSTRUCTORS / INITIALIZERS
private Logger m_logger;

/**
* @param name The name of this recorder (used as the filename).
*/
protected RecorderEntry( String name )
protected RecorderEntry( final PrintStream output )
{
m_output = output;
}

/**
* Provide component with a logger.
*
* @param logger the logger
*/
public void enableLogging( final Logger logger )
{
filename = name;
m_logger = logger;
}

protected final Logger getLogger()
{
return m_logger;
}

private static String formatTime( long millis )
@@ -71,38 +76,18 @@ public class RecorderEntry

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

}

public void setEmacsMode( boolean emacsMode )
{
throw new java.lang.RuntimeException( "Method setEmacsMode() not yet implemented." );
}

public void setErrorPrintStream( PrintStream err )
public void setLogLevel( final int loglevel )
{
out = err;
}

public void setMessageOutputLevel( int level )
{
if( level >= Project.MSG_ERR && level <= Project.MSG_DEBUG )
loglevel = level;
}

public void setOutputPrintStream( PrintStream output )
{
out = output;
m_loglevel = loglevel;
}

/**
@@ -110,105 +95,125 @@ public class RecorderEntry
*
* @param state true for on, false for off, null for no change.
*/
public void setRecordState( Boolean state )
public void setRecordState( final boolean record )
{
if( state != null )
record = state.booleanValue();
m_record = record;
}

//////////////////////////////////////////////////////////////////////
// ACCESSOR METHODS
/**
* Notify listener of log message event.
*
* @param message the message
* @param throwable the throwable
*/
public void log( final String message, final Throwable throwable )
{
m_output.println( StringUtil.LINE_SEPARATOR + "BUILD FAILED" + StringUtil.LINE_SEPARATOR );
throwable.printStackTrace( m_output );
finishRecording();
}

/**
* @return the name of the file the output is sent to.
* Notify listener of projectFinished event.
*/
public String getFilename()
public void projectFinished()
{
return filename;
m_output.println( StringUtil.LINE_SEPARATOR + "BUILD SUCCESSFUL" );
finishRecording();
}

public void buildFinished( BuildEvent event )
private void finishRecording()
{
getLogger().debug( "< BUILD FINISHED" );

Throwable error = event.getException();
if( error == null )
{
out.println( LINE_SEP + "BUILD SUCCESSFUL" );
}
else
{
out.println( LINE_SEP + "BUILD FAILED" + LINE_SEP );
error.printStackTrace( out );
}
out.flush();
out.close();
m_output.flush();
m_output.close();
}

public void buildStarted( BuildEvent event )
/**
* Notify listener of projectStarted event.
*/
public void projectStarted()
{
getLogger().debug( "> BUILD STARTED" );
}

public void messageLogged( BuildEvent event )
/**
* Notify listener of log message event.
*
* @param message the message
*/
public void log( final String message )
{
getLogger().debug( "--- MESSAGE LOGGED" );

StringBuffer buf = new StringBuffer();
if( event.getTask() != null )
final StringBuffer sb = new StringBuffer();

final String task = getTask();
if( task != null )
{
String name = "[" + event.getTask() + "]";
/**
* @todo replace 12 with DefaultLogger.LEFT_COLUMN_SIZE
*/
for( int i = 0; i < ( 12 - name.length() ); i++ )
final String name = "[" + task + "]";
final int padding = 12 - name.length();
for( int i = 0; i < padding; i++ )
{
buf.append( " " );
}// for
buf.append( name );
}// if
buf.append( event.getMessage() );
sb.append( " " );
}
sb.append( name );
}

log( buf.toString(), event.getPriority() );
}
sb.append( message );

public void targetFinished( BuildEvent event )
{
getLogger().debug( "<< TARGET FINISHED -- " + event.getTarget() );
String time = formatTime( System.currentTimeMillis() - targetStartTime );
getLogger().debug( event.getTarget() + ": duration " + time );
out.flush();
//FIXME: Check log level here
if( m_record )
{
m_output.println( sb.toString() );
}
}

public void targetStarted( final BuildEvent event )
/**
* Notify listener of targetFinished event.
*/
public void targetFinished()
{
getLogger().debug( ">> TARGET STARTED -- " + event.getTarget() );
getLogger().info( LINE_SEP + event.getTarget() + ":" );
targetStartTime = System.currentTimeMillis();
getLogger().debug( "<< TARGET FINISHED -- " + getTarget() );
final long millis = System.currentTimeMillis() - m_targetStartTime;
final String duration = formatTime( millis );
getLogger().debug( getTarget() + ": duration " + duration );
m_output.flush();
super.targetFinished();
}

public void taskFinished( BuildEvent event )
/**
* Notify listener of targetStarted event.
*
* @param target the name of target
*/
public void targetStarted( final String target )
{
getLogger().debug( "<<< TASK FINISHED -- " + event.getTask() );
out.flush();
super.targetStarted( target );
getLogger().debug( ">> TARGET STARTED -- " + getTarget() );
getLogger().info( StringUtil.LINE_SEPARATOR + getTarget() + ":" );
m_targetStartTime = System.currentTimeMillis();

}

public void taskStarted( BuildEvent event )
/**
* Notify listener of taskStarted event.
*
* @param task the name of task
*/
public void taskStarted( String task )
{
getLogger().debug( ">>> TASK STARTED -- " + event.getTask() );
super.taskStarted( task );
getLogger().debug( ">>> TASK STARTED -- " + getTask() );
}

/**
* The thing that actually sends the information to the output.
*
* @param mesg The message to log.
* @param level The verbosity level of the message.
* Notify listener of taskFinished event.
*/
private void log( String mesg, int level )
public void taskFinished()
{
if( record && ( level <= loglevel ) )
{
out.println( mesg );
}
getLogger().debug( "<<< TASK FINISHED -- " + getTask() );
m_output.flush();
super.taskFinished();
}
}

+ 26
- 0
proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/VerbosityLevelChoices.java View File

@@ -0,0 +1,26 @@
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.types.EnumeratedAttribute;

/**
* A list of possible values for the <code>setLoglevel()</code> method.
* Possible values include: error, warn, info, verbose, debug.
*/
public class VerbosityLevelChoices
extends EnumeratedAttribute
{
private final static String[] values =
{"error", "warn", "info", "verbose", "debug"};

public String[] getValues()
{
return values;
}
}

Loading…
Cancel
Save