diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Recorder.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Recorder.java deleted file mode 100644 index 1c41a2b1d..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/Recorder.java +++ /dev/null @@ -1,194 +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.taskdefs; - -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.Hashtable; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.LogLevel; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; - -/** - * This task is the manager for RecorderEntry's. It is this class that holds all - * entries, modifies them every time the <recorder> task is called, and - * addes them to the build listener process. - * - * @author J D Glanville - * @version 0.5 - * @see RecorderEntry - */ -public class Recorder - extends Task -{ - /** - * The list of recorder entries. - */ - private final static Hashtable c_recorderEntries = new Hashtable(); - - /** - * The name of the file to record to. - */ - private String m_filename; - - /** - * Whether or not to append. Need Boolean to record an unset state (null). - */ - private Boolean m_append; - - /** - * Whether to start or stop recording. Need Boolean to record an unset state - * (null). - */ - private Boolean m_start; - - /** - * What level to log? -1 means not initialized yet. - */ - private int loglevel = -1; - - /** - * Sets the action for the associated recorder entry. - * - * @param action The action for the entry to take: start or stop. - */ - public void setAction( final ActionChoices action ) - { - if( action.getValue().equalsIgnoreCase( "start" ) ) - { - m_start = Boolean.TRUE; - } - else - { - m_start = Boolean.FALSE; - } - } - - /** - * Whether or not the logger should append to a previous file. - * - * @param append The new Append value - */ - public void setAppend( final boolean append ) - { - m_append = new Boolean( append ); - } - - /** - * Sets the level to which this recorder entry should log to. - * - * @param level The new Loglevel value - * @see VerbosityLevelChoices - */ - public void setLoglevel( final LogLevel level ) - { - //I hate cascading if/elseif clauses !!! - if( LogLevel.ERROR == level ) - { - loglevel = Project.MSG_ERR; - } - else if( LogLevel.WARN == level ) - { - loglevel = Project.MSG_WARN; - } - else if( LogLevel.INFO == level ) - { - loglevel = Project.MSG_INFO; - } - else if( LogLevel.DEBUG == level ) - { - loglevel = Project.MSG_VERBOSE; - } - } - - /** - * Sets the name of the file to log to, and the name of the recorder entry. - * - * @param fname File name of logfile. - */ - public void setName( String fname ) - { - m_filename = fname; - } - - /** - * The main execution. - * - * @exception TaskException Description of Exception - */ - public void execute() - throws TaskException - { - if( m_filename == null ) - { - throw new TaskException( "No filename specified" ); - } - - getLogger().debug( "setting a recorder for name " + m_filename ); - - // get the recorder entry - final RecorderEntry recorder = getRecorder( m_filename ); - - getProject().addProjectListener( recorder ); - - // set the values on the recorder - 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. - */ - protected RecorderEntry getRecorder( final String name ) - throws TaskException - { - final Object o = c_recorderEntries.get( name ); - if( null == o ) - { - return (RecorderEntry)o; - } - - // 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 ) - { - throw new TaskException( "Problems creating a recorder entry", - ioe ); - } - } - - private PrintStream createOutput( final String name ) - throws FileNotFoundException - { - FileOutputStream outputStream = null; - if( m_append == null ) - { - outputStream = new FileOutputStream( name ); - } - else - { - outputStream = new FileOutputStream( name, m_append.booleanValue() ); - } - - return new PrintStream( outputStream ); - } -} diff --git a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java b/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java deleted file mode 100644 index 8800fb765..000000000 --- a/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/RecorderEntry.java +++ /dev/null @@ -1,208 +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.taskdefs; - -import java.io.PrintStream; -import org.apache.avalon.excalibur.util.StringUtil; -import org.apache.avalon.framework.logger.LogEnabled; -import org.apache.avalon.framework.logger.Logger; -import org.apache.myrmidon.listeners.AbstractProjectListener; -import org.apache.myrmidon.listeners.LogEvent; -import org.apache.myrmidon.listeners.ProjectEvent; -import org.apache.myrmidon.listeners.TargetEvent; -import org.apache.myrmidon.listeners.TaskEvent; -import org.apache.tools.ant.Project; - -/** - * This is a class that represents a recorder. This is the listener to the build - * process. - * - * @author J D Glanville - */ -public class RecorderEntry - extends AbstractProjectListener - implements LogEnabled -{ - /** - * The state of the recorder (recorder on or off). - */ - private boolean m_record; - - /** - * The current verbosity level to record at. - */ - private int m_loglevel = Project.MSG_INFO; - - /** - * The output PrintStream to record to. - */ - private final PrintStream m_output; - - /** - * The start time of the last know target. - */ - private long m_targetStartTime = 0l; - - private Logger m_logger; - - protected RecorderEntry( final PrintStream output ) - { - m_output = output; - } - - /** - * Provide component with a logger. - * - * @param logger the logger - */ - public void enableLogging( final Logger logger ) - { - m_logger = logger; - } - - protected final Logger getLogger() - { - return m_logger; - } - - private static String formatTime( long millis ) - { - long seconds = millis / 1000; - long minutes = seconds / 60; - - if( minutes > 0 ) - { - return minutes + " minute" + ( minutes == 1 ? " " : "s " ) + - ( seconds % 60 ) + " second" + ( seconds % 60 == 1 ? "" : "s" ); - } - else - { - return seconds + " second" + ( seconds % 60 == 1 ? "" : "s" ); - } - } - - public void setLogLevel( final int loglevel ) - { - m_loglevel = loglevel; - } - - /** - * Turns off or on this recorder. - * - * @param record true for on, false for off, null for no change. - */ - public void setRecordState( final boolean record ) - { - m_record = record; - } - - /** - * Notify listener of log message event. - */ - public void log( final LogEvent event ) - { - final Throwable throwable = event.getThrowable(); - if( throwable != null ) - { - m_output.println( StringUtil.LINE_SEPARATOR + "BUILD FAILED" + StringUtil.LINE_SEPARATOR ); - throwable.printStackTrace( m_output ); - finishRecording(); - } - else - { - getLogger().debug( "--- MESSAGE LOGGED" ); - - final StringBuffer sb = new StringBuffer(); - - final String task = event.getTaskName(); - if( task != null ) - { - final String name = "[" + task + "]"; - final int padding = 12 - name.length(); - for( int i = 0; i < padding; i++ ) - { - sb.append( " " ); - } - sb.append( name ); - } - - sb.append( event.getMessage() ); - - //FIXME: Check log level here - if( m_record ) - { - m_output.println( sb.toString() ); - } - } - } - - /** - * Notify listener of projectFinished event. - */ - public void projectFinished( final ProjectEvent event ) - { - m_output.println( StringUtil.LINE_SEPARATOR + "BUILD SUCCESSFUL" ); - finishRecording(); - } - - private void finishRecording() - { - getLogger().debug( "< BUILD FINISHED" ); - m_output.flush(); - m_output.close(); - } - - /** - * Notify listener of projectStarted event. - */ - public void projectStarted( final ProjectEvent event ) - { - getLogger().debug( "> BUILD STARTED" ); - } - - - /** - * Notify listener of targetFinished event. - */ - public void targetFinished( final TargetEvent event ) - { - getLogger().debug( "<< TARGET FINISHED -- " + event.getTargetName() ); - final long millis = System.currentTimeMillis() - m_targetStartTime; - final String duration = formatTime( millis ); - getLogger().debug( event.getTargetName() + ": duration " + duration ); - m_output.flush(); - } - - /** - * Notify listener of targetStarted event. - */ - public void targetStarted( final TargetEvent event ) - { - getLogger().debug( ">> TARGET STARTED -- " + event.getTargetName() ); - getLogger().info( StringUtil.LINE_SEPARATOR + event.getTargetName() + ":" ); - m_targetStartTime = System.currentTimeMillis(); - - } - - /** - * Notify listener of taskStarted event. - */ - public void taskStarted( final TaskEvent event ) - { - getLogger().debug( ">>> TASK STARTED -- " + event.getTaskName() ); - } - - /** - * Notify listener of taskFinished event. - */ - public void taskFinished( final TaskEvent event ) - { - getLogger().debug( "<<< TASK FINISHED -- " + event.getTaskName() ); - m_output.flush(); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Recorder.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Recorder.java deleted file mode 100644 index 1c41a2b1d..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/Recorder.java +++ /dev/null @@ -1,194 +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.taskdefs; - -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.Hashtable; -import org.apache.myrmidon.api.TaskException; -import org.apache.myrmidon.framework.LogLevel; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; - -/** - * This task is the manager for RecorderEntry's. It is this class that holds all - * entries, modifies them every time the <recorder> task is called, and - * addes them to the build listener process. - * - * @author J D Glanville - * @version 0.5 - * @see RecorderEntry - */ -public class Recorder - extends Task -{ - /** - * The list of recorder entries. - */ - private final static Hashtable c_recorderEntries = new Hashtable(); - - /** - * The name of the file to record to. - */ - private String m_filename; - - /** - * Whether or not to append. Need Boolean to record an unset state (null). - */ - private Boolean m_append; - - /** - * Whether to start or stop recording. Need Boolean to record an unset state - * (null). - */ - private Boolean m_start; - - /** - * What level to log? -1 means not initialized yet. - */ - private int loglevel = -1; - - /** - * Sets the action for the associated recorder entry. - * - * @param action The action for the entry to take: start or stop. - */ - public void setAction( final ActionChoices action ) - { - if( action.getValue().equalsIgnoreCase( "start" ) ) - { - m_start = Boolean.TRUE; - } - else - { - m_start = Boolean.FALSE; - } - } - - /** - * Whether or not the logger should append to a previous file. - * - * @param append The new Append value - */ - public void setAppend( final boolean append ) - { - m_append = new Boolean( append ); - } - - /** - * Sets the level to which this recorder entry should log to. - * - * @param level The new Loglevel value - * @see VerbosityLevelChoices - */ - public void setLoglevel( final LogLevel level ) - { - //I hate cascading if/elseif clauses !!! - if( LogLevel.ERROR == level ) - { - loglevel = Project.MSG_ERR; - } - else if( LogLevel.WARN == level ) - { - loglevel = Project.MSG_WARN; - } - else if( LogLevel.INFO == level ) - { - loglevel = Project.MSG_INFO; - } - else if( LogLevel.DEBUG == level ) - { - loglevel = Project.MSG_VERBOSE; - } - } - - /** - * Sets the name of the file to log to, and the name of the recorder entry. - * - * @param fname File name of logfile. - */ - public void setName( String fname ) - { - m_filename = fname; - } - - /** - * The main execution. - * - * @exception TaskException Description of Exception - */ - public void execute() - throws TaskException - { - if( m_filename == null ) - { - throw new TaskException( "No filename specified" ); - } - - getLogger().debug( "setting a recorder for name " + m_filename ); - - // get the recorder entry - final RecorderEntry recorder = getRecorder( m_filename ); - - getProject().addProjectListener( recorder ); - - // set the values on the recorder - 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. - */ - protected RecorderEntry getRecorder( final String name ) - throws TaskException - { - final Object o = c_recorderEntries.get( name ); - if( null == o ) - { - return (RecorderEntry)o; - } - - // 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 ) - { - throw new TaskException( "Problems creating a recorder entry", - ioe ); - } - } - - private PrintStream createOutput( final String name ) - throws FileNotFoundException - { - FileOutputStream outputStream = null; - if( m_append == null ) - { - outputStream = new FileOutputStream( name ); - } - else - { - outputStream = new FileOutputStream( name, m_append.booleanValue() ); - } - - return new PrintStream( outputStream ); - } -} diff --git a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/RecorderEntry.java b/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/RecorderEntry.java deleted file mode 100644 index 8800fb765..000000000 --- a/proposal/myrmidon/src/todo/org/apache/tools/ant/taskdefs/RecorderEntry.java +++ /dev/null @@ -1,208 +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.taskdefs; - -import java.io.PrintStream; -import org.apache.avalon.excalibur.util.StringUtil; -import org.apache.avalon.framework.logger.LogEnabled; -import org.apache.avalon.framework.logger.Logger; -import org.apache.myrmidon.listeners.AbstractProjectListener; -import org.apache.myrmidon.listeners.LogEvent; -import org.apache.myrmidon.listeners.ProjectEvent; -import org.apache.myrmidon.listeners.TargetEvent; -import org.apache.myrmidon.listeners.TaskEvent; -import org.apache.tools.ant.Project; - -/** - * This is a class that represents a recorder. This is the listener to the build - * process. - * - * @author J D Glanville - */ -public class RecorderEntry - extends AbstractProjectListener - implements LogEnabled -{ - /** - * The state of the recorder (recorder on or off). - */ - private boolean m_record; - - /** - * The current verbosity level to record at. - */ - private int m_loglevel = Project.MSG_INFO; - - /** - * The output PrintStream to record to. - */ - private final PrintStream m_output; - - /** - * The start time of the last know target. - */ - private long m_targetStartTime = 0l; - - private Logger m_logger; - - protected RecorderEntry( final PrintStream output ) - { - m_output = output; - } - - /** - * Provide component with a logger. - * - * @param logger the logger - */ - public void enableLogging( final Logger logger ) - { - m_logger = logger; - } - - protected final Logger getLogger() - { - return m_logger; - } - - private static String formatTime( long millis ) - { - long seconds = millis / 1000; - long minutes = seconds / 60; - - if( minutes > 0 ) - { - return minutes + " minute" + ( minutes == 1 ? " " : "s " ) + - ( seconds % 60 ) + " second" + ( seconds % 60 == 1 ? "" : "s" ); - } - else - { - return seconds + " second" + ( seconds % 60 == 1 ? "" : "s" ); - } - } - - public void setLogLevel( final int loglevel ) - { - m_loglevel = loglevel; - } - - /** - * Turns off or on this recorder. - * - * @param record true for on, false for off, null for no change. - */ - public void setRecordState( final boolean record ) - { - m_record = record; - } - - /** - * Notify listener of log message event. - */ - public void log( final LogEvent event ) - { - final Throwable throwable = event.getThrowable(); - if( throwable != null ) - { - m_output.println( StringUtil.LINE_SEPARATOR + "BUILD FAILED" + StringUtil.LINE_SEPARATOR ); - throwable.printStackTrace( m_output ); - finishRecording(); - } - else - { - getLogger().debug( "--- MESSAGE LOGGED" ); - - final StringBuffer sb = new StringBuffer(); - - final String task = event.getTaskName(); - if( task != null ) - { - final String name = "[" + task + "]"; - final int padding = 12 - name.length(); - for( int i = 0; i < padding; i++ ) - { - sb.append( " " ); - } - sb.append( name ); - } - - sb.append( event.getMessage() ); - - //FIXME: Check log level here - if( m_record ) - { - m_output.println( sb.toString() ); - } - } - } - - /** - * Notify listener of projectFinished event. - */ - public void projectFinished( final ProjectEvent event ) - { - m_output.println( StringUtil.LINE_SEPARATOR + "BUILD SUCCESSFUL" ); - finishRecording(); - } - - private void finishRecording() - { - getLogger().debug( "< BUILD FINISHED" ); - m_output.flush(); - m_output.close(); - } - - /** - * Notify listener of projectStarted event. - */ - public void projectStarted( final ProjectEvent event ) - { - getLogger().debug( "> BUILD STARTED" ); - } - - - /** - * Notify listener of targetFinished event. - */ - public void targetFinished( final TargetEvent event ) - { - getLogger().debug( "<< TARGET FINISHED -- " + event.getTargetName() ); - final long millis = System.currentTimeMillis() - m_targetStartTime; - final String duration = formatTime( millis ); - getLogger().debug( event.getTargetName() + ": duration " + duration ); - m_output.flush(); - } - - /** - * Notify listener of targetStarted event. - */ - public void targetStarted( final TargetEvent event ) - { - getLogger().debug( ">> TARGET STARTED -- " + event.getTargetName() ); - getLogger().info( StringUtil.LINE_SEPARATOR + event.getTargetName() + ":" ); - m_targetStartTime = System.currentTimeMillis(); - - } - - /** - * Notify listener of taskStarted event. - */ - public void taskStarted( final TaskEvent event ) - { - getLogger().debug( ">>> TASK STARTED -- " + event.getTaskName() ); - } - - /** - * Notify listener of taskFinished event. - */ - public void taskFinished( final TaskEvent event ) - { - getLogger().debug( "<<< TASK FINISHED -- " + event.getTaskName() ); - m_output.flush(); - } -}