donaldp 01/12/30 01:15:38
Modified: proposal/myrmidon/src/main/org/apache/tools/ant Project.java
proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
Recorder.java RecorderEntry.java
Added: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs
ActionChoices.java VerbosityLevelChoices.java
Removed: proposal/myrmidon/src/main/org/apache/tools/ant
BuildEvent.java BuildListener.java BuildLogger.java
Log:
Remove old BuildListener architecture and replace with ProjectListener
Revision Changes Path
1.20 +2 -7
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Project.java 30 Dec 2001 03:30:34 -0000 1.19
+++ Project.java 30 Dec 2001 09:15:37 -0000 1.20
@@ -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 @@
return null;
}
- public void addBuildListener( BuildListener listener )
+ public void addProjectListener( final ProjectListener listener )
{
-
}
/**
1.7 +58 -98
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Recorder.java
Index: Recorder.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Recorder.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Recorder.java 30 Dec 2001 00:14:24 -0000 1.6
+++ Recorder.java 30 Dec 2001 09:15:37 -0000 1.7
@@ -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 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 @@
* @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 @@
*
* @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 @@
*
* @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 @@
* @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 @@
}
}
- //////////////////////////////////////////////////////////////////////
- // 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 void setName( String fname )
{
- filename = fname;
+ m_filename = fname;
}
- //////////////////////////////////////////////////////////////////////
- // CORE / MAIN BODY
-
/**
* The main execution.
*
@@ -139,101 +131,69 @@
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 )
- {
- // 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 );
- }
- else
+ final Object o = c_recorderEntries.get( name );
+ if( null == o )
{
- entry = (RecorderEntry)o;
+ return (RecorderEntry)o;
}
- 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()
+ // create a recorder entry
+ try
+ {
+ final PrintStream output = createOutput( name );
+ final RecorderEntry entry = new RecorderEntry( output );
+ c_recorderEntries.put( name, entry );
+ return entry;
+ }
+ 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;
+ }
}
1.9 +118 -113
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java
Index: RecorderEntry.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- RecorderEntry.java 30 Dec 2001 03:44:05 -0000 1.8
+++ RecorderEntry.java 30 Dec 2001 09:15:37 -0000 1.9
@@ -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 @@
* process.
*
* @author <a href="mailto:[EMAIL PROTECTED]">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 @@
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 @@
*
* @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();
}
}
1.1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/ActionChoices.java
Index: ActionChoices.java
===================================================================
/*
* 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;
}
}
1.1
jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/VerbosityLevelChoices.java
Index: VerbosityLevelChoices.java
===================================================================
/*
* 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;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>