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/tools/lib ant.jar
Date Wed, 06 Jun 2001 06:12:58 GMT
donaldp     01/06/05 23:12:58

  Modified:    proposal/myrmidon/src/java/org/apache/myrmidon/aspects
                        AbstractAspectHandler.java AspectHandler.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect
                        AspectManager.java DefaultAspectManager.java
               proposal/myrmidon/src/java/org/apache/myrmidon/components/executor
                        AspectAwareExecutor.java
               proposal/myrmidon/src/java/org/apache/myrmidon/framework/ant1
                        TaskAdapter.java
               proposal/myrmidon/src/make sample.ant
               proposal/myrmidon/tools/lib ant.jar
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/aspects
                        NoopAspectHandler.java
  Log:
  Updated to use latest ant/avalon jars.
  
  Settings are now passed to aspect as appropriate. Empty ones passed to aspects that do no
have any defined on task.
  
  Attributes/elements that have namespace marked but have no equivelent aspect cause a TaskException
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/aspects/AbstractAspectHandler.java
  
  Index: AbstractAspectHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/aspects/AbstractAspectHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractAspectHandler.java	2001/06/05 04:35:55	1.2
  +++ AbstractAspectHandler.java	2001/06/06 06:12:44	1.3
  @@ -35,7 +35,7 @@
           return taskModel;
       }
   
  -    public void aspect( final Parameters parameters, final Configuration[] elements )
  +    public void aspectSettings( final Parameters parameters, final Configuration[] elements
)
           throws TaskException
       {
           m_aspectParameters = parameters;
  
  
  
  1.3       +1 -1      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/aspects/AspectHandler.java
  
  Index: AspectHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/aspects/AspectHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AspectHandler.java	2001/06/05 04:35:07	1.2
  +++ AspectHandler.java	2001/06/06 06:12:44	1.3
  @@ -24,7 +24,7 @@
       Configuration preCreate( Configuration taskModel )
           throws TaskException;
   
  -    void aspect( Parameters parameters, Configuration[] children )
  +    void aspectSettings( Parameters parameters, Configuration[] children )
           throws TaskException;
   
       void postCreate( Task task )
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/aspects/NoopAspectHandler.java
  
  Index: NoopAspectHandler.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.aspects;
  
  /**
   * A Noop aspect handler that does nothing.
   *
   * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
   */
  public class NoopAspectHandler
      extends AbstractAspectHandler
  {
  }
  
  
  
  1.2       +14 -3     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/AspectManager.java
  
  Index: AspectManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/AspectManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AspectManager.java	2001/06/04 12:45:33	1.1
  +++ AspectManager.java	2001/06/06 06:12:47	1.2
  @@ -7,8 +7,11 @@
    */
   package org.apache.myrmidon.components.aspect;
   
  -import org.apache.myrmidon.aspects.AspectHandler;
   import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.myrmidon.api.TaskException;
  +import org.apache.myrmidon.aspects.AspectHandler;
   
   /**
    * Manage and propogate Aspects.
  @@ -19,7 +22,15 @@
       extends Component, AspectHandler
   {
       String ROLE = "org.apache.myrmidon.components.aspect.AspectManager";
  +
  +    String[] getNames();
  +
  +    void dispatchAspectSettings( String name, Parameters parameters, Configuration[] elements
)
  +        throws TaskException;
  +
  +    void addAspectHandler( String name, AspectHandler handler )
  +        throws TaskException;
   
  -    void addAspectHandler( AspectHandler handler );
  -    void removeAspectHandler( AspectHandler handler );
  +    void removeAspectHandler( String name, AspectHandler handler )
  +        throws TaskException;
   }
  
  
  
  1.3       +55 -12    jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/DefaultAspectManager.java
  
  Index: DefaultAspectManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/aspect/DefaultAspectManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultAspectManager.java	2001/06/05 04:36:24	1.2
  +++ DefaultAspectManager.java	2001/06/06 06:12:48	1.3
  @@ -7,13 +7,15 @@
    */
   package org.apache.myrmidon.components.aspect;
   
  -import java.util.ArrayList;
  +import java.util.HashMap;
  +import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.log.Logger;
   import org.apache.myrmidon.api.Task;
   import org.apache.myrmidon.api.TaskException;
   import org.apache.myrmidon.aspects.AspectHandler;
  +import org.apache.myrmidon.aspects.NoopAspectHandler;
   
   /**
    * Manage and propogate Aspects.
  @@ -21,21 +23,62 @@
    * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
    */
   public class DefaultAspectManager
  -    implements AspectManager
  +    implements AspectManager, Initializable
   {
  -    private ArrayList            m_aspectCopy  = new ArrayList();
  -    private AspectHandler[]      m_aspects     = new AspectHandler[ 0 ];
  +    private HashMap          m_aspectMap  = new HashMap();
  +    private AspectHandler[]  m_aspects    = new AspectHandler[ 0 ];
  +    private String[]         m_names      = new String[ 0 ];
   
  -    public synchronized void addAspectHandler( final AspectHandler handler )
  +    public void initialize()
  +        throws Exception
       {
  -        m_aspectCopy.add( handler );
  -        m_aspects = (AspectHandler[])m_aspectCopy.toArray( m_aspects );
  +        ///UGLY HACK!!!!
  +        addAspectHandler( "ant", new NoopAspectHandler() );
  +        addAspectHandler( "doc", new NoopAspectHandler() );
       }
   
  -    public synchronized void removeAspectHandler( final AspectHandler handler )
  +    public synchronized void addAspectHandler( final String name, final AspectHandler handler
)
  +        throws TaskException
  +    {
  +        m_aspectMap.put( name, handler );
  +        rebuildArrays();
  +    }
  +
  +    public synchronized void removeAspectHandler( final String name, final AspectHandler
handler )
  +        throws TaskException
  +    {
  +        final AspectHandler entry = (AspectHandler)m_aspectMap.remove( name );
  +        if( null == entry )
  +        {
  +            throw new TaskException( "No such aspect with name '" + name + "'" );
  +        }
  +
  +        rebuildArrays();
  +    }
  +
  +    private void rebuildArrays()
       {
  -        m_aspectCopy.remove( handler );
  -        m_aspects = (AspectHandler[])m_aspectCopy.toArray( m_aspects );
  +        m_aspects = (AspectHandler[])m_aspectMap.values().toArray( m_aspects );
  +        m_names = (String[])m_aspectMap.keySet().toArray( m_names );
  +    }
  +
  +    public String[] getNames()
  +    {
  +        return m_names;
  +    }
  +
  +    public void dispatchAspectSettings( final String name,
  +                                        final Parameters parameters,
  +                                        final Configuration[] elements )
  +        throws TaskException
  +    {
  +        final AspectHandler handler = (AspectHandler)m_aspectMap.get( name );
  +        if( null == handler )
  +        {
  +            throw new TaskException( "No such aspect with name '" + name + "'" );
  +        }
  +
  +        handler.aspectSettings( parameters, elements );
       }
   
       public Configuration preCreate( final Configuration configuration )
  @@ -52,10 +95,10 @@
           return model;
       }
   
  -    public void aspect( final Parameters parameters, final Configuration[] elements )
  +    public void aspectSettings( final Parameters parameters, final Configuration[] elements
)
           throws TaskException
       {
  -        throw new UnsupportedOperationException( "Can not provide parameters to AspectManager"
); 
  +        throw new UnsupportedOperationException( "Can not provide Settings to AspectManager"
);
       }
   
       public void postCreate( final Task task )
  
  
  
  1.2       +105 -13   jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java
  
  Index: AspectAwareExecutor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AspectAwareExecutor.java	2001/06/05 07:54:33	1.1
  +++ AspectAwareExecutor.java	2001/06/06 06:12:51	1.2
  @@ -34,10 +34,6 @@
   
       private AspectManager        m_aspectManager;
   
  -    public AspectAwareExecutor()
  -    {
  -    }
  -
       /**
        * Retrieve relevent services.
        *
  @@ -61,7 +57,7 @@
           }
           catch( final TaskException te )
           {
  -            if( false == getAspectHandler().error( te ) )
  +            if( false == getAspectManager().error( te ) )
               {
                   throw te;
               }
  @@ -73,14 +69,14 @@
       {
           getLogger().debug( "Creating" );
   
  -        taskModel = getAspectHandler().preCreate( taskModel );
  +        taskModel = getAspectManager().preCreate( taskModel );
   
           taskModel = prepareAspects( taskModel );
   
           final Task task = createTask( taskModel.getName() );
  -        getAspectHandler().postCreate( task );
  +        getAspectManager().postCreate( task );
   
  -        getAspectHandler().preLoggable( getLogger() );
  +        getAspectManager().preLoggable( getLogger() );
           setupLogger( task );
   
           getLogger().debug( "Contextualizing" );
  @@ -90,25 +86,25 @@
           doCompose( task, taskModel );
   
           getLogger().debug( "Configuring" );
  -        getAspectHandler().preConfigure( taskModel );
  +        getAspectManager().preConfigure( taskModel );
           doConfigure( task, taskModel, context );
   
           getLogger().debug( "Initializing" );
           doInitialize( task, taskModel );
   
           getLogger().debug( "Executing" );
  -        getAspectHandler().preExecute();
  +        getAspectManager().preExecute();
           task.execute();
   
           getLogger().debug( "Disposing" );
  -        getAspectHandler().preDestroy();
  +        getAspectManager().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 )
  +    private final Configuration prepareAspects( final Configuration taskModel )
           throws TaskException
       {
           final DefaultConfiguration newTaskModel = 
  @@ -119,9 +115,105 @@
           processAttributes( taskModel, newTaskModel, parameterMap );
           processElements( taskModel, newTaskModel, elementMap );
   
  +        dispatchAspectsSettings( parameterMap, elementMap );
  +        checkForUnusedSettings( parameterMap, elementMap );
  +
           return newTaskModel;
       }
   
  +    private final void dispatchAspectsSettings( final HashMap parameterMap, 
  +                                                final HashMap elementMap )
  +        throws TaskException
  +    {
  +        final String[] names = getAspectManager().getNames();
  +        
  +        for( int i = 0; i < names.length; i++ )
  +        {
  +            final ArrayList elementList = (ArrayList)elementMap.remove( names[ i ] );
  +
  +            Parameters parameters = (Parameters)parameterMap.remove( names[ i ] );
  +            if( null == parameters ) parameters = EMPTY_PARAMETERS;
  +
  +            Configuration[] elements = null;
  +            if( null == elementList ) elements = EMPTY_ELEMENTS;
  +            else
  +            {
  +                elements = (Configuration[])elementList.toArray( EMPTY_ELEMENTS );
  +            }
  +            
  +            dispatch( names[ i ], parameters, elements );
  +        }
  +    }
  +
  +    private final void checkForUnusedSettings( final HashMap parameterMap, 
  +                                               final HashMap elementMap )
  +        throws TaskException
  +    {
  +        if( 0 != parameterMap.size() )
  +        {
  +            final String[] namespaces = 
  +                (String[])parameterMap.keySet().toArray( new String[ 0 ] );
  +
  +            for( int i = 0; i < namespaces.length; i++ )
  +            {
  +                final String namespace = namespaces[ i ];
  +                final Parameters parameters = (Parameters)parameterMap.get( namespace );
  +                final ArrayList elementList = (ArrayList)elementMap.remove( namespace );
  +                
  +                Configuration[] elements = null;
  +                
  +                if( null == elementList ) elements = EMPTY_ELEMENTS;
  +                else
  +                {
  +                    elements = (Configuration[])elementList.toArray( EMPTY_ELEMENTS );
  +                }
  +                
  +                unusedSetting( namespace, parameters, elements );
  +            }
  +        }
  +
  +        if( 0 != elementMap.size() )
  +        {
  +            final String[] namespaces = 
  +                (String[])elementMap.keySet().toArray( new String[ 0 ] );
  +            
  +            for( int i = 0; i < namespaces.length; i++ )
  +            {
  +                final String namespace = namespaces[ i ];
  +                final ArrayList elementList = (ArrayList)elementMap.remove( namespace );
  +                final Configuration[] elements = 
  +                    (Configuration[])elementList.toArray( EMPTY_ELEMENTS );
  +                
  +                unusedSetting( namespace, EMPTY_PARAMETERS, elements );
  +            }
  +        }
  +    }
  +
  +    private void unusedSetting( final String namespace, 
  +                                final Parameters parameters, 
  +                                final Configuration[] elements )
  +        throws TaskException
  +    {
  +        throw new TaskException( "Unused aspect settings for namespace " + namespace +

  +                                " (parameterCount=" + parameters.getNames().length + 
  +                                 " elementCount=" + elements.length + ")" ); 
  +    }
  +
  +    private void dispatch( final String namespace, 
  +                           final Parameters parameters, 
  +                           final Configuration[] elements )
  +        throws TaskException
  +    {
  +        getAspectManager().dispatchAspectSettings( namespace, parameters, elements );
  +
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            getLogger().debug( "Dispatching Aspect Settings to: " + namespace + 
  +                               " parameterCount=" + parameters.getNames().length + 
  +                               " elementCount=" + elements.length ); 
  +        }
  +    }
  +
       private final void processElements( final Configuration taskModel, 
                                           final DefaultConfiguration newTaskModel,
                                           final HashMap map )
  @@ -198,7 +290,7 @@
           return parameters;
       }
   
  -    protected final AspectHandler getAspectHandler()
  +    protected final AspectManager getAspectManager()
       {
           return m_aspectManager;
       }
  
  
  
  1.2       +1 -2      jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/ant1/TaskAdapter.java
  
  Index: TaskAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/ant1/TaskAdapter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TaskAdapter.java	2001/06/05 04:33:03	1.1
  +++ TaskAdapter.java	2001/06/06 06:12:53	1.2
  @@ -64,8 +64,7 @@
               getProject().contextualize( getContext() );
               getProject().init();
   
  -            //getTask().setProject( getProject() );
  -
  +            getTask().setProject( getProject() );
               getTask().init();
               getTask().execute();
           }
  
  
  
  1.4       +6 -1      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- sample.ant	2001/06/05 07:54:35	1.3
  +++ sample.ant	2001/06/06 06:12:55	1.4
  @@ -103,7 +103,12 @@
       <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 ...."/>
  +    <echo ant:fail-on-error="true" message="Some random message">
  +      <doc:description>
  +        Test case for aspects
  +      </doc:description>
  +      <ant:some-element some-attribute="blah"/>
  +    </echo>
     </target>
   
   </project>
  
  
  
  1.3       +1810 -1173jakarta-ant/proposal/myrmidon/tools/lib/ant.jar
  
  	<<Binary file>>
  
  

Mime
View raw message