Browse Source

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.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269111 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
794a883964
10 changed files with 242 additions and 35 deletions
  1. +1
    -1
      proposal/myrmidon/build.sh
  2. BIN
      proposal/myrmidon/lib/avalon-excalibur.jar
  3. BIN
      proposal/myrmidon/lib/avalon-framework.jar
  4. BIN
      proposal/myrmidon/lib/xerces.jar
  5. +0
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java
  6. +4
    -4
      proposal/myrmidon/src/java/org/apache/myrmidon/api/DefaultTaskContext.java
  7. +2
    -1
      proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java
  8. +205
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java
  9. +28
    -28
      proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java
  10. +2
    -0
      proposal/myrmidon/src/make/sample.ant

+ 1
- 1
proposal/myrmidon/build.sh View File

@@ -10,6 +10,6 @@ chmod u+x $MYRMIDON_HOME/bin/antRun
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 $@

BIN
proposal/myrmidon/lib/avalon-excalibur.jar View File


BIN
proposal/myrmidon/lib/avalon-framework.jar View File


BIN
proposal/myrmidon/lib/xerces.jar View File


+ 0
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/api/AbstractTask.java View File

@@ -63,7 +63,6 @@ public abstract class AbstractTask
* @exception Exception if an error occurs
*/
public void dispose()
throws Exception
{
}



+ 4
- 4
proposal/myrmidon/src/java/org/apache/myrmidon/api/DefaultTaskContext.java View File

@@ -165,23 +165,23 @@ public class DefaultTaskContext
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 );


+ 2
- 1
proposal/myrmidon/src/java/org/apache/myrmidon/components/embeddor/DefaultEmbeddor.java View File

@@ -182,7 +182,8 @@ public class DefaultEmbeddor
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,


+ 205
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/AspectAwareExecutor.java View File

@@ -0,0 +1,205 @@
/*
* 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;
}
}

+ 28
- 28
proposal/myrmidon/src/java/org/apache/myrmidon/components/executor/DefaultExecutor.java View File

@@ -61,34 +61,34 @@ public class DefaultExecutor
}
}

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 @@ public class DefaultExecutor
}
}

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 @@ public class DefaultExecutor
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 @@ public class DefaultExecutor
}
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 @@ public class DefaultExecutor
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 @@ public class DefaultExecutor
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 );
}
}


+ 2
- 0
proposal/myrmidon/src/make/sample.ant View File

@@ -102,6 +102,8 @@ Legal:
<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>

Loading…
Cancel
Save