ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/listener AbstractProjectListener.java ProjectEvent.java TaskToProjectListenerAdapter.java
Date Wed, 29 May 2002 13:03:33 GMT
adammurdoch    02/05/29 06:03:33

  Modified:    antlib/src/java/org/apache/antlib/java
                        JavaCompilerAdaptor.java
               antlib/src/java/org/apache/antlib/project
                        DefaultProjectListener.java
               antlib/src/test/org/apache/antlib
                        AbstractProjectTestCase.java
               api/src/java/org/apache/myrmidon/api/event TaskEvent.java
                        TaskListener.java
               buildtools/src/java/org/apache/myrmidon/build
                        AntlibDescriptorTask.java
               container/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java
               container/src/java/org/apache/myrmidon/frontends
                        CLIMain.java Resources.properties
               container/src/java/org/apache/myrmidon/interfaces
                        BasicLogger.java EmbeddedAnt.java
               container/src/java/org/apache/myrmidon/interfaces/embeddor
                        Embeddor.java
               container/src/test/org/apache/myrmidon
                        TrackingTaskListener.java
               framework/src/java/org/apache/myrmidon/framework/listener
                        AbstractProjectListener.java ProjectEvent.java
                        TaskToProjectListenerAdapter.java
  Added:       api/src/java/org/apache/myrmidon/api/event
                        AbstractTaskListener.java
  Removed:     antlib/src/java/org/apache/antlib/project
                        ClassicProjectListener.java
                        NoPrefixProjectListener.java
  Log:
  Changes to TaskListener lifecycle:
  
  * Added TaskListener.contextualize(), used to supply a TaskContext to a
    listener.
  
  * Listeners are now contextualised and configured before they are used.
  
  * Changed Embeddor.createListener() to take a ModelElement representing
    the listener's config.  The embeddor is currently responsible for managing
    the listener's lifecycle.
  
  * Added AbstractTaskListener.
  
  * Added ProjectEvent.getLogLevel().
  
  * Combined the classic, noprefix, and default listeners into a single
    configurable listener.
  
  * Added --bannner command-line option, to replace '--listener classic'.
  
  * Removed '-' from all command-line option names.
  
  Revision  Changes    Path
  1.4       +6 -1      jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/java/JavaCompilerAdaptor.java
  
  Index: JavaCompilerAdaptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/java/JavaCompilerAdaptor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JavaCompilerAdaptor.java	24 May 2002 04:30:59 -0000	1.3
  +++ JavaCompilerAdaptor.java	29 May 2002 13:03:31 -0000	1.4
  @@ -29,7 +29,7 @@
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.3 $ $Date: 2002/05/24 04:30:59 $
  + * @version $Revision: 1.4 $ $Date: 2002/05/29 13:03:31 $
    *
    * @ant.role name="java-compiler"
    */
  @@ -162,6 +162,11 @@
        */
       private void logFiles( final File[] compileList )
       {
  +        if( compileList.length == 0 )
  +        {
  +            return;
  +        }
  +
           // Log
           final String message = "Compiling " + compileList.length + " source files to "
+ m_destDir;
           getContext().info( message );
  
  
  
  1.2       +92 -15    jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/DefaultProjectListener.java
  
  Index: DefaultProjectListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/java/org/apache/antlib/project/DefaultProjectListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultProjectListener.java	18 May 2002 04:19:34 -0000	1.1
  +++ DefaultProjectListener.java	29 May 2002 13:03:31 -0000	1.2
  @@ -7,37 +7,65 @@
    */
   package org.apache.antlib.project;
   
  -import org.apache.antlib.project.ClassicProjectListener;
  +import java.io.PrintWriter;
  +import org.apache.avalon.framework.ExceptionUtil;
  +import org.apache.myrmidon.api.event.LogLevel;
  +import org.apache.myrmidon.framework.listener.AbstractProjectListener;
   import org.apache.myrmidon.framework.listener.ProjectEvent;
   
   /**
    * Default listener that emulates the Ant 1.x no banner listener.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2002/05/18 04:19:34 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/29 13:03:31 $
    * @ant.type type="project-listener" name="default"
    */
   public class DefaultProjectListener
  -    extends ClassicProjectListener
  +    extends AbstractProjectListener
   {
  -    private boolean m_targetOutput;
  +    private final PrintWriter m_printWriter;
  +    private LogLevel m_minLevel;
  +    private boolean m_banner = true;
  +    private boolean m_includePrefix = true;
  +    private String m_lastTarget;
  +
  +    public DefaultProjectListener()
  +    {
  +        m_printWriter = new PrintWriter( System.out, true );
  +    }
   
       /**
  -     * Notify listener of targetStarted event.
  +     * Sets the minimum log level for this listener.
  +     */
  +    public void setLevel( final LogLevel minLevel )
  +    {
  +        m_minLevel = minLevel;
  +    }
  +
  +    /**
  +     * Enables the task name prefix.
  +     */
  +    public void setPrefix( final boolean prefix )
  +    {
  +        m_includePrefix = prefix;
  +    }
  +
  +    /**
  +     * Enables the target banner.
        */
  -    public void targetStarted( final ProjectEvent target )
  +    public void setBanner( final boolean banner )
       {
  -        m_targetOutput = false;
  +        m_banner = banner;
       }
   
       /**
  -     * Notify listener of targetFinished event.
  +     * Notify listener of targetStarted event.
        */
  -    public void targetFinished( final ProjectEvent event )
  +    public void targetStarted( final ProjectEvent event )
       {
  -        if( m_targetOutput )
  +        if( m_banner )
           {
  -            getWriter().println();
  +            writeTargetHeader( event );
           }
       }
   
  @@ -46,15 +74,64 @@
        */
       public void log( final ProjectEvent event )
       {
  +        if( event.getLogLevel().isLessThan( m_minLevel ) )
  +        {
  +            return;
  +        }
  +
           // Write the target header, if necessary
  +        writeTargetHeader( event );
  +
  +        // Write the message and
  +        writeMessage( event );
  +        writeThrowable( event );
  +    }
  +
  +    /**
  +     * Writes the target header.
  +     */
  +    private void writeTargetHeader( final ProjectEvent event )
  +    {
           final String target = event.getTarget();
  -        if( target != null && !m_targetOutput )
  +        if( target == null || target.equals( m_lastTarget ) )
           {
  -            writeTargetHeader( event );
  -            m_targetOutput = true;
  +            return;
           }
  +        m_lastTarget = target;
  +
  +        m_printWriter.println();
  +        m_printWriter.println( target + ":" );
  +    }
   
  +    /**
  +     * Writes a message
  +     */
  +    private void writeMessage( final ProjectEvent event )
  +    {
           // Write the message
  -        super.log( event );
  +        final String message = event.getMessage();
  +        final String task = event.getTask();
  +        if( m_includePrefix && null != task )
  +        {
  +            m_printWriter.println( "    [" + task + "] " + message );
  +        }
  +        else
  +        {
  +            m_printWriter.println( message );
  +        }
  +    }
  +
  +    /**
  +     * Writes a throwable.
  +     */
  +    private void writeThrowable( final ProjectEvent event )
  +    {
  +        // Write the exception, if any
  +        final Throwable throwable = event.getThrowable();
  +        if( throwable != null )
  +        {
  +            m_printWriter.println( ExceptionUtil.printStackTrace( throwable, 8, true )
);
  +        }
       }
  +
   }
  
  
  
  1.6       +1 -2      jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/AbstractProjectTestCase.java
  
  Index: AbstractProjectTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/AbstractProjectTestCase.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractProjectTestCase.java	28 May 2002 03:55:41 -0000	1.5
  +++ AbstractProjectTestCase.java	29 May 2002 13:03:31 -0000	1.6
  @@ -18,7 +18,7 @@
    * A base class for test cases which need to execute projects or tasks.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.5 $ $Date: 2002/05/28 03:55:41 $
  + * @version $Revision: 1.6 $ $Date: 2002/05/29 13:03:31 $
    */
   public class AbstractProjectTestCase
       extends AbstractAutTestCase
  @@ -126,7 +126,6 @@
               embeddor.setSharedClassLoader( getClass().getClassLoader() );
               embeddor.setContainerClassLoader( getClass().getClassLoader() );
               embeddor.setProjectFile( projectFile.getAbsolutePath() );
  -            embeddor.setProjectListener( null );
               embeddor.setEmbeddorProperty( "myrmidon.ext.path", System.getProperty( "test.libdir"
) );
   
               // Add a listener to make sure all is good
  
  
  
  1.5       +1 -2      jakarta-ant-myrmidon/api/src/java/org/apache/myrmidon/api/event/TaskEvent.java
  
  Index: TaskEvent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/api/src/java/org/apache/myrmidon/api/event/TaskEvent.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TaskEvent.java	24 May 2002 04:19:02 -0000	1.4
  +++ TaskEvent.java	29 May 2002 13:03:32 -0000	1.5
  @@ -13,9 +13,8 @@
    * or logs a message via the
    * {@link org.apache.myrmidon.api.TaskContext}.
    *
  - *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.4 $ $Date: 2002/05/24 04:19:02 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/29 13:03:32 $
    */
   public final class TaskEvent
   {
  
  
  
  1.5       +14 -5     jakarta-ant-myrmidon/api/src/java/org/apache/myrmidon/api/event/TaskListener.java
  
  Index: TaskListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/api/src/java/org/apache/myrmidon/api/event/TaskListener.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TaskListener.java	18 May 2002 04:19:34 -0000	1.4
  +++ TaskListener.java	29 May 2002 13:03:32 -0000	1.5
  @@ -7,12 +7,15 @@
    */
   package org.apache.myrmidon.api.event;
   
  +import org.apache.myrmidon.api.TaskContext;
  +import org.apache.myrmidon.api.TaskException;
  +
   /**
    * Use the TaskListener interface to receive {@link TaskEvent}
    * notifications about tasks.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.4 $ $Date: 2002/05/18 04:19:34 $
  + * @version $Revision: 1.5 $ $Date: 2002/05/29 13:03:32 $
    * @ant.role name="task-listener"
    */
   public interface TaskListener
  @@ -20,7 +23,14 @@
       String ROLE = "task-listener";
   
       /**
  -     * Notify the listener that the task is starting.
  +     * Sets the context that the listener operates in.  The listener uses
  +     * this context to access the services provided by the container.
  +     */
  +    void contextualize( TaskContext context )
  +        throws TaskException;
  +
  +    /**
  +     * Notify the listener that a task is starting.
        * This is called prior to task starting.
        *
        * @param event the TaskEvent
  @@ -28,15 +38,14 @@
       void taskStarting( TaskEvent event );
   
       /**
  -     * Notify the listener that the task logged
  -     * a message.
  +     * Notify the listener that a task has logged a message.
        *
        * @param event the TaskEvent
        */
       void taskMessage( TaskEvent event );
   
       /**
  -     * Notify the listener that the task has finished.
  +     * Notify the listener that a task has finished.
        * This is called after task has finished.
        *
        * @param event the TaskEvent
  
  
  
  1.1                  jakarta-ant-myrmidon/api/src/java/org/apache/myrmidon/api/event/AbstractTaskListener.java
  
  Index: AbstractTaskListener.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.myrmidon.api.event;
  
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  
  /**
   * An empty implementation of {@link TaskListener}.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/29 13:03:32 $
   */
  public abstract class AbstractTaskListener
      implements TaskListener
  {
      private TaskContext m_context;
  
      /**
       * Returns the context that this listener operates in.
       */
      protected TaskContext getContext()
      {
          return m_context;
      }
  
      /**
       * Sets the context that the listener operates in.  The listener uses
       * this context to access the services provided by the container.
       */
      public void contextualize( final TaskContext context )
          throws TaskException
      {
          m_context = context;
      }
  
      /**
       * Notify the listener that a task is starting.
       * This implementation does nothing.
       *
       * @param event the TaskEvent
       */
      public void taskStarting( final TaskEvent event )
      {
      }
  
      /**
       * Notify the listener that a task has logged a message.
       * This implementation does nothing.
       *
       * @param event the TaskEvent
       */
      public void taskMessage( final TaskEvent event )
      {
      }
  
      /**
       * Notify the listener that a task has finished.
       * This implementation does nothing.
       *
       * @param event the TaskEvent
       */
      public void taskFinished( final TaskEvent event )
      {
      }
  }
  
  
  
  1.5       +1 -22     jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntlibDescriptorTask.java
  
  Index: AntlibDescriptorTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/buildtools/src/java/org/apache/myrmidon/build/AntlibDescriptorTask.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AntlibDescriptorTask.java	29 May 2002 10:50:35 -0000	1.4
  +++ AntlibDescriptorTask.java	29 May 2002 13:03:32 -0000	1.5
  @@ -8,12 +8,9 @@
   package org.apache.myrmidon.build;
   
   import java.net.URL;
  -import java.util.List;
  -import java.io.File;
  -import java.io.IOException;
  +import org.apache.tools.ant.BuildException;
   import xdoclet.DocletTask;
   import xdoclet.TemplateSubTask;
  -import org.apache.tools.ant.BuildException;
   
   /**
    * A Task that generates Myrmidon Antlib descriptors from source files,
  @@ -27,7 +24,6 @@
       private static final String DESCRIPTOR_TEMPLATE = "/org/apache/myrmidon/build/ant-descriptor.j";
       private static final String ROLES_TEMPLATE = "/org/apache/myrmidon/build/ant-roles.j";
   
  -    private TemplateSubTask m_antDocs;
       private String m_libName;
       private String m_descriptorFileName;
       private String m_rolesFileName;
  @@ -61,23 +57,6 @@
           addTemplate( antDocs );
       }
   
  -//    public void execute()
  -//        throws BuildException
  -//    {
  -//        File tmpFile;
  -//        try
  -//        {
  -//            tmpFile = File.createTempFile( "antlib", "tmp" );
  -//            setXdoclettempfile( tmpFile );
  -//        }
  -//        catch( final IOException ioe )
  -//        {
  -//            throw new BuildException( ioe.getMessage(), ioe );
  -//        }
  -//
  -//        super.execute();
  -//        tmpFile.delete();
  -//    }
       /**
        * Describe what the method does
        *
  
  
  
  1.79      +20 -9     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.78
  retrieving revision 1.79
  diff -u -r1.78 -r1.79
  --- DefaultEmbeddor.java	29 May 2002 06:40:06 -0000	1.78
  +++ DefaultEmbeddor.java	29 May 2002 13:03:32 -0000	1.79
  @@ -31,7 +31,9 @@
   import org.apache.myrmidon.Constants;
   import org.apache.myrmidon.api.TaskContext;
   import org.apache.myrmidon.api.event.TaskListener;
  +import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.components.property.DefaultPropertyStore;
  +import org.apache.myrmidon.components.workspace.DefaultTaskContext;
   import org.apache.myrmidon.interfaces.builder.ModelBuilder;
   import org.apache.myrmidon.interfaces.builder.ProjectBuilder;
   import org.apache.myrmidon.interfaces.configurer.Configurer;
  @@ -63,7 +65,7 @@
    * Instantiate this to embed inside other applications.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.78 $ $Date: 2002/05/29 06:40:06 $
  + * @version $Revision: 1.79 $ $Date: 2002/05/29 13:03:32 $
    */
   public class DefaultEmbeddor
       extends AbstractLogEnabled
  @@ -81,10 +83,13 @@
       private Deployer m_deployer;
       private TypeManager m_typeManager;
       private LibraryManager m_libraryManager;
  +    private Configurer m_configurer;
   
       private List m_components = new ArrayList();
       private DefaultServiceManager m_serviceManager = new DefaultServiceManager();
       private Context m_context;
  +    private ExecutionFrame m_rootFrame;
  +    private TaskContext m_rootContext;
       private PropertyStore m_rootProps;
   
       /**
  @@ -183,16 +188,18 @@
   
       /**
        * Creates a task listener.
  -     *
  -     * @param name The shorthand name of the listener.
  -     * @return the listener.
        */
  -    public TaskListener createListener( final String name )
  +    public TaskListener createListener( final ModelElement model )
           throws Exception
       {
  +        // Create the listener, contextualise it, and then configure it using
  +        // the supplied model.
           final TypeFactory factory =
               m_typeManager.getFactory( TaskListener.ROLE );
  -        return (TaskListener)factory.create( name );
  +        final TaskListener listener = (TaskListener)factory.create( model.getName() );
  +        listener.contextualize( m_rootContext );
  +        m_configurer.configureElement( listener, model, m_rootContext );
  +        return listener;
       }
   
       /**
  @@ -210,9 +217,12 @@
           m_deployer = (Deployer)m_serviceManager.lookup( Deployer.ROLE );
           m_typeManager = (TypeManager)m_serviceManager.lookup( TypeManager.ROLE );
           m_libraryManager = (LibraryManager)m_serviceManager.lookup( LibraryManager.ROLE
);
  +        m_configurer = (Configurer)m_serviceManager.lookup( Configurer.ROLE );
   
  -        // create the root property store
  +        // create the root execution frame
           m_rootProps = createBaseStore( m_serviceManager );
  +        m_rootFrame = new DefaultExecutionFrame( "", new File("."), m_serviceManager );
  +        m_rootContext = new DefaultTaskContext( m_rootFrame, "<init>", "<init>"
);
       }
   
       public void start()
  @@ -406,13 +416,14 @@
       }
   
       /**
  -     * Creates the root property store.
  +     * Creates a root property store.
        */
  -    private PropertyStore createBaseStore( final ServiceManager serviceManager )
  +    private PropertyStore createBaseStore( final DefaultServiceManager serviceManager )
           throws Exception
       {
           final DefaultPropertyStore store = new DefaultPropertyStore();
           ContainerUtil.service( store, serviceManager );
  +        serviceManager.put( PropertyStore.ROLE, store );
   
           //Add system properties
           addToStore( store, System.getProperties() );
  
  
  
  1.46      +33 -19    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/CLIMain.java
  
  Index: CLIMain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/CLIMain.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- CLIMain.java	28 May 2002 07:05:15 -0000	1.45
  +++ CLIMain.java	29 May 2002 13:03:32 -0000	1.46
  @@ -24,6 +24,7 @@
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.myrmidon.Constants;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.interfaces.BasicLogger;
   import org.apache.myrmidon.interfaces.EmbeddedAnt;
   import org.apache.myrmidon.interfaces.executor.Executor;
  @@ -34,7 +35,7 @@
    * to run project.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.45 $ $Date: 2002/05/28 07:05:15 $
  + * @version $Revision: 1.46 $ $Date: 2002/05/29 13:03:32 $
    */
   public class CLIMain
   {
  @@ -62,6 +63,7 @@
       private static final int DRY_RUN_OPT = 9;
       private static final int DEBUG_OPT = 10;
       private static final int TYPE_OPT = 11;
  +    private static final int BANNER_OPT = 12;
   
       //incompatable options for info options
       private static final int[] INFO_OPT_INCOMPAT = new int[]
  @@ -69,7 +71,8 @@
           HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT,
           LOG_LEVEL_OPT, BUILDER_PARAM_OPT, NO_PREFIX_OPT,
           VERSION_OPT, LISTENER_OPT, EXTLIB_DIR_OPT,
  -        INCREMENTAL_OPT, HOME_DIR_OPT, DRY_RUN_OPT, TYPE_OPT
  +        INCREMENTAL_OPT, HOME_DIR_OPT, DRY_RUN_OPT, TYPE_OPT,
  +        BANNER_OPT
       };
   
       //incompatable options for other logging options
  @@ -79,12 +82,6 @@
       };
   
       //incompatible options for listener options
  -    private static final int[] LISTENER_OPT_INCOMPAT = new int[]
  -    {
  -        LISTENER_OPT, NO_PREFIX_OPT
  -    };
  -
  -    //incompatible options for listener options
       private static final int[] RUNSTYLE_OPT_INCOMPAT = new int[]
       {
           GUI_OPT, INCREMENTAL_OPT
  @@ -99,6 +96,11 @@
       ///Enables incremental mode
       private boolean m_incremental;
   
  +    ///The name of the listener to use
  +    private String m_listenerName = "default";
  +    private boolean m_prefix = true;
  +    private boolean m_banner = false;
  +
       ///The launcher
       private final EmbeddedAnt m_embedded = new EmbeddedAnt();
   
  @@ -174,7 +176,7 @@
                                       CLOptionDescriptor.ARGUMENT_REQUIRED,
                                       FILE_OPT,
                                       REZ.getString( "file.opt" ) ),
  -            new CLOptionDescriptor( "log-level",
  +            new CLOptionDescriptor( "loglevel",
                                       CLOptionDescriptor.ARGUMENT_REQUIRED,
                                       LOG_LEVEL_OPT,
                                       REZ.getString( "log-level.opt" ),
  @@ -197,19 +199,21 @@
               new CLOptionDescriptor( "listener",
                                       CLOptionDescriptor.ARGUMENT_REQUIRED,
                                       LISTENER_OPT,
  -                                    REZ.getString( "listener.opt" ),
  -                                    LISTENER_OPT_INCOMPAT ),
  +                                    REZ.getString( "listener.opt" ) ),
               new CLOptionDescriptor( "noprefix",
                                       CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                       NO_PREFIX_OPT,
  -                                    REZ.getString( "noprefix.opt" ),
  -                                    LISTENER_OPT_INCOMPAT ),
  +                                    REZ.getString( "noprefix.opt" ) ),
  +            new CLOptionDescriptor( "banner",
  +                                    CLOptionDescriptor.ARGUMENT_DISALLOWED,
  +                                    BANNER_OPT,
  +                                    REZ.getString( "banner.opt" ) ),
               new CLOptionDescriptor( "version",
                                       CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                       VERSION_OPT,
                                       REZ.getString( "version.opt" ),
                                       INFO_OPT_INCOMPAT ),
  -            new CLOptionDescriptor( "ext-path",
  +            new CLOptionDescriptor( "extpath",
                                       CLOptionDescriptor.ARGUMENT_REQUIRED,
                                       EXTLIB_DIR_OPT,
                                       REZ.getString( "extlib.opt" ) ),
  @@ -218,7 +222,7 @@
                                       INCREMENTAL_OPT,
                                       REZ.getString( "incremental.opt" ),
                                       CLIMain.RUNSTYLE_OPT_INCOMPAT ),
  -            new CLOptionDescriptor( "ant-home",
  +            new CLOptionDescriptor( "anthome",
                                       CLOptionDescriptor.ARGUMENT_REQUIRED,
                                       HOME_DIR_OPT,
                                       REZ.getString( "home.opt" ) ),
  @@ -227,11 +231,11 @@
                                       DEFINE_OPT,
                                       REZ.getString( "define.opt" ),
                                       new int[ 0 ] ),
  -            new CLOptionDescriptor( "builder-parameter",
  +            new CLOptionDescriptor( "builderparam",
                                       CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
                                       BUILDER_PARAM_OPT,
                                       REZ.getString( "build.opt" ) ),
  -            new CLOptionDescriptor( "dry-run",
  +            new CLOptionDescriptor( "dryrun",
                                       CLOptionDescriptor.ARGUMENT_DISALLOWED,
                                       DRY_RUN_OPT,
                                       REZ.getString( "dry-run.opt" ) ),
  @@ -306,10 +310,13 @@
                       break;
   
                   case LISTENER_OPT:
  -                    embeddedAnt.setProjectListener( option.getArgument() );
  +                    m_listenerName = option.getArgument();
                       break;
                   case NO_PREFIX_OPT:
  -                    embeddedAnt.setProjectListener( "noprefix" );
  +                    m_prefix = false;
  +                    break;
  +                case BANNER_OPT:
  +                    m_banner = true;
                       break;
   
                   case DEFINE_OPT:
  @@ -364,6 +371,13 @@
               {
                   embeddedAnt.setEmbeddorProperty( Executor.ROLE, PRINTING_EXECUTOR );
               }
  +
  +            // Setup the listener
  +            final ModelElement listenerModel = new ModelElement( m_listenerName, "command-line:?:?"
);
  +            listenerModel.setAttribute( "level", BasicLogger.mapLogLevel( m_priority )
);
  +            listenerModel.setAttribute( "prefix", String.valueOf( m_prefix ) );
  +            listenerModel.setAttribute( "banner", String.valueOf( m_banner ) );
  +            m_embedded.addTaskListener( listenerModel );
   
               // Set the common and container classloaders
               final ClassLoader sharedClassLoader = (ClassLoader)properties.get( "myrmidon.shared.classloader"
);
  
  
  
  1.13      +2 -1      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/Resources.properties,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Resources.properties	28 May 2002 07:05:15 -0000	1.12
  +++ Resources.properties	29 May 2002 13:03:32 -0000	1.13
  @@ -7,7 +7,8 @@
   verbose.opt=Equivalent to --log-level=VERBOSE.
   debug.opt=Equivalent to --log-level=DEBUG.
   listener.opt=Specify the listener for log events.
  -noprefix.opt=Do not prefix output with the task name.  Equivalent to --listener noprefix.
  +noprefix.opt=Do not prefix output with the task name.
  +banner.opt=Include a target banner in the output, for every target executed.
   version.opt=Display version.
   extlib.opt=Specify the path to use to search for optional packages.
   incremental.opt=Run in incremental mode.
  
  
  
  1.4       +23 -1     jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/BasicLogger.java
  
  Index: BasicLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/BasicLogger.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BasicLogger.java	28 May 2002 05:12:40 -0000	1.3
  +++ BasicLogger.java	29 May 2002 13:03:32 -0000	1.4
  @@ -14,7 +14,7 @@
    * A basic logger that just prints out messages to <code>System.out</code>.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.3 $ $Date: 2002/05/28 05:12:40 $
  + * @version $Revision: 1.4 $ $Date: 2002/05/29 13:03:32 $
    */
   public class BasicLogger
       extends AbstractLogger
  @@ -74,6 +74,28 @@
           else
           {
               throw new IllegalArgumentException( "Unknown Level: " + logLevel );
  +        }
  +    }
  +
  +    /**
  +     * Returns the name for a log level.
  +     */
  +    public static String mapLogLevel( int logLevel )
  +    {
  +        switch( logLevel )
  +        {
  +            case LEVEL_DEBUG:
  +                return "DEBUG";
  +            case LEVEL_INFO:
  +                return "VERBOSE";
  +            case LEVEL_WARN:
  +                return "INFO";
  +            case LEVEL_ERROR:
  +                return "WARN";
  +            case LEVEL_FATAL:
  +                return "ERROR";
  +            default:
  +                throw new IllegalArgumentException( "Unknown Level: " + logLevel );
           }
       }
   
  
  
  
  1.14      +29 -35    jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/EmbeddedAnt.java
  
  Index: EmbeddedAnt.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/EmbeddedAnt.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- EmbeddedAnt.java	23 May 2002 06:21:47 -0000	1.13
  +++ EmbeddedAnt.java	29 May 2002 13:03:32 -0000	1.14
  @@ -15,15 +15,12 @@
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.excalibur.io.FileUtil;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.activity.Startable;
   import org.apache.avalon.framework.container.ContainerUtil;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.api.event.TaskListener;
   import org.apache.myrmidon.interfaces.embeddor.Embeddor;
   import org.apache.myrmidon.interfaces.event.TaskEventManager;
  @@ -43,7 +40,7 @@
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.13 $ $Date: 2002/05/23 06:21:47 $
  + * @version $Revision: 1.14 $ $Date: 2002/05/29 13:03:32 $
    */
   public class EmbeddedAnt
       extends AbstractLogEnabled
  @@ -61,7 +58,6 @@
   
       private String m_projectFile = "build.ant";
       private Project m_project;
  -    private String m_listenerName = "default";
       private ClassLoader m_sharedClassLoader;
       private Embeddor m_embeddor;
       private File m_homeDir;
  @@ -110,16 +106,21 @@
       }
   
       /**
  -     * Sets the name of the project listener to use.  Set to null to disable
  -     * the project listener.
  +     * Adds a task listener.  The listener is created and configured using
  +     * the supplied model.
  +     *
  +     * @param model The configuration for the listener to add.
        */
  -    public void setProjectListener( final String listener )
  +    public void addTaskListener( final ModelElement model )
       {
  -        m_listenerName = listener;
  +        m_listeners.add( model );
       }
   
       /**
  -     * Adds a task listener.
  +     * Adds a task listener.  The supplied listener must be configured by the
  +     * caller.
  +     *
  +     * @param listener The listener to add.
        */
       public void addTaskListener( final TaskListener listener )
       {
  @@ -147,12 +148,10 @@
   
       /**
        * Sets a task engine property.  These are used to configure the task engine.
  -     *
  -     * @todo Make this method actually work with objects...
        */
       public void setEmbeddorProperty( final String name, final Object value )
       {
  -        m_embeddorParameters.put( name, value.toString() );
  +        m_embeddorParameters.put( name, value );
       }
   
       /**
  @@ -278,7 +277,7 @@
        * Make sure myrmidon home directory has been specified, and is a
        * directory.  Set the paths that the embeddor expects.
        */
  -    private void setupPaths( Map parameters ) throws Exception
  +    private void setupPaths( final Map parameters ) throws Exception
       {
           if( m_homeDir == null )
           {
  @@ -313,20 +312,10 @@
           if( m_embeddor == null )
           {
               m_embeddor = createEmbeddor();
  -            setupLogger( m_embeddor );
  -            if( m_embeddor instanceof Contextualizable )
  -            {
  -                final Context context = new DefaultContext( parameters );
  -                ( (Contextualizable)m_embeddor ).contextualize( context );
  -            }
  -            if( m_embeddor instanceof Initializable )
  -            {
  -                ( (Initializable)m_embeddor ).initialize();
  -            }
  -            if( m_embeddor instanceof Startable )
  -            {
  -                ( (Startable)m_embeddor ).start();
  -            }
  +            ContainerUtil.enableLogging( m_embeddor, getLogger() );
  +            ContainerUtil.contextualize( m_embeddor, new DefaultContext( parameters ) );
  +            ContainerUtil.initialize( m_embeddor );
  +            ContainerUtil.start( m_embeddor );
           }
           return m_embeddor;
       }
  @@ -357,15 +346,20 @@
           throws Exception
       {
           final TaskEventManager eventManager = frame.getTaskEventManager();
  -        if( m_listenerName != null )
  -        {
  -            final TaskListener listener = embeddor.createListener( m_listenerName );
  -            eventManager.addTaskListener( listener );
  -        }
           final int count = m_listeners.size();
           for( int i = 0; i < count; i++ )
           {
  -            final TaskListener listener = (TaskListener)m_listeners.get( i );
  +            final Object obj = m_listeners.get( i );
  +            final TaskListener listener;
  +            if( obj instanceof TaskListener )
  +            {
  +                listener = (TaskListener)obj;
  +            }
  +            else
  +            {
  +                final ModelElement model = (ModelElement)obj;
  +                listener = embeddor.createListener( model );
  +            }
               eventManager.addTaskListener( listener );
           }
       }
  
  
  
  1.18      +4 -3      jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/embeddor/Embeddor.java
  
  Index: Embeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/interfaces/embeddor/Embeddor.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Embeddor.java	29 May 2002 06:42:26 -0000	1.17
  +++ Embeddor.java	29 May 2002 13:03:32 -0000	1.18
  @@ -10,6 +10,7 @@
   import java.util.Map;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.myrmidon.api.event.TaskListener;
  +import org.apache.myrmidon.api.metadata.ModelElement;
   import org.apache.myrmidon.interfaces.oldmodel.Project;
   import org.apache.myrmidon.interfaces.workspace.Workspace;
   import org.apache.myrmidon.interfaces.executor.ExecutionFrame;
  @@ -18,7 +19,7 @@
    * Interface through which you embed Myrmidon into applications.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.17 $ $Date: 2002/05/29 06:42:26 $
  + * @version $Revision: 1.18 $ $Date: 2002/05/29 13:03:32 $
    */
   public interface Embeddor
   {
  @@ -45,11 +46,11 @@
       /**
        * Creates a task listener.
        *
  -     * @param name The shorthand name of the listener.
  +     * @param model The model to use to create and configure the listener.
        * @return the listener.
        * @throws Exception If the listener could not be created.
        */
  -    TaskListener createListener( String name )
  +    TaskListener createListener( ModelElement model )
           throws Exception;
   
       /**
  
  
  
  1.2       +12 -1     jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/TrackingTaskListener.java
  
  Index: TrackingTaskListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/test/org/apache/myrmidon/TrackingTaskListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TrackingTaskListener.java	11 May 2002 12:44:00 -0000	1.1
  +++ TrackingTaskListener.java	29 May 2002 13:03:33 -0000	1.2
  @@ -11,13 +11,15 @@
   import junit.framework.Assert;
   import org.apache.myrmidon.api.event.TaskEvent;
   import org.apache.myrmidon.api.event.TaskListener;
  +import org.apache.myrmidon.api.TaskContext;
  +import org.apache.myrmidon.api.TaskException;
   
   /**
    * A task listener that asserts that it receives a particular sequence of
    * events.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.1 $ $Date: 2002/05/11 12:44:00 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/29 13:03:33 $
    */
   public class TrackingTaskListener
       extends Assert
  @@ -25,6 +27,15 @@
   {
       private final ArrayList m_taskStack = new ArrayList();
       private String m_currentTask;
  +
  +    /**
  +     * Sets the context that the listener operates in.  The listener uses
  +     * this context to access the services provided by the container.
  +     */
  +    public void contextualize( final TaskContext context )
  +        throws TaskException
  +    {
  +    }
   
       /**
        * Notify the listener that the task is starting.
  
  
  
  1.2       +3 -1      jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/listener/AbstractProjectListener.java
  
  Index: AbstractProjectListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/listener/AbstractProjectListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractProjectListener.java	18 May 2002 04:19:34 -0000	1.1
  +++ AbstractProjectListener.java	29 May 2002 13:03:33 -0000	1.2
  @@ -7,13 +7,15 @@
    */
   package org.apache.myrmidon.framework.listener;
   
  +
  +
   /**
    * Abstract listener from which to extend.  This implementation provedes
    * empty implementions of each of the event methods.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
  - * @version $Revision: 1.1 $ $Date: 2002/05/18 04:19:34 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/29 13:03:33 $
    */
   public abstract class AbstractProjectListener
       implements ProjectListener
  
  
  
  1.2       +15 -2     jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/listener/ProjectEvent.java
  
  Index: ProjectEvent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/listener/ProjectEvent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProjectEvent.java	18 May 2002 04:19:34 -0000	1.1
  +++ ProjectEvent.java	29 May 2002 13:03:33 -0000	1.2
  @@ -9,13 +9,14 @@
   
   import java.util.EventObject;
   import org.apache.myrmidon.api.event.TaskEvent;
  +import org.apache.myrmidon.api.event.LogLevel;
   
   /**
    * An event raised while processing an Ant project.
    *
    * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2002/05/18 04:19:34 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/29 13:03:33 $
    */
   public class ProjectEvent
       extends EventObject
  @@ -45,12 +46,18 @@
        */
       private final Throwable m_throwable;
   
  +    /**
  +     * The log level of the event.
  +     */
  +    private final LogLevel m_logLevel;
  +
       public ProjectEvent( final TaskEvent source,
                            final String projectName,
                            final String targetName,
                            final String taskName,
                            final String message,
  -                         final Throwable throwable )
  +                         final Throwable throwable,
  +                         final LogLevel logLevel )
       {
           super( source );
           m_projectName = projectName;
  @@ -58,6 +65,7 @@
           m_taskName = taskName;
           m_message = message;
           m_throwable = throwable;
  +        m_logLevel = logLevel;
       }
   
       public String getProject()
  @@ -88,5 +96,10 @@
       public TaskEvent getTaskEvent()
       {
           return (TaskEvent)getSource();
  +    }
  +
  +    public LogLevel getLogLevel()
  +    {
  +        return m_logLevel;
       }
   }
  
  
  
  1.2       +33 -3     jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/listener/TaskToProjectListenerAdapter.java
  
  Index: TaskToProjectListenerAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/framework/src/java/org/apache/myrmidon/framework/listener/TaskToProjectListenerAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TaskToProjectListenerAdapter.java	18 May 2002 04:19:34 -0000	1.1
  +++ TaskToProjectListenerAdapter.java	29 May 2002 13:03:33 -0000	1.2
  @@ -10,18 +10,25 @@
   import java.util.StringTokenizer;
   import org.apache.myrmidon.api.event.TaskEvent;
   import org.apache.myrmidon.api.event.TaskListener;
  +import org.apache.myrmidon.api.event.AbstractTaskListener;
  +import org.apache.myrmidon.api.metadata.Modeller;
  +import org.apache.myrmidon.api.metadata.ModelException;
  +import org.apache.myrmidon.api.metadata.ModelElement;
  +import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.framework.listener.ProjectEvent;
   import org.apache.myrmidon.framework.listener.ProjectListener;
  +import org.apache.myrmidon.interfaces.configurer.Configurer;
   
   /**
    * This is a class that adapts {@link org.apache.myrmidon.api.event.TaskListener} interface
to
    * the {@link org.apache.myrmidon.framework.listener.ProjectListener} interface.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @version $Revision: 1.1 $ $Date: 2002/05/18 04:19:34 $
  + * @version $Revision: 1.2 $ $Date: 2002/05/29 13:03:33 $
    */
   public class TaskToProjectListenerAdapter
  -    implements TaskListener
  +    extends AbstractTaskListener
  +    implements TaskListener, Modeller
   {
       private final ProjectListener m_listener;
   
  @@ -36,6 +43,28 @@
       }
   
       /**
  +     * Pass the object a read-only instance of it's own
  +     * model.
  +     *
  +     * @param element the ModelElement representing object
  +     * @throws ModelException if there is an error interpreting model
  +     */
  +    public void model( final ModelElement element )
  +        throws ModelException
  +    {
  +        final Configurer configurer;
  +        try
  +        {
  +            configurer = (Configurer)getContext().getService( Configurer.class );
  +        }
  +        catch( final TaskException e )
  +        {
  +            throw new ModelException( e.getMessage(), e );
  +        }
  +        configurer.configureElement( m_listener, element, getContext() );
  +    }
  +
  +    /**
        * Notify the listener that the task is starting.
        * This is called prior to task starting.
        *
  @@ -127,7 +156,8 @@
                                    targetName,
                                    taskName,
                                    event.getMessage(),
  -                                 event.getThrowable() );
  +                                 event.getThrowable(),
  +                                 event.getLogLevel() );
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message