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/make sample.ant
Date Tue, 05 Jun 2001 07:54:36 GMT
donaldp     01/06/05 00:54:36

  Modified:    proposal/myrmidon build.sh
               proposal/myrmidon/lib avalon-excalibur.jar
                        avalon-framework.jar
               proposal/myrmidon/src/java/org/apache/myrmidon/api
                        AbstractTask.java DefaultTaskContext.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor
                        DefaultEmbeddor.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/executor
                        DefaultExecutor.java
               proposal/myrmidon/src/make sample.ant
  Added:       proposal/myrmidon/lib crimson.jar jaxp.jar
               proposal/myrmidon/src/java/org/apache/myrmidon/components/executor
                        AspectAwareExecutor.java
  Removed:     proposal/myrmidon/lib xerces.jar
  Log:
  Updated to work with JAXP1.1 and crimson (as it is smaller).
  
  Also implemented infrastructure for aspect handling. Aspects are now called out to and can
do all the things we have discussed. The only thing not implemented is actually passing parameters
and elements to aspect handler for each task.
  
  Revision  Changes    Path
  1.5       +1 -1      jakarta-ant/proposal/myrmidon/build.sh
  
  Index: build.sh
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/build.sh,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- build.sh	2001/05/28 06:28:05	1.4
  +++ build.sh	2001/06/05 07:54:21	1.5
  @@ -10,6 +10,6 @@
   chmod u+x $MYRMIDON_HOME/bin/ant
   
   export ANT_HOME=
  -export CLASSPATH=lib/xerces.jar
  +export CLASSPATH=lib/crimson.jar:lib/jaxp.jar
   
   $MYRMIDON_HOME/bin/ant -logger org.apache.tools.ant.NoBannerLogger -emacs $@
  
  
  
  1.2       +346 -265  jakarta-ant/proposal/myrmidon/lib/avalon-excalibur.jar
  
  	<<Binary file>>
  
  
  1.3       +128 -119  jakarta-ant/proposal/myrmidon/lib/avalon-framework.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-ant/proposal/myrmidon/lib/crimson.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-ant/proposal/myrmidon/lib/jaxp.jar
  
  	<<Binary file>>
  
  
  1.4       +0 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java
  
  Index: AbstractTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractTask.java	2001/05/29 12:06:16	1.3
  +++ AbstractTask.java	2001/06/05 07:54:28	1.4
  @@ -63,7 +63,6 @@
        * @exception Exception if an error occurs
        */
       public void dispose()
  -        throws Exception
       {
       }
   
  
  
  
  1.5       +4 -4      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/DefaultTaskContext.java
  
  Index: DefaultTaskContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/api/DefaultTaskContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultTaskContext.java	2001/06/03 13:11:40	1.4
  +++ DefaultTaskContext.java	2001/06/05 07:54:29	1.5
  @@ -165,23 +165,23 @@
           if( CURRENT == scope ) put( name, value );
           else if( PARENT == scope )
           {
  -            if( null == m_parent )
  +            if( null == getParent() )
               {
                   throw new TaskException( "Can't set a property with parent scope when context
" +
                                           " has no parent" );
               }
               else
               {
  -                ((DefaultTaskContext)m_parent).put( name, value );
  +                ((DefaultTaskContext)getParent()).put( name, value );
               }
           }
           else if( TOP_LEVEL == scope )
           {
               DefaultTaskContext context = this;
   
  -            while( null != context.m_parent )
  +            while( null != context.getParent() )
               {
  -                context = (DefaultTaskContext)context.m_parent;
  +                context = (DefaultTaskContext)context.getParent();
               }
   
               context.putValue( name, value );
  
  
  
  1.2       +2 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultEmbeddor.java	2001/06/04 12:44:34	1.1
  +++ DefaultEmbeddor.java	2001/06/05 07:54:32	1.2
  @@ -182,7 +182,8 @@
           defaults.setParameter( TypeManager.ROLE,
                                  "org.apache.myrmidon.components.type.DefaultTypeManager"
);
           defaults.setParameter( Executor.ROLE,
  -                               "org.apache.myrmidon.components.executor.DefaultExecutor"
);
  +                               //"org.apache.myrmidon.components.executor.DefaultExecutor"
);
  +                               "org.apache.myrmidon.components.executor.AspectAwareExecutor"
);
           defaults.setParameter( ProjectManager.ROLE,
                                  "org.apache.myrmidon.components.manager.DefaultProjectManager"
);
           defaults.setParameter( ProjectBuilder.ROLE,
  
  
  
  1.9       +28 -28    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java
  
  Index: DefaultExecutor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultExecutor.java	2001/06/03 06:10:05	1.8
  +++ DefaultExecutor.java	2001/06/05 07:54:33	1.9
  @@ -61,34 +61,34 @@
           }
       }
   
  -    public void execute( final Configuration taskData, final TaskContext context )
  +    public void execute( final Configuration taskModel, final TaskContext context )
           throws TaskException
       {
           getLogger().debug( "Creating" );
  -        final Task task = createTask( taskData.getName() );
  +        final Task task = createTask( taskModel.getName() );
           setupLogger( task );
   
           getLogger().debug( "Contextualizing" );
  -        doContextualize( task, taskData, context );
  +        doContextualize( task, taskModel, context );
   
           getLogger().debug( "Composing" );
  -        doCompose( task, taskData );
  +        doCompose( task, taskModel );
   
           getLogger().debug( "Configuring" );
  -        doConfigure( task, taskData, context );
  +        doConfigure( task, taskModel, context );
   
           getLogger().debug( "Initializing" );
  -        doInitialize( task, taskData );
  +        doInitialize( task, taskModel );
   
           getLogger().debug( "Running" );
   
           task.execute();
   
           getLogger().debug( "Disposing" );
  -        doDispose( task, taskData );
  +        doDispose( task, taskModel );
       }
   
  -    private Task createTask( final String name )
  +    protected final Task createTask( final String name )
           throws TaskException
       {
           try
  @@ -101,21 +101,21 @@
           }
       }
   
  -    private void doConfigure( final Task task,
  -                              final Configuration taskData,
  -                              final TaskContext context )
  +    protected final void doConfigure( final Task task,
  +                                      final Configuration taskModel,
  +                                      final TaskContext context )
           throws TaskException
       {
  -        try { m_configurer.configure( task, taskData, context ); }
  +        try { m_configurer.configure( task, taskModel, context ); }
           catch( final Throwable throwable )
           {
  -            throw new TaskException( "Error configuring task " +  taskData.getName() +
" at " +
  -                                     taskData.getLocation() + "(Reason: " +
  -                                     throwable.getMessage() + ")", throwable );
  +            throw new TaskException( "Error configuring task " +  taskModel.getName() +
" at " +
  +                                     taskModel.getLocation() + "(Reason: " +
  +                                     throwable.getMessage() + ")" );
           }
       }
   
  -    private void doCompose( final Task task, final Configuration taskData )
  +    protected final void doCompose( final Task task, final Configuration taskModel )
           throws TaskException
       {
           if( task instanceof Composable )
  @@ -123,15 +123,15 @@
               try { ((Composable)task).compose( m_componentManager ); }
               catch( final Throwable throwable )
               {
  -                throw new TaskException( "Error composing task " +  taskData.getName()
+ " at " +
  -                                         taskData.getLocation() + "(Reason: " +
  +                throw new TaskException( "Error composing task " +  taskModel.getName()
+ " at " +
  +                                         taskModel.getLocation() + "(Reason: " +
                                            throwable.getMessage() + ")", throwable );
               }
           }
       }
   
  -    private void doContextualize( final Task task,
  -                                  final Configuration taskData,
  +    protected final void doContextualize( final Task task,
  +                                  final Configuration taskModel,
                                     final TaskContext context )
           throws TaskException
       {
  @@ -144,13 +144,13 @@
           }
           catch( final Throwable throwable )
           {
  -            throw new TaskException( "Error contextualizing task " +  taskData.getName()
+ " at " +
  -                                     taskData.getLocation() + "(Reason: " +
  +            throw new TaskException( "Error contextualizing task " +  taskModel.getName()
+ " at " +
  +                                     taskModel.getLocation() + "(Reason: " +
                                        throwable.getMessage() + ")", throwable );
           }
       }
   
  -    private void doDispose( final Task task, final Configuration taskData )
  +    protected final void doDispose( final Task task, final Configuration taskModel )
           throws TaskException
       {
           if( task instanceof Disposable )
  @@ -158,14 +158,14 @@
               try { ((Disposable)task).dispose(); }
               catch( final Throwable throwable )
               {
  -                throw new TaskException( "Error disposing task " +  taskData.getName()
+ " at " +
  -                                         taskData.getLocation() + "(Reason: " +
  +                throw new TaskException( "Error disposing task " +  taskModel.getName()
+ " at " +
  +                                         taskModel.getLocation() + "(Reason: " +
                                            throwable.getMessage() + ")", throwable );
               }
           }
       }
   
  -    private void doInitialize( final Task task, final Configuration taskData )
  +    protected final void doInitialize( final Task task, final Configuration taskModel )
           throws TaskException
       {
           if( task instanceof Initializable )
  @@ -173,8 +173,8 @@
               try { ((Initializable)task).initialize(); }
               catch( final Throwable throwable )
               {
  -                throw new TaskException( "Error initializing task " +  taskData.getName()
+ " at " +
  -                                         taskData.getLocation() + "(Reason: " +
  +                throw new TaskException( "Error initializing task " +  taskModel.getName()
+ " at " +
  +                                         taskModel.getLocation() + "(Reason: " +
                                            throwable.getMessage() + ")", throwable );
               }
           }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java
  
  Index: AspectAwareExecutor.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.executor;
  
  import java.util.HashMap;
  import java.util.ArrayList;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.apache.myrmidon.api.Task;
  import org.apache.myrmidon.api.TaskContext;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.aspects.AspectHandler;
  import org.apache.myrmidon.components.aspect.AspectManager;
  
  public class AspectAwareExecutor
      extends DefaultExecutor
  {
      private final static Parameters       EMPTY_PARAMETERS;
      private final static Configuration[]  EMPTY_ELEMENTS       = new Configuration[ 0 ];
  
      static
      {
          EMPTY_PARAMETERS = new Parameters();
          EMPTY_PARAMETERS.makeReadOnly();
      }
  
      private AspectManager        m_aspectManager;
  
      public AspectAwareExecutor()
      {
      }
  
      /**
       * Retrieve relevent services.
       *
       * @param componentManager the ComponentManager
       * @exception ComponentException if an error occurs
       */
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          super.compose( componentManager );
  
          m_aspectManager = (AspectManager)componentManager.lookup( AspectManager.ROLE );
      }
  
      public void execute( final Configuration taskModel, final TaskContext context )
          throws TaskException
      {
          try
          {
              executeTask( taskModel, context );
          }
          catch( final TaskException te )
          {
              if( false == getAspectHandler().error( te ) )
              {
                  throw te;
              }
          }
      }
  
      private void executeTask( Configuration taskModel, final TaskContext context )
          throws TaskException
      {
          getLogger().debug( "Creating" );
  
          taskModel = getAspectHandler().preCreate( taskModel );
  
          taskModel = prepareAspects( taskModel );
  
          final Task task = createTask( taskModel.getName() );
          getAspectHandler().postCreate( task );
  
          getAspectHandler().preLoggable( getLogger() );
          setupLogger( task );
  
          getLogger().debug( "Contextualizing" );
          doContextualize( task, taskModel, context );
  
          getLogger().debug( "Composing" );
          doCompose( task, taskModel );
  
          getLogger().debug( "Configuring" );
          getAspectHandler().preConfigure( taskModel );
          doConfigure( task, taskModel, context );
  
          getLogger().debug( "Initializing" );
          doInitialize( task, taskModel );
  
          getLogger().debug( "Executing" );
          getAspectHandler().preExecute();
          task.execute();
  
          getLogger().debug( "Disposing" );
          getAspectHandler().preDestroy();
          doDispose( task, taskModel );
      }
  
      //TODO: Extract and clean taskModel here.
      //Get all parameters from model and provide to appropriate aspect.
      //aspect( final Parameters parameters, final Configuration[] elements )
      private Configuration prepareAspects( final Configuration taskModel )
          throws TaskException
      {
          final DefaultConfiguration newTaskModel = 
              new DefaultConfiguration( taskModel.getName(), taskModel.getLocation() );
          final HashMap parameterMap = new HashMap();
          final HashMap elementMap = new HashMap();
  
          processAttributes( taskModel, newTaskModel, parameterMap );
          processElements( taskModel, newTaskModel, elementMap );
  
          return newTaskModel;
      }
  
      private final void processElements( final Configuration taskModel, 
                                          final DefaultConfiguration newTaskModel,
                                          final HashMap map )
      {
          final Configuration[] elements = taskModel.getChildren();
          for( int i = 0; i < elements.length; i++ )
          {
              final String name = elements[ i ].getName();
              final int index = name.indexOf( ':' );
              
              if( -1 == index ) 
              {
                  newTaskModel.addChild( elements[ i ] );
              }
              else
              {
                  final String namespace = name.substring( 0, index );
                  final String localName = name.substring( index + 1 );
                  final ArrayList elementSet = getElements( namespace, map );
                  elementSet.add( elements[ i ] );
              }
          }
      }
  
      private final void processAttributes( final Configuration taskModel, 
                                            final DefaultConfiguration newTaskModel,
                                            final HashMap map )
      {
          final String[] attributes = taskModel.getAttributeNames();
          for( int i = 0; i < attributes.length; i++ )
          {
              final String name = attributes[ i ];
              final String value = taskModel.getAttribute( name, null );
  
              final int index = name.indexOf( ':' );
              
              if( -1 == index ) 
              {
                  newTaskModel.setAttribute( name, value );
              }
              else
              {
                  final String namespace = name.substring( 0, index );
                  final String localName = name.substring( index + 1 );
                  final Parameters parameters = getParameters( namespace, map );
                  parameters.setParameter( localName, value );
              }
          }
      }
  
      private final ArrayList getElements( final String namespace, final HashMap map )
      {
          ArrayList elements = (ArrayList)map.get( namespace );
  
          if( null == elements )
          {
              elements = new ArrayList();
              map.put( namespace, elements );
          }
  
          return elements;
      }
  
      private final Parameters getParameters( final String namespace, final HashMap map )
      {
          Parameters parameters = (Parameters)map.get( namespace );
  
          if( null == parameters )
          {
              parameters = new Parameters();
              map.put( namespace, parameters );
          }
  
          return parameters;
      }
  
      protected final AspectHandler getAspectHandler()
      {
          return m_aspectManager;
      }
  }
  
  
  
  1.3       +2 -0      jakarta-ant/proposal/myrmidon/src/make/sample.ant
  
  Index: sample.ant
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/make/sample.ant,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- sample.ant	2001/06/02 15:09:18	1.2
  +++ sample.ant	2001/06/05 07:54:35	1.3
  @@ -102,6 +102,8 @@
       <echo message="This should fail ...."/>
       <echo message="${blah}"/>
       <echo message="Whoa - it no fail. Did you use ant-call to call me and set param
blah?"/>
  +
  +    <echo ant:fail-on-error="true" message="This should fail ...."/>
     </target>
   
   </project>
  
  
  

Mime
View raw message