ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/manager DefaultProjectManager.java LogTargetToListenerAdapter.java ProjectListenerSupport.java ProjectManager.java
Date Tue, 29 May 2001 09:13:36 GMT
donaldp     01/05/29 02:13:36

  Modified:    proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        Embeddor.java MyrmidonEmbeddor.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/components/manager
                        DefaultProjectManager.java
                        LogTargetToListenerAdapter.java
                        ProjectListenerSupport.java ProjectManager.java
  Removed:     proposal/myrmidon/src/java/org/apache/ant/project
                        DefaultProjectEngine.java
                        LogTargetToListenerAdapter.java ProjectEngine.java
                        ProjectListenerSupport.java
  Log:
  ProjectEngine->ProjectManager (need a better name).
  
  Revision  Changes    Path
  1.4       +2 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/Embeddor.java
  
  Index: Embeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/Embeddor.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Embeddor.java	2001/05/29 07:33:23	1.3
  +++ Embeddor.java	2001/05/29 09:13:32	1.4
  @@ -7,13 +7,13 @@
    */
   package org.apache.myrmidon.components.embeddor;
   
  -import org.apache.ant.project.ProjectEngine;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Startable;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.myrmidon.components.builder.ProjectBuilder;
  +import org.apache.myrmidon.components.manager.ProjectManager;
   
   /**
    * Interface through which you embed Myrmidon into applications.
  @@ -37,5 +37,5 @@
        *
        * @return the ProjectBuilder
        */
  -    ProjectEngine getProjectEngine();
  +    ProjectManager getProjectManager();
   }
  
  
  
  1.5       +6 -6      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java
  
  Index: MyrmidonEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/MyrmidonEmbeddor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MyrmidonEmbeddor.java	2001/05/29 07:33:23	1.4
  +++ MyrmidonEmbeddor.java	2001/05/29 09:13:33	1.5
  @@ -10,7 +10,6 @@
   import java.io.File;
   import org.apache.ant.AntException;
   import org.apache.ant.convert.engine.ConverterEngine;
  -import org.apache.ant.project.ProjectEngine;
   import org.apache.ant.tasklet.engine.DataTypeEngine;
   import org.apache.ant.tasklet.engine.TskDeployer;
   import org.apache.avalon.excalibur.io.FileUtil;
  @@ -29,6 +28,7 @@
   import org.apache.myrmidon.components.builder.ProjectBuilder;
   import org.apache.myrmidon.components.configurer.Configurer;
   import org.apache.myrmidon.components.executor.Executor;
  +import org.apache.myrmidon.components.manager.ProjectManager;
   
   /**
    * Default implementation of Ant runtime.
  @@ -42,7 +42,7 @@
       private ConverterEngine          m_converterEngine;
       private DataTypeEngine           m_dataTypeEngine;
       private Executor                 m_executor;
  -    private ProjectEngine            m_projectEngine;
  +    private ProjectManager            m_projectEngine;
   
       private ProjectBuilder           m_builder;
       private TskDeployer              m_deployer;
  @@ -87,7 +87,7 @@
        *
        * @return the ProjectBuilder
        */
  -    public ProjectEngine getProjectEngine()
  +    public ProjectManager getProjectManager()
       {
           return m_projectEngine;
       }
  @@ -174,7 +174,7 @@
           defaults.setParameter( "ant.comp.task",
                                  "org.apache.myrmidon.components.executor.DefaultExecutor"
);
           defaults.setParameter( "ant.comp.project",
  -                               "org.apache.ant.project.DefaultProjectEngine" );
  +                               "org.apache.myrmidon.components.manager.DefaultProjectManager"
);
           defaults.setParameter( "ant.comp.builder",
                                  "org.apache.myrmidon.components.builder.DefaultProjectBuilder"
);
           defaults.setParameter( "ant.comp.deployer",
  @@ -194,7 +194,7 @@
       {
           final DefaultComponentManager componentManager = new DefaultComponentManager();
   
  -        componentManager.put( "org.apache.ant.project.ProjectEngine", m_projectEngine );
  +        componentManager.put( "org.apache.myrmidon.components.manager.ProjectManager",
m_projectEngine );
           componentManager.put( "org.apache.ant.convert.engine.ConverterEngine",
                                 m_converterEngine );
           componentManager.put( "org.apache.ant.convert.Converter", m_converterEngine );
  @@ -229,7 +229,7 @@
           m_executor = (Executor)createComponent( component, Executor.class );
   
           component = getParameter( "ant.comp.project" );
  -        m_projectEngine = (ProjectEngine)createComponent( component, ProjectEngine.class
);
  +        m_projectEngine = (ProjectManager)createComponent( component, ProjectManager.class
);
   
           component = getParameter( "ant.comp.builder" );
           m_builder =(ProjectBuilder)createComponent( component, ProjectBuilder.class );
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/manager/DefaultProjectManager.java
  
  Index: DefaultProjectManager.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 file.
   */
  package org.apache.myrmidon.components.manager;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import org.apache.ant.AntException;
  import org.apache.ant.util.Condition;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.DefaultComponentManager;
  import org.apache.avalon.framework.component.DefaultComponentManager;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.log.Logger;
  import org.apache.myrmidon.api.DefaultTaskContext;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.components.executor.Executor;
  import org.apache.myrmidon.components.model.Project;
  import org.apache.myrmidon.components.model.Target;
  import org.apache.myrmidon.listeners.ProjectListener;
  
  /**
   * This is the default implementation of ProjectEngine.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class DefaultProjectManager
      extends AbstractLoggable
      implements ProjectManager, Composable
  {
      private Executor                 m_executor;
      private ProjectListenerSupport   m_listenerSupport = new ProjectListenerSupport();
      private DefaultComponentManager  m_componentManager;
  
      /**
       * Add a listener to project events.
       *
       * @param listener the listener
       */
      public void addProjectListener( final ProjectListener listener )
      {
          m_listenerSupport.addProjectListener( listener );
      }
  
      /**
       * Remove a listener from project events.
       *
       * @param listener the listener
       */
      public void removeProjectListener( final ProjectListener listener )
      {
          m_listenerSupport.removeProjectListener( listener );
      }
  
      /**
       * Retrieve relevent services needed for engine.
       *
       * @param componentManager the ComponentManager
       * @exception ComponentException if an error occurs
       */
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          m_componentManager = (DefaultComponentManager)componentManager;
          m_executor = (Executor)componentManager.
              lookup( "org.apache.myrmidon.components.executor.Executor" );
      }
  
      /**
       * Execute a target in a particular project.
       * Execute in the project context.
       *
       * @param project the Project
       * @param target the name of the target
       * @exception AntException if an error occurs
       */
      public void executeTarget( final Project project, final String target, final TaskContext
context )
          throws AntException
      {
          //HACK: should do this a better way !!!!!!
          m_componentManager.put( "org.apache.ant.project.Project", project );
  
          m_listenerSupport.projectStarted();
  
          executeTargetWork( "<init>", project.getImplicitTarget(), context );
  
          execute( project, target, context );
  
          m_listenerSupport.projectFinished();
      }
  
      /**
       * Execute a target in a particular project, in a particular context.
       *
       * @param project the Project
       * @param target the name of the target
       * @param context the context
       * @exception AntException if an error occurs
       */
      public void execute( Project project, String target, TaskContext context )
          throws AntException
      {
          execute( project, target, context, new ArrayList() );
      }
  
      /**
       * Helper method to execute a target.
       *
       * @param project the Project
       * @param target the name of the target
       * @param context the context
       * @param done the list of targets already executed in current run
       * @exception AntException if an error occurs
       */
      private void execute( final Project project,
                            final String targetName,
                            final TaskContext context,
                            final ArrayList done )
          throws AntException
      {
          final Target target = project.getTarget( targetName );
  
          if( null == target )
          {
              throw new AntException( "Unable to find target " + targetName );
          }
  
          //add target to list of targets executed
          done.add( targetName );
  
          //execute all dependencies
          final String[] dependencies = target.getDependencies();
          for( int i = 0; i < dependencies.length; i++ )
          {
              if( !done.contains( dependencies[ i ] ) )
              {
                  execute( project, dependencies[ i ], context, done );
              }
          }
  
          executeTarget( targetName, target, context );
      }
  
      /**
       * Method to execute a particular target instance.
       *
       * @param targetName the name of target
       * @param target the target
       * @param context the context in which to execute
       * @exception AntException if an error occurs
       */
      private void executeTarget( final String targetName,
                                  final Target target,
                                  final TaskContext context )
          throws AntException
      {
          //is this necessary ? I think not but ....
          // NO it isn't because you set target name and project has already been provided
          //m_componentManager.put( "org.apache.ant.project.Target", target );
  
          //create project context and set target name
          final TaskContext targetContext = new DefaultTaskContext( context );
          targetContext.setProperty( Project.TARGET, targetName );
  
          //notify listeners
          m_listenerSupport.targetStarted( targetName );
  
          //actually do the execution work
          executeTargetWork( targetName, target, targetContext );
  
          //notify listeners
          m_listenerSupport.targetFinished();
      }
  
      /**
       * Do the work associated with target.
       * ie execute all tasks
       *
       * @param name the name of target
       * @param target the target
       * @param context the context
       */
      private void executeTargetWork( final String name,
                                      final Target target,
                                      final TaskContext context )
      {
          //check the condition associated with target.
          //if it is not satisfied then skip target
          final Condition condition = target.getCondition();
          if( null != condition )
          {
              if( false == condition.evaluate( context ) )
              {
                  getLogger().debug( "Skipping target " + name +
                                     " as it does not satisfy condition" );
                  return;
              }
          }
  
          getLogger().debug( "Executing target " + name );
  
          //execute all tasks assciated with target
          final Configuration[] tasks = target.getTasks();
          for( int i = 0; i < tasks.length; i++ )
          {
              executeTask( tasks[ i ], context );
          }
      }
  
      /**
       * Execute a task.
       *
       * @param task the task definition
       * @param context the context
       * @exception AntException if an error occurs
       */
      private void executeTask( final Configuration task, final TaskContext context )
          throws AntException
      {
          final String name = task.getName();
          getLogger().debug( "Executing task " + name );
  
          //Set up context for task...
          //is Only necessary if we are multi-threaded
          //final TaskletContext targetContext = new DefaultTaskletContext( context );
  
          //is setting name even necessary ???
          context.setProperty( TaskContext.NAME, name );
  
          //notify listeners
          m_listenerSupport.taskStarted( name );
  
          //run task
          m_executor.execute( task, context );
  
          //notify listeners task has ended
          m_listenerSupport.taskFinished();
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/manager/LogTargetToListenerAdapter.java
  
  Index: LogTargetToListenerAdapter.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 file.
   */
  package org.apache.myrmidon.components.manager;
  
  import org.apache.log.LogEvent;
  import org.apache.log.LogTarget;
  import org.apache.myrmidon.listeners.ProjectListener;
  
  /**
   * Adapter between Avalon LogKit and Project listener interfaces.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class LogTargetToListenerAdapter
      implements LogTarget
  {
      private final ProjectListener    m_listener;
  
      /**
       * Constructor taking listener to convert to.
       *
       * @param listener the ProjectListener
       */
      public LogTargetToListenerAdapter( final ProjectListener listener )
      {
          m_listener = listener;
      }
  
      /**
       * Process a log event.
       *
       * @param event the event
       */
      public void processEvent( final LogEvent event )
      {
          if( null == event.getThrowable() )
          {
              m_listener.log( event.getMessage() );
          }
          else
          {
              m_listener.log( event.getMessage(), event.getThrowable() );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/manager/ProjectListenerSupport.java
  
  Index: ProjectListenerSupport.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 file.
   */
  package org.apache.myrmidon.components.manager;
  
  import org.apache.myrmidon.listeners.ProjectListener;
  
  /**
   * Support for the project listener event dispatching.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class ProjectListenerSupport
      implements ProjectListener
  {
      private ProjectListener[]   m_listeners = new ProjectListener[ 0 ];
  
      /**
       * Add an extra project listener that wants to receive notification of listener events.
       *
       * @param listener the listener
       */
      public void addProjectListener( final ProjectListener listener )
      {
          final ProjectListener[] listeners = new ProjectListener[ m_listeners.length + 1
];
          System.arraycopy( m_listeners, 0, listeners, 0, m_listeners.length );
          listeners[ m_listeners.length ] = listener;
          m_listeners = listeners;
      }
  
      /**
       * Remove a project listener that wants to receive notification of listener events.
       *
       * @param listener the listener
       */
      public void removeProjectListener( final ProjectListener listener )
      {
          int found = -1;
  
          for( int i = 0; i < m_listeners.length; i++ )
          {
              if( listener == m_listeners[ i ] )
              {
                  found = i;
                  break;
              }
          }
  
          if( -1 == found ) return;
  
          final ProjectListener[] listeners = new ProjectListener[ m_listeners.length - 1
];
          System.arraycopy( m_listeners, 0, listeners, 0, found );
  
          final int count = m_listeners.length - found - 1;
          System.arraycopy( m_listeners, found, listeners, found + 1, count );
  
          m_listeners = listeners;
      }
  
      /**
       * Fire a projectStarted event.
       */
      public void projectStarted()
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].projectStarted();
          }
      }
  
      /**
       * Fire a projectFinished event.
       */
      public void projectFinished()
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].projectFinished();
          }
      }
  
      /**
       * Fire a targetStarted event.
       *
       * @param targetName the name of target
       */
      public void targetStarted( String targetName )
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].targetStarted( targetName );
          }
      }
  
      /**
       * Fire a targetFinished event.
       */
      public void targetFinished()
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].targetFinished();
          }
      }
  
      /**
       * Fire a targetStarted event.
       *
       * @param targetName the name of target
       */
      public void taskStarted( String taskName )
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].taskStarted( taskName );
          }
      }
  
      /**
       * Fire a taskFinished event.
       */
      public void taskFinished()
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].taskFinished();
          }
      }
  
      /**
       * Fire a log event.
       *
       * @param message the log message
       */
      public void log( String message )
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].log( message );
          }
      }
  
      /**
       * Fire a log event.
       *
       * @param message the log message
       * @param throwable the throwable to be logged
       */
      public void log( String message, Throwable throwable )
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].log( message, throwable );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/manager/ProjectManager.java
  
  Index: ProjectManager.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 file.
   */
  package org.apache.myrmidon.components.manager;
  
  import org.apache.ant.AntException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.components.model.Project;
  import org.apache.myrmidon.listeners.ProjectListener;
  
  /**
   * This is the abstraction through which Projects are executed.
   * TODO: Think of better name
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public interface ProjectManager
      extends Component
  {
      /**
       * Add a listener to project events.
       *
       * @param listener the listener
       */
      void addProjectListener( ProjectListener listener );
  
      /**
       * Remove a listener from project events.
       *
       * @param listener the listener
       */
      void removeProjectListener( ProjectListener listener );
  
      /**
       * Execute a target in a particular project, in a particular context.
       *
       * @param project the Project
       * @param target the name of the target
       * @param context the context
       * @exception AntException if an error occurs
       */
      void executeTarget( Project project, String target, TaskContext context )
          throws AntException;
  }
  
  
  

Mime
View raw message