a ComponentManager. Currently all components are also exposed as services. * Some tidy up to DefaultExecutionFrame and DefaultWorkspace. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271313 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -8,13 +8,8 @@ | |||||
| package org.apache.myrmidon.components.workspace; | package org.apache.myrmidon.components.workspace; | ||||
| import org.apache.avalon.framework.component.Component; | import org.apache.avalon.framework.component.Component; | ||||
| import org.apache.avalon.framework.context.Context; | |||||
| import org.apache.avalon.framework.context.ContextException; | |||||
| import org.apache.avalon.framework.context.Contextualizable; | |||||
| import org.apache.avalon.framework.logger.LogEnabled; | |||||
| import org.apache.avalon.framework.logger.Logger; | import org.apache.avalon.framework.logger.Logger; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.api.TaskException; | |||||
| import org.apache.myrmidon.interfaces.executor.ExecutionFrame; | import org.apache.myrmidon.interfaces.executor.ExecutionFrame; | ||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| @@ -25,29 +20,19 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| */ | */ | ||||
| class DefaultExecutionFrame | class DefaultExecutionFrame | ||||
| implements ExecutionFrame, Component, LogEnabled, Contextualizable | |||||
| implements ExecutionFrame, Component | |||||
| { | { | ||||
| private Logger m_logger; | |||||
| private TaskContext m_context; | |||||
| private TypeManager m_typeManager; | |||||
| private final Logger m_logger; | |||||
| private final TaskContext m_context; | |||||
| private final TypeManager m_typeManager; | |||||
| public void enableLogging( final Logger logger ) | |||||
| public DefaultExecutionFrame( final Logger logger, | |||||
| final TaskContext context, | |||||
| final TypeManager typeManager ) | |||||
| { | { | ||||
| m_logger = logger; | m_logger = logger; | ||||
| } | |||||
| public void contextualize( final Context context ) | |||||
| throws ContextException | |||||
| { | |||||
| m_context = (TaskContext)context; | |||||
| try | |||||
| { | |||||
| m_typeManager = (TypeManager)m_context.getService( TypeManager.class ); | |||||
| } | |||||
| catch( TaskException te ) | |||||
| { | |||||
| throw new ContextException( te.getMessage(), te ); | |||||
| } | |||||
| m_context = context; | |||||
| m_typeManager = typeManager; | |||||
| } | } | ||||
| public TypeManager getTypeManager() | public TypeManager getTypeManager() | ||||
| @@ -13,13 +13,12 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||||
| import org.apache.avalon.excalibur.io.FileUtil; | import org.apache.avalon.excalibur.io.FileUtil; | ||||
| import org.apache.avalon.excalibur.property.PropertyException; | import org.apache.avalon.excalibur.property.PropertyException; | ||||
| import org.apache.avalon.excalibur.property.PropertyUtil; | import org.apache.avalon.excalibur.property.PropertyUtil; | ||||
| import org.apache.avalon.framework.component.Component; | |||||
| import org.apache.avalon.framework.component.ComponentException; | |||||
| import org.apache.avalon.framework.component.ComponentManager; | |||||
| import org.apache.avalon.framework.context.ContextException; | import org.apache.avalon.framework.context.ContextException; | ||||
| import org.apache.avalon.framework.context.DefaultContext; | import org.apache.avalon.framework.context.DefaultContext; | ||||
| import org.apache.myrmidon.api.TaskContext; | import org.apache.myrmidon.api.TaskContext; | ||||
| import org.apache.myrmidon.api.TaskException; | import org.apache.myrmidon.api.TaskException; | ||||
| import org.apache.myrmidon.interfaces.service.ServiceException; | |||||
| import org.apache.myrmidon.interfaces.service.ServiceManager; | |||||
| /** | /** | ||||
| * Default implementation of TaskContext. | * Default implementation of TaskContext. | ||||
| @@ -34,14 +33,14 @@ public class DefaultTaskContext | |||||
| private final static Resources REZ = | private final static Resources REZ = | ||||
| ResourceManager.getPackageResources( DefaultTaskContext.class ); | ResourceManager.getPackageResources( DefaultTaskContext.class ); | ||||
| private ComponentManager m_componentManager; | |||||
| private ServiceManager m_serviceManager; | |||||
| /** | /** | ||||
| * Constructor for Context with no parent contexts. | * Constructor for Context with no parent contexts. | ||||
| */ | */ | ||||
| public DefaultTaskContext() | public DefaultTaskContext() | ||||
| { | { | ||||
| this( (TaskContext)null ); | |||||
| this( null, null ); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -53,21 +52,21 @@ public class DefaultTaskContext | |||||
| } | } | ||||
| /** | /** | ||||
| * Constructor that specifies the ComponentManager for context. | |||||
| * Constructor that specifies the service directory for context. | |||||
| */ | */ | ||||
| public DefaultTaskContext( final ComponentManager componentManager ) | |||||
| public DefaultTaskContext( final ServiceManager serviceManager ) | |||||
| { | { | ||||
| this( null, componentManager ); | |||||
| this( null, serviceManager ); | |||||
| } | } | ||||
| /** | /** | ||||
| * Constructor that takes both parent context and a service directory. | * Constructor that takes both parent context and a service directory. | ||||
| */ | */ | ||||
| public DefaultTaskContext( final TaskContext parent, | public DefaultTaskContext( final TaskContext parent, | ||||
| final ComponentManager componentManager ) | |||||
| final ServiceManager serviceManager ) | |||||
| { | { | ||||
| super( parent ); | super( parent ); | ||||
| m_componentManager = componentManager; | |||||
| m_serviceManager = serviceManager; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -121,27 +120,15 @@ public class DefaultTaskContext | |||||
| { | { | ||||
| // Try this context first | // Try this context first | ||||
| final String name = serviceClass.getName(); | final String name = serviceClass.getName(); | ||||
| if( m_componentManager.hasComponent( name ) ) | |||||
| if( m_serviceManager != null && m_serviceManager.hasService( serviceClass ) ) | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| final Component service = m_componentManager.lookup( name ); | |||||
| if( !serviceClass.isInstance( service ) ) | |||||
| { | |||||
| final String message = | |||||
| REZ.getString( "bad-service-class.error", | |||||
| name, | |||||
| service.getClass().getName(), | |||||
| serviceClass.getName() ); | |||||
| throw new TaskException( message ); | |||||
| } | |||||
| return service; | |||||
| return m_serviceManager.getService( serviceClass ); | |||||
| } | } | ||||
| catch( final ComponentException ce ) | |||||
| catch( final ServiceException se ) | |||||
| { | { | ||||
| final String message = REZ.getString( "bad-find-service.error", name ); | |||||
| throw new TaskException( message, ce ); | |||||
| throw new TaskException( se.getMessage(), se ); | |||||
| } | } | ||||
| } | } | ||||
| @@ -236,8 +223,6 @@ public class DefaultTaskContext | |||||
| /** | /** | ||||
| * Set property value. | * Set property value. | ||||
| * | |||||
| * @param property the property | |||||
| */ | */ | ||||
| public void setProperty( final String name, final Object value, final ScopeEnum scope ) | public void setProperty( final String name, final Object value, final ScopeEnum scope ) | ||||
| throws TaskException | throws TaskException | ||||
| @@ -37,6 +37,9 @@ import org.apache.myrmidon.interfaces.executor.Executor; | |||||
| import org.apache.myrmidon.interfaces.model.Project; | import org.apache.myrmidon.interfaces.model.Project; | ||||
| import org.apache.myrmidon.interfaces.model.Target; | import org.apache.myrmidon.interfaces.model.Target; | ||||
| import org.apache.myrmidon.interfaces.model.TypeLib; | import org.apache.myrmidon.interfaces.model.TypeLib; | ||||
| import org.apache.myrmidon.interfaces.service.ComponentManagerAdaptor; | |||||
| import org.apache.myrmidon.interfaces.service.MultiSourceServiceManager; | |||||
| import org.apache.myrmidon.interfaces.service.ServiceManager; | |||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| import org.apache.myrmidon.interfaces.workspace.Workspace; | import org.apache.myrmidon.interfaces.workspace.Workspace; | ||||
| import org.apache.myrmidon.listeners.ProjectListener; | import org.apache.myrmidon.listeners.ProjectListener; | ||||
| @@ -142,7 +145,7 @@ public class DefaultWorkspace | |||||
| private TaskContext createBaseContext() | private TaskContext createBaseContext() | ||||
| throws TaskException | throws TaskException | ||||
| { | { | ||||
| final TaskContext context = new DefaultTaskContext( m_componentManager ); | |||||
| final TaskContext context = new DefaultTaskContext(); | |||||
| final String[] names = m_parameters.getNames(); | final String[] names = m_parameters.getNames(); | ||||
| for( int i = 0; i < names.length; i++ ) | for( int i = 0; i < names.length; i++ ) | ||||
| @@ -220,8 +223,11 @@ public class DefaultWorkspace | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Creates an execution frame for a project. | |||||
| */ | |||||
| private ExecutionFrame createExecutionFrame( final Project project ) | private ExecutionFrame createExecutionFrame( final Project project ) | ||||
| throws TaskException | |||||
| throws TaskException, ComponentException | |||||
| { | { | ||||
| //Create per frame ComponentManager | //Create per frame ComponentManager | ||||
| final DefaultComponentManager componentManager = | final DefaultComponentManager componentManager = | ||||
| @@ -232,32 +238,11 @@ public class DefaultWorkspace | |||||
| final TypeManager typeManager = m_typeManager.createChildTypeManager(); | final TypeManager typeManager = m_typeManager.createChildTypeManager(); | ||||
| componentManager.put( TypeManager.ROLE, typeManager ); | componentManager.put( TypeManager.ROLE, typeManager ); | ||||
| //try | |||||
| //{ | |||||
| // //Add VFS manager | |||||
| // // TODO - need to drive this from a typelib descriptor, plus | |||||
| // // should be adding services to the root frame, rather than here | |||||
| // final DefaultFileSystemManager vfsManager = new DefaultFileSystemManager(); | |||||
| // vfsManager.setBaseFile( project.getBaseDirectory() ); | |||||
| // componentManager.put( FileSystemManager.ROLE, vfsManager ); | |||||
| //} | |||||
| //catch( Exception e ) | |||||
| //{ | |||||
| // throw new TaskException( e.getMessage(), e ); | |||||
| //} | |||||
| //We need to create a new deployer so that it deploys | //We need to create a new deployer so that it deploys | ||||
| //to project specific TypeManager | //to project specific TypeManager | ||||
| final Deployer deployer; | final Deployer deployer; | ||||
| try | |||||
| { | |||||
| deployer = m_deployer.createChildDeployer( componentManager ); | |||||
| componentManager.put( Deployer.ROLE, deployer ); | |||||
| } | |||||
| catch( ComponentException e ) | |||||
| { | |||||
| throw new TaskException( e.getMessage(), e ); | |||||
| } | |||||
| deployer = m_deployer.createChildDeployer( componentManager ); | |||||
| componentManager.put( Deployer.ROLE, deployer ); | |||||
| // Deploy the imported typelibs | // Deploy the imported typelibs | ||||
| deployTypeLib( deployer, project ); | deployTypeLib( deployer, project ); | ||||
| @@ -275,32 +260,28 @@ public class DefaultWorkspace | |||||
| componentManager.put( Project.ROLE + "/" + name, other ); | componentManager.put( Project.ROLE + "/" + name, other ); | ||||
| } | } | ||||
| // Create a service manager that aggregates the contents of the context's | |||||
| // component manager, and service manager | |||||
| final MultiSourceServiceManager serviceManager = new MultiSourceServiceManager(); | |||||
| serviceManager.add( (ServiceManager)componentManager.lookup( ServiceManager.ROLE ) ); | |||||
| serviceManager.add( new ComponentManagerAdaptor( componentManager ) ); | |||||
| // Create and configure the context | // Create and configure the context | ||||
| final DefaultTaskContext context = | final DefaultTaskContext context = | ||||
| new DefaultTaskContext( m_baseContext, componentManager ); | |||||
| new DefaultTaskContext( m_baseContext, serviceManager ); | |||||
| context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() ); | context.setProperty( TaskContext.BASE_DIRECTORY, project.getBaseDirectory() ); | ||||
| final DefaultExecutionFrame frame = new DefaultExecutionFrame(); | |||||
| // Create a logger | |||||
| final Logger logger = | |||||
| new LogKitLogger( m_hierarchy.getLoggerFor( "project" + m_projectID ) ); | |||||
| m_projectID++; | |||||
| try | |||||
| { | |||||
| final Logger logger = | |||||
| new LogKitLogger( m_hierarchy.getLoggerFor( "project" + m_projectID ) ); | |||||
| m_projectID++; | |||||
| final DefaultExecutionFrame frame = new DefaultExecutionFrame( logger, context, typeManager ); | |||||
| frame.enableLogging( logger ); | |||||
| frame.contextualize( context ); | |||||
| /** | |||||
| * @todo Should no occur but done for the time being to simplify evolution. | |||||
| */ | |||||
| componentManager.put( ExecutionFrame.ROLE, frame ); | |||||
| } | |||||
| catch( final Exception e ) | |||||
| { | |||||
| final String message = REZ.getString( "bad-frame.error" ); | |||||
| throw new TaskException( message, e ); | |||||
| } | |||||
| /** | |||||
| * @todo Should no occur but done for the time being to simplify evolution. | |||||
| */ | |||||
| componentManager.put( ExecutionFrame.ROLE, frame ); | |||||
| return frame; | return frame; | ||||
| } | } | ||||
| @@ -312,9 +293,17 @@ public class DefaultWorkspace | |||||
| if( null == entry ) | if( null == entry ) | ||||
| { | { | ||||
| final ExecutionFrame frame = createExecutionFrame( project ); | |||||
| entry = new ProjectEntry( project, frame ); | |||||
| m_entrys.put( project, entry ); | |||||
| try | |||||
| { | |||||
| final ExecutionFrame frame = createExecutionFrame( project ); | |||||
| entry = new ProjectEntry( project, frame ); | |||||
| m_entrys.put( project, entry ); | |||||
| } | |||||
| catch( Exception e ) | |||||
| { | |||||
| final String message = REZ.getString( "bad-frame.error" ); | |||||
| throw new TaskException( message, e ); | |||||
| } | |||||
| } | } | ||||
| return entry; | return entry; | ||||
| @@ -15,7 +15,6 @@ no-version.error=No JavaVersion in Context. | |||||
| no-name.error=No Name in Context. | no-name.error=No Name in Context. | ||||
| no-dir.error=No Base Directory in Context. | no-dir.error=No Base Directory in Context. | ||||
| no-parent.error=Can't set a property with parent scope when context has no parent. | no-parent.error=Can't set a property with parent scope when context has no parent. | ||||
| bad-find-services.error=Unable to find service "{0}". | |||||
| bad-scope.error=Unknown property scope! ({0}). | bad-scope.error=Unknown property scope! ({0}). | ||||
| bad-property.error=Property {0} must have a value of type {1}. | bad-property.error=Property {0} must have a value of type {1}. | ||||
| null-resolved-value.error=Value "{0}" resolved to null. | null-resolved-value.error=Value "{0}" resolved to null. | ||||
| @@ -33,6 +33,7 @@ import org.apache.myrmidon.components.deployer.ClassLoaderManager; | |||||
| import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | ||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | import org.apache.myrmidon.components.role.DefaultRoleManager; | ||||
| import org.apache.myrmidon.components.type.DefaultTypeManager; | import org.apache.myrmidon.components.type.DefaultTypeManager; | ||||
| import org.apache.myrmidon.components.service.DefaultServiceManager; | |||||
| import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | ||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | import org.apache.myrmidon.interfaces.converter.MasterConverter; | ||||
| @@ -42,6 +43,7 @@ import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| import org.apache.myrmidon.interfaces.service.ServiceManager; | |||||
| import org.apache.myrmidon.converter.Converter; | import org.apache.myrmidon.converter.Converter; | ||||
| import org.apache.myrmidon.AbstractMyrmidonTest; | import org.apache.myrmidon.AbstractMyrmidonTest; | ||||
| @@ -133,6 +135,10 @@ public abstract class AbstractComponentTest | |||||
| m_componentManager.put( RoleManager.ROLE, component ); | m_componentManager.put( RoleManager.ROLE, component ); | ||||
| components.add( component ); | components.add( component ); | ||||
| component = new DefaultServiceManager(); | |||||
| m_componentManager.put( ServiceManager.ROLE, component ); | |||||
| components.add( component ); | |||||
| // Log enable the components | // Log enable the components | ||||
| for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | ||||
| { | { | ||||
| @@ -52,7 +52,7 @@ public class DefaultConfigurerTest | |||||
| m_configurer = (Configurer)getComponentManager().lookup( Configurer.ROLE ); | m_configurer = (Configurer)getComponentManager().lookup( Configurer.ROLE ); | ||||
| // Setup a context | // Setup a context | ||||
| m_context = new DefaultTaskContext( getComponentManager() ); | |||||
| m_context = new DefaultTaskContext(); | |||||
| final File baseDir = new File( "." ).getAbsoluteFile(); | final File baseDir = new File( "." ).getAbsoluteFile(); | ||||
| m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | ||||
| } | } | ||||
| @@ -33,6 +33,7 @@ import org.apache.myrmidon.components.deployer.ClassLoaderManager; | |||||
| import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | import org.apache.myrmidon.components.extensions.DefaultExtensionManager; | ||||
| import org.apache.myrmidon.components.role.DefaultRoleManager; | import org.apache.myrmidon.components.role.DefaultRoleManager; | ||||
| import org.apache.myrmidon.components.type.DefaultTypeManager; | import org.apache.myrmidon.components.type.DefaultTypeManager; | ||||
| import org.apache.myrmidon.components.service.DefaultServiceManager; | |||||
| import org.apache.myrmidon.interfaces.configurer.Configurer; | import org.apache.myrmidon.interfaces.configurer.Configurer; | ||||
| import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | import org.apache.myrmidon.interfaces.converter.ConverterRegistry; | ||||
| import org.apache.myrmidon.interfaces.converter.MasterConverter; | import org.apache.myrmidon.interfaces.converter.MasterConverter; | ||||
| @@ -42,6 +43,7 @@ import org.apache.myrmidon.interfaces.role.RoleManager; | |||||
| import org.apache.myrmidon.interfaces.type.TypeManager; | import org.apache.myrmidon.interfaces.type.TypeManager; | ||||
| import org.apache.myrmidon.interfaces.type.TypeException; | import org.apache.myrmidon.interfaces.type.TypeException; | ||||
| import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | import org.apache.myrmidon.interfaces.type.DefaultTypeFactory; | ||||
| import org.apache.myrmidon.interfaces.service.ServiceManager; | |||||
| import org.apache.myrmidon.converter.Converter; | import org.apache.myrmidon.converter.Converter; | ||||
| import org.apache.myrmidon.AbstractMyrmidonTest; | import org.apache.myrmidon.AbstractMyrmidonTest; | ||||
| @@ -133,6 +135,10 @@ public abstract class AbstractComponentTest | |||||
| m_componentManager.put( RoleManager.ROLE, component ); | m_componentManager.put( RoleManager.ROLE, component ); | ||||
| components.add( component ); | components.add( component ); | ||||
| component = new DefaultServiceManager(); | |||||
| m_componentManager.put( ServiceManager.ROLE, component ); | |||||
| components.add( component ); | |||||
| // Log enable the components | // Log enable the components | ||||
| for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | ||||
| { | { | ||||
| @@ -52,7 +52,7 @@ public class DefaultConfigurerTest | |||||
| m_configurer = (Configurer)getComponentManager().lookup( Configurer.ROLE ); | m_configurer = (Configurer)getComponentManager().lookup( Configurer.ROLE ); | ||||
| // Setup a context | // Setup a context | ||||
| m_context = new DefaultTaskContext( getComponentManager() ); | |||||
| m_context = new DefaultTaskContext(); | |||||
| final File baseDir = new File( "." ).getAbsoluteFile(); | final File baseDir = new File( "." ).getAbsoluteFile(); | ||||
| m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | m_context.setProperty( TaskContext.BASE_DIRECTORY, baseDir ); | ||||
| } | } | ||||