be used in the config: * All services that used to implement Parameterizable now implement Contextualizable. * Changed 'myrmidon.home' to a File, and the paths to File[]. * DefaultEmbeddor now deploys Antlibs from all directories in 'myrmidon.lib.path', rather than just a single dir. Can't specify alternative service implementations (temporarily broken). * Added 'myrmidon.antlib.path', which DefaultWorkspace uses to search for <import>-ed antlibs. * Replaced --task-lib-dir with --antlib-path, which appends directories to 'myrmidon.antlib.path' * Added --ext-path, which appends directories to 'myrmidon.ext.path'. * DefaultClassLoaderManager now uses the container config to locate the shared classloader, rather than using the context classloader. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272306 13f79535-47bb-0310-9956-ffa450edef68master
@@ -12,16 +12,19 @@ import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.HashSet; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import java.util.HashSet; | |||
import java.util.jar.Manifest; | |||
import java.util.jar.JarFile; | |||
import java.util.jar.Manifest; | |||
import org.apache.aut.nativelib.PathUtil; | |||
import org.apache.avalon.excalibur.extension.Extension; | |||
import org.apache.avalon.excalibur.extension.OptionalPackage; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.framework.activity.Initializable; | |||
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.AbstractLogEnabled; | |||
import org.apache.avalon.framework.service.ServiceException; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
@@ -30,7 +33,6 @@ import org.apache.myrmidon.interfaces.classloader.ClassLoaderException; | |||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager; | |||
import org.apache.myrmidon.interfaces.deployer.DeploymentException; | |||
import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||
import org.apache.aut.nativelib.PathUtil; | |||
/** | |||
* A default implementation of a ClassLoader manager. | |||
@@ -40,7 +42,7 @@ import org.apache.aut.nativelib.PathUtil; | |||
*/ | |||
public class DefaultClassLoaderManager | |||
extends AbstractLogEnabled | |||
implements ClassLoaderManager, Serviceable, Initializable | |||
implements ClassLoaderManager, Serviceable, Contextualizable | |||
{ | |||
private static final Resources REZ = | |||
ResourceManager.getPackageResources( DefaultClassLoaderManager.class ); | |||
@@ -62,11 +64,11 @@ public class DefaultClassLoaderManager | |||
m_commonClassLoader = commonClassLoader; | |||
} | |||
public void initialize() throws Exception | |||
public void contextualize( final Context context ) throws ContextException | |||
{ | |||
if( null == m_commonClassLoader ) | |||
{ | |||
m_commonClassLoader = Thread.currentThread().getContextClassLoader(); | |||
m_commonClassLoader = (ClassLoader)context.get( "myrmidon.shared.classloader" ); | |||
} | |||
} | |||
@@ -19,6 +19,9 @@ import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.excalibur.io.ExtensionFileFilter; | |||
import org.apache.avalon.excalibur.io.FileUtil; | |||
import org.apache.avalon.framework.CascadingException; | |||
import org.apache.avalon.framework.context.Contextualizable; | |||
import org.apache.avalon.framework.context.Context; | |||
import org.apache.avalon.framework.context.ContextException; | |||
import org.apache.avalon.framework.activity.Disposable; | |||
import org.apache.avalon.framework.activity.Initializable; | |||
import org.apache.avalon.framework.activity.Startable; | |||
@@ -62,7 +65,7 @@ import org.apache.myrmidon.components.store.DefaultPropertyStore; | |||
*/ | |||
public class DefaultEmbeddor | |||
extends AbstractLogEnabled | |||
implements Embeddor, Parameterizable, Initializable, Startable, Disposable | |||
implements Embeddor, Contextualizable, Initializable, Startable, Disposable | |||
{ | |||
private static final Resources REZ = | |||
ResourceManager.getPackageResources( DefaultEmbeddor.class ); | |||
@@ -76,17 +79,15 @@ public class DefaultEmbeddor | |||
private List m_components = new ArrayList(); | |||
private DefaultServiceManager m_serviceManager = new DefaultServiceManager(); | |||
private Parameters m_parameters; | |||
private Context m_context; | |||
/** | |||
* Setup basic properties of engine. | |||
* Called before init() and can be used to specify alternate components in system. | |||
* | |||
* @param parameters the parameters. | |||
*/ | |||
public void parameterize( final Parameters parameters ) | |||
public void contextualize( final Context context ) throws ContextException | |||
{ | |||
m_parameters = parameters; | |||
m_context = context; | |||
} | |||
/** | |||
@@ -137,7 +138,7 @@ public class DefaultEmbeddor | |||
{ | |||
final Workspace workspace = | |||
(Workspace)createService( Workspace.class, PREFIX + "workspace.DefaultWorkspace" ); | |||
setupObject( workspace, m_workspaceServiceManager, m_parameters ); | |||
setupObject( workspace, m_workspaceServiceManager, null ); | |||
// Create the property store | |||
final PropertyStore propStore = createBaseStore( properties ); | |||
@@ -185,7 +186,7 @@ public class DefaultEmbeddor | |||
final ServiceManager projServiceManager | |||
= (ServiceManager)createService( ServiceManager.class, | |||
PREFIX + "service.InstantiatingServiceManager" ); | |||
setupObject( projServiceManager, m_serviceManager, m_parameters ); | |||
setupObject( projServiceManager, m_serviceManager, null ); | |||
m_components.add( projServiceManager ); | |||
// setup a service manager to be used by workspaces | |||
@@ -204,8 +205,8 @@ public class DefaultEmbeddor | |||
// Deploy all type libraries in the lib directory | |||
final ExtensionFileFilter filter = new ExtensionFileFilter( ".atl" ); | |||
final File taskLibDir = new File( m_parameters.getParameter( "myrmidon.lib.path" ) ); | |||
deployFromDirectory( m_deployer, taskLibDir, filter ); | |||
final File[] taskLibDirs = (File[])m_context.get( "myrmidon.lib.path" ); | |||
deployFromDirectories( m_deployer, taskLibDirs, filter ); | |||
} | |||
/** | |||
@@ -236,7 +237,7 @@ public class DefaultEmbeddor | |||
m_components = null; | |||
m_deployer = null; | |||
m_serviceManager = null; | |||
m_parameters = null; | |||
m_context = null; | |||
} | |||
/** | |||
@@ -266,7 +267,7 @@ public class DefaultEmbeddor | |||
for( Iterator iterator = m_components.iterator(); iterator.hasNext(); ) | |||
{ | |||
final Object component = iterator.next(); | |||
setupObject( component, m_serviceManager, m_parameters ); | |||
setupObject( component, m_serviceManager, null ); | |||
} | |||
} | |||
@@ -294,8 +295,8 @@ public class DefaultEmbeddor | |||
private Object createService( final Class roleType, final String defaultImpl ) | |||
throws Exception | |||
{ | |||
final String role = roleType.getName(); | |||
final String className = m_parameters.getParameter( role, defaultImpl ); | |||
// TODO - need to be able to provide different implementations | |||
final String className = defaultImpl; | |||
try | |||
{ | |||
@@ -341,12 +342,17 @@ public class DefaultEmbeddor | |||
{ | |||
setupLogger( object ); | |||
if(object instanceof Contextualizable ) | |||
{ | |||
( (Contextualizable)object ).contextualize( m_context ); | |||
} | |||
if( object instanceof Serviceable ) | |||
{ | |||
( (Serviceable)object ).service( serviceManager ); | |||
} | |||
if( object instanceof Parameterizable ) | |||
if( parameters != null && object instanceof Parameterizable ) | |||
{ | |||
( (Parameterizable)object ).parameterize( parameters ); | |||
} | |||
@@ -360,16 +366,20 @@ public class DefaultEmbeddor | |||
/** | |||
* Deploys all type libraries in a directory. | |||
*/ | |||
private void deployFromDirectory( final Deployer deployer, | |||
final File directory, | |||
final FilenameFilter filter ) | |||
private void deployFromDirectories( final Deployer deployer, | |||
final File[] directories, | |||
final FilenameFilter filter ) | |||
throws DeploymentException | |||
{ | |||
final File[] files = directory.listFiles( filter ); | |||
if( null != files ) | |||
for( int i = 0; i < directories.length; i++ ) | |||
{ | |||
deployFiles( deployer, files ); | |||
File directory = directories[i ]; | |||
final File[] files = directory.listFiles( filter ); | |||
if( null != files ) | |||
{ | |||
deployFiles( deployer, files ); | |||
} | |||
} | |||
} | |||
@@ -13,14 +13,13 @@ import org.apache.avalon.excalibur.extension.Extension; | |||
import org.apache.avalon.excalibur.extension.OptionalPackage; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.excalibur.util.StringUtil; | |||
import org.apache.avalon.framework.activity.Disposable; | |||
import org.apache.avalon.framework.activity.Initializable; | |||
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.parameters.ParameterException; | |||
import org.apache.avalon.framework.parameters.Parameterizable; | |||
import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||
/** | |||
@@ -31,7 +30,7 @@ import org.apache.myrmidon.interfaces.extensions.ExtensionManager; | |||
*/ | |||
public class DefaultExtensionManager | |||
extends DefaultPackageRepository | |||
implements LogEnabled, Parameterizable, Initializable, Disposable, ExtensionManager | |||
implements LogEnabled, Contextualizable, Initializable, Disposable, ExtensionManager | |||
{ | |||
private static final Resources REZ = | |||
ResourceManager.getPackageResources( DefaultExtensionManager.class ); | |||
@@ -50,7 +49,7 @@ public class DefaultExtensionManager | |||
File.separator + "lib" + File.separator + "tools.jar"; | |||
private Logger m_logger; | |||
private String m_path; | |||
private File[] m_path; | |||
public DefaultExtensionManager() | |||
{ | |||
@@ -67,24 +66,15 @@ public class DefaultExtensionManager | |||
m_logger = logger; | |||
} | |||
public void parameterize( final Parameters parameters ) | |||
throws ParameterException | |||
public void contextualize( final Context context ) throws ContextException | |||
{ | |||
m_path = parameters.getParameter( "myrmidon.ext.path" ); | |||
m_path = (File[])context.get( "myrmidon.ext.path" ); | |||
} | |||
public void initialize() | |||
throws Exception | |||
{ | |||
final String[] pathElements = StringUtil.split( m_path, File.pathSeparator ); | |||
final File[] dirs = new File[ pathElements.length ]; | |||
for( int i = 0; i < dirs.length; i++ ) | |||
{ | |||
dirs[ i ] = new File( pathElements[ i ] ); | |||
} | |||
setPath( dirs ); | |||
setPath( m_path ); | |||
scanPath(); | |||
// Add the JVM's tools.jar as an extension | |||
@@ -23,6 +23,9 @@ import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.avalon.framework.service.ServiceException; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
import org.apache.avalon.framework.service.Serviceable; | |||
import org.apache.avalon.framework.context.Contextualizable; | |||
import org.apache.avalon.framework.context.Context; | |||
import org.apache.avalon.framework.context.ContextException; | |||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||
import org.apache.myrmidon.interfaces.role.RoleManager; | |||
import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||
@@ -37,9 +40,12 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||
* and running the service instances through the service lifecycle: | |||
* <ul> | |||
* <li>log enable | |||
* <li>contextualise | |||
* <li>service | |||
* <li>parameterise | |||
* <li>initialise | |||
* <li>use | |||
* <li>dispose | |||
* </ul> | |||
* | |||
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a> | |||
@@ -47,7 +53,7 @@ import org.apache.myrmidon.interfaces.type.TypeManager; | |||
*/ | |||
public class InstantiatingServiceManager | |||
extends AbstractLogEnabled | |||
implements ServiceManager, Parameterizable, Serviceable, Disposable | |||
implements ServiceManager, Contextualizable, Parameterizable, Serviceable, Disposable | |||
{ | |||
private static final Resources REZ = | |||
ResourceManager.getPackageResources( InstantiatingServiceManager.class ); | |||
@@ -64,8 +70,14 @@ public class InstantiatingServiceManager | |||
private ServiceManager m_serviceManager; | |||
private Parameters m_parameters; | |||
private TypeManager m_typeManager; | |||
private Context m_context; | |||
public void parameterize( Parameters parameters ) throws ParameterException | |||
public void contextualize( final Context context ) throws ContextException | |||
{ | |||
m_context = context; | |||
} | |||
public void parameterize( final Parameters parameters ) throws ParameterException | |||
{ | |||
m_parameters = parameters; | |||
} | |||
@@ -211,12 +223,17 @@ public class InstantiatingServiceManager | |||
{ | |||
setupLogger( object ); | |||
if( m_context != null && object instanceof Contextualizable ) | |||
{ | |||
( (Contextualizable)object ).contextualize( m_context ); | |||
} | |||
if( object instanceof Serviceable ) | |||
{ | |||
( (Serviceable)object ).service( m_serviceManager ); | |||
} | |||
if( object instanceof Parameterizable ) | |||
if( m_parameters != null && object instanceof Parameterizable ) | |||
{ | |||
( (Parameterizable)object ).parameterize( m_parameters ); | |||
} | |||
@@ -12,11 +12,11 @@ import java.util.HashMap; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.framework.configuration.Configuration; | |||
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.AbstractLogEnabled; | |||
import org.apache.avalon.framework.logger.Logger; | |||
import org.apache.avalon.framework.parameters.ParameterException; | |||
import org.apache.avalon.framework.parameters.Parameterizable; | |||
import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.avalon.framework.service.DefaultServiceManager; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
import org.apache.myrmidon.api.TaskContext; | |||
@@ -44,7 +44,7 @@ import org.apache.myrmidon.listeners.ProjectListener; | |||
*/ | |||
public class DefaultWorkspace | |||
extends AbstractLogEnabled | |||
implements Workspace, ExecutionContainer, Parameterizable | |||
implements Workspace, ExecutionContainer, Contextualizable | |||
{ | |||
private static final Resources REZ = | |||
ResourceManager.getPackageResources( DefaultWorkspace.class ); | |||
@@ -52,10 +52,10 @@ public class DefaultWorkspace | |||
private Executor m_executor; | |||
private ProjectListenerSupport m_listenerSupport = new ProjectListenerSupport(); | |||
private ServiceManager m_serviceManager; | |||
private Parameters m_parameters; | |||
private PropertyStore m_baseStore; | |||
private TypeManager m_typeManager; | |||
private Deployer m_deployer; | |||
private Context m_context; | |||
/** A map from Project object -> ProjectEntry for that project. */ | |||
private HashMap m_entries = new HashMap(); | |||
@@ -92,10 +92,9 @@ public class DefaultWorkspace | |||
m_deployer = (Deployer)m_serviceManager.lookup( Deployer.ROLE ); | |||
} | |||
public void parameterize( final Parameters parameters ) | |||
throws ParameterException | |||
public void contextualize( final Context context ) throws ContextException | |||
{ | |||
m_parameters = parameters; | |||
m_context = context; | |||
} | |||
/** | |||
@@ -127,21 +126,23 @@ public class DefaultWorkspace | |||
//workspace specific) | |||
final String name = libraryName.replace( '/', File.separatorChar ) + ".atl"; | |||
final String home = m_parameters.getParameter( "myrmidon.home" ); | |||
final File homeDir = new File( home + File.separatorChar + "ext" ); | |||
final File library = new File( homeDir, name ); | |||
if( library.exists() ) | |||
final File[] extPath = (File[])m_context.get( "myrmidon.antlib.path" ); | |||
for( int i = 0; i < extPath.length; i++ ) | |||
{ | |||
if( !library.canRead() ) | |||
{ | |||
final String message = REZ.getString( "no-read.error", library ); | |||
throw new TaskException( message ); | |||
} | |||
else | |||
final File extDir = extPath[ i ]; | |||
final File library = new File( extDir, name ); | |||
if( library.exists() ) | |||
{ | |||
return library; | |||
if( !library.canRead() ) | |||
{ | |||
final String message = REZ.getString( "no-read.error", library ); | |||
throw new TaskException( message ); | |||
} | |||
else | |||
{ | |||
return library; | |||
} | |||
} | |||
} | |||
@@ -8,13 +8,10 @@ | |||
package org.apache.myrmidon.framework.factories; | |||
import java.io.File; | |||
import org.apache.aut.nativelib.ExecException; | |||
import org.apache.aut.nativelib.impl.DefaultExecManager; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.framework.parameters.Parameterizable; | |||
import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.avalon.framework.parameters.ParameterException; | |||
import org.apache.avalon.framework.context.Context; | |||
import org.apache.avalon.framework.context.ContextException; | |||
import org.apache.avalon.framework.context.Contextualizable; | |||
import org.apache.myrmidon.interfaces.service.AntServiceException; | |||
import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||
@@ -25,17 +22,13 @@ import org.apache.myrmidon.interfaces.service.ServiceFactory; | |||
* @version $Revision$ $Date$ | |||
*/ | |||
public class ExecManagerFactory | |||
implements ServiceFactory, Parameterizable | |||
implements ServiceFactory, Contextualizable | |||
{ | |||
private static final Resources REZ = | |||
ResourceManager.getPackageResources( ExecManagerFactory.class ); | |||
private File m_homeDir; | |||
private Parameters m_parameters; | |||
public void parameterize( final Parameters parameters ) | |||
throws ParameterException | |||
public void contextualize( final Context context ) throws ContextException | |||
{ | |||
m_parameters = parameters; | |||
m_homeDir = (File)context.get( "myrmidon.home" ); | |||
} | |||
/** | |||
@@ -46,28 +39,11 @@ public class ExecManagerFactory | |||
{ | |||
try | |||
{ | |||
final File home = getHomeDirectory(); | |||
return new DefaultExecManager( home ); | |||
return new DefaultExecManager( m_homeDir ); | |||
} | |||
catch( final Exception ee ) | |||
{ | |||
throw new AntServiceException( ee.getMessage(), ee ); | |||
} | |||
} | |||
/** | |||
* Utility method to retrieve home directory. | |||
*/ | |||
private File getHomeDirectory() | |||
throws Exception | |||
{ | |||
final String home = m_parameters.getParameter( "myrmidon.home" ); | |||
if( null == home ) | |||
{ | |||
final String message = REZ.getString( "missing-home-dir.error" ); | |||
throw new AntServiceException( message ); | |||
} | |||
return new File( home ); | |||
} | |||
} |
@@ -51,18 +51,19 @@ public class CLIMain | |||
private static final int VERSION_OPT = 1; | |||
private static final int LISTENER_OPT = 2; | |||
private static final int TASKLIB_DIR_OPT = 5; | |||
private static final int INCREMENTAL_OPT = 6; | |||
private static final int HOME_DIR_OPT = 7; | |||
private static final int DRY_RUN_OPT = 8; | |||
private static final int DEBUG_OPT = 9; | |||
private static final int TYPE_OPT = 10; | |||
private static final int EXTLIB_DIR_OPT = 6; | |||
private static final int INCREMENTAL_OPT = 7; | |||
private static final int HOME_DIR_OPT = 8; | |||
private static final int DRY_RUN_OPT = 9; | |||
private static final int DEBUG_OPT = 10; | |||
private static final int TYPE_OPT = 11; | |||
//incompatable options for info options | |||
private static final int[] INFO_OPT_INCOMPAT = new int[] | |||
{ | |||
HELP_OPT, QUIET_OPT, VERBOSE_OPT, FILE_OPT, | |||
LOG_LEVEL_OPT, BUILDER_PARAM_OPT, NO_PREFIX_OPT, | |||
VERSION_OPT, LISTENER_OPT, TASKLIB_DIR_OPT, | |||
VERSION_OPT, LISTENER_OPT, TASKLIB_DIR_OPT, EXTLIB_DIR_OPT, | |||
INCREMENTAL_OPT, HOME_DIR_OPT, DRY_RUN_OPT, TYPE_OPT | |||
}; | |||
@@ -191,10 +192,14 @@ public class CLIMain | |||
VERSION_OPT, | |||
REZ.getString( "version.opt" ), | |||
INFO_OPT_INCOMPAT ), | |||
new CLOptionDescriptor( "task-lib-dir", | |||
new CLOptionDescriptor( "antlib-path", | |||
CLOptionDescriptor.ARGUMENT_REQUIRED, | |||
TASKLIB_DIR_OPT, | |||
REZ.getString( "tasklib.opt" ) ), | |||
new CLOptionDescriptor( "ext-path", | |||
CLOptionDescriptor.ARGUMENT_REQUIRED, | |||
EXTLIB_DIR_OPT, | |||
REZ.getString( "extlib.opt" ) ), | |||
new CLOptionDescriptor( "incremental", | |||
CLOptionDescriptor.ARGUMENT_DISALLOWED, | |||
INCREMENTAL_OPT, | |||
@@ -257,7 +262,10 @@ public class CLIMain | |||
m_embedded.setEmbeddorProperty( "myrmidon.home", option.getArgument() ); | |||
break; | |||
case TASKLIB_DIR_OPT: | |||
m_embedded.setEmbeddorProperty( "myrmidon.lib.path", option.getArgument() ); | |||
m_embedded.setEmbeddorProperty( "myrmidon.antlib.path", option.getArgument() ); | |||
break; | |||
case EXTLIB_DIR_OPT: | |||
m_embedded.setEmbeddorProperty( "myrmidon.ext.path", option.getArgument() ); | |||
break; | |||
case LOG_LEVEL_OPT: | |||
@@ -14,11 +14,14 @@ import java.util.Map; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.excalibur.io.FileUtil; | |||
import org.apache.avalon.excalibur.util.StringUtil; | |||
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.context.Context; | |||
import org.apache.avalon.framework.context.Contextualizable; | |||
import org.apache.avalon.framework.context.DefaultContext; | |||
import org.apache.avalon.framework.logger.AbstractLogEnabled; | |||
import org.apache.avalon.framework.parameters.Parameterizable; | |||
import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.myrmidon.api.TaskException; | |||
import org.apache.myrmidon.interfaces.embeddor.Embeddor; | |||
@@ -48,13 +51,14 @@ public class EmbeddedAnt | |||
private static final String DEFAULT_EMBEDDOR_CLASS = | |||
"org.apache.myrmidon.components.embeddor.DefaultEmbeddor"; | |||
private final ArrayList m_listeners = new ArrayList(); | |||
private final Parameters m_builderProps = new Parameters(); | |||
private final Map m_embeddorParameters = new HashMap(); | |||
private final Map m_workspaceProperties = new HashMap(); | |||
private String m_projectFile = "build.ant"; | |||
private Project m_project; | |||
private String m_listenerName = "default"; | |||
private ArrayList m_listeners = new ArrayList(); | |||
private Parameters m_builderProps = new Parameters(); | |||
private Parameters m_embeddorParameters = new Parameters(); | |||
private Map m_workspaceProperties = new HashMap(); | |||
private ClassLoader m_sharedClassLoader; | |||
private Embeddor m_embeddor; | |||
private File m_homeDir; | |||
@@ -63,8 +67,8 @@ public class EmbeddedAnt | |||
/** | |||
* Sets the Myrmidon home directory. Default is to use the current | |||
* directory. | |||
* | |||
* @todo Autodetect myrmidon home, rather than using current directory | |||
* | |||
* @todo Autodetect myrmidon home, rather than using current directory | |||
* as the default (which is a dud default). | |||
*/ | |||
public void setHomeDirectory( final File homeDir ) | |||
@@ -144,8 +148,7 @@ public class EmbeddedAnt | |||
*/ | |||
public void setEmbeddorProperty( final String name, final Object value ) | |||
{ | |||
// TODO - Make properties Objects, not Strings | |||
m_embeddorParameters.setParameter( name, value.toString() ); | |||
m_embeddorParameters.put( name, value.toString() ); | |||
} | |||
/** | |||
@@ -163,15 +166,16 @@ public class EmbeddedAnt | |||
*/ | |||
public void executeTargets( final String[] targets ) throws Exception | |||
{ | |||
Map embeddorParameters = new HashMap( m_embeddorParameters ); | |||
setupPaths( embeddorParameters ); | |||
if( m_sharedClassLoader != null ) | |||
{ | |||
Thread.currentThread().setContextClassLoader( m_sharedClassLoader ); | |||
embeddorParameters.put( "myrmidon.shared.classloader", m_sharedClassLoader ); | |||
} | |||
checkHomeDir(); | |||
// Prepare the embeddor, and project model | |||
final Embeddor embeddor = prepareEmbeddor(); | |||
final Embeddor embeddor = prepareEmbeddor( embeddorParameters ); | |||
final Project project = prepareProjectModel( embeddor ); | |||
// Create a new workspace | |||
@@ -233,16 +237,16 @@ public class EmbeddedAnt | |||
/** | |||
* Make sure myrmidon home directory has been specified, and is a | |||
* directory. | |||
* directory. Set the paths that the embeddor expects. | |||
*/ | |||
private void checkHomeDir() throws Exception | |||
private void setupPaths( Map parameters ) throws Exception | |||
{ | |||
if( m_homeDir == null ) | |||
{ | |||
m_homeDir = new File( "." ).getAbsoluteFile(); | |||
} | |||
checkDirectory( m_homeDir, "home-dir.name" ); | |||
m_embeddorParameters.setParameter( "myrmidon.home", m_homeDir.getAbsolutePath() ); | |||
parameters.put( "myrmidon.home", m_homeDir ); | |||
if( getLogger().isInfoEnabled() ) | |||
{ | |||
@@ -250,28 +254,36 @@ public class EmbeddedAnt | |||
getLogger().info( message ); | |||
} | |||
String path = m_embeddorParameters.getParameter( "myrmidon.lib.path", "lib" ); | |||
File dir = resolveDirectory( m_homeDir, path, "task-lib-dir.name" ); | |||
m_embeddorParameters.setParameter( "myrmidon.lib.path", dir.getAbsolutePath() ); | |||
// Build the lib path | |||
String path = (String)parameters.get( "myrmidon.lib.path" ); | |||
File[] dirs = buildPath( m_homeDir, path, "lib", "lib-dir.name" ); | |||
parameters.put( "myrmidon.lib.path", dirs ); | |||
// Build the antlib search path | |||
path = (String)parameters.get( "myrmidon.antlib.path" ); | |||
dirs = buildPath( m_homeDir, path, "ext", "task-lib-dir.name" ); | |||
parameters.put( "myrmidon.antlib.path", dirs ); | |||
path = m_embeddorParameters.getParameter( "myrmidon.ext.path", "ext" ); | |||
dir = resolveDirectory( m_homeDir, path, "ext-dir.name" ); | |||
m_embeddorParameters.setParameter( "myrmidon.ext.path", dir.getAbsolutePath() ); | |||
// Build the extension search path | |||
path = (String)parameters.get( "myrmidon.ext.path" ); | |||
dirs = buildPath( m_homeDir, path, "ext", "ext-dir.name" ); | |||
parameters.put( "myrmidon.ext.path", dirs ); | |||
} | |||
/** | |||
* Prepares and returns the embeddor to use. | |||
*/ | |||
private Embeddor prepareEmbeddor() | |||
private Embeddor prepareEmbeddor( final Map parameters ) | |||
throws Exception | |||
{ | |||
if( m_embeddor == null ) | |||
{ | |||
m_embeddor = createEmbeddor(); | |||
setupLogger( m_embeddor ); | |||
if( m_embeddor instanceof Parameterizable ) | |||
if( m_embeddor instanceof Contextualizable ) | |||
{ | |||
( (Parameterizable)m_embeddor ).parameterize( m_embeddorParameters ); | |||
final Context context = new DefaultContext( parameters ); | |||
( (Contextualizable)m_embeddor ).contextualize( context ); | |||
} | |||
if( m_embeddor instanceof Initializable ) | |||
{ | |||
@@ -310,7 +322,7 @@ public class EmbeddedAnt | |||
final int count = m_listeners.size(); | |||
for( int i = 0; i < count; i++ ) | |||
{ | |||
final ProjectListener listener = (ProjectListener)m_listeners.get(i ); | |||
final ProjectListener listener = (ProjectListener)m_listeners.get( i ); | |||
workspace.addProjectListener( listener ); | |||
} | |||
} | |||
@@ -352,12 +364,38 @@ public class EmbeddedAnt | |||
/** | |||
* Resolve a directory relative to another base directory. | |||
*/ | |||
private File resolveDirectory( final File baseDir, final String dir, final String name ) | |||
private File[] buildPath( final File baseDir, | |||
final String path, | |||
final String defaultPath, | |||
final String name ) | |||
throws Exception | |||
{ | |||
final File file = FileUtil.resolveFile( baseDir, dir ); | |||
checkDirectory( file, name ); | |||
return file; | |||
// Build the canonical list of files | |||
final ArrayList files = new ArrayList(); | |||
// Add the default path | |||
files.add( FileUtil.resolveFile( baseDir, defaultPath ) ); | |||
// Add the additional path | |||
if( path != null ) | |||
{ | |||
final String[] split = StringUtil.split( path, File.pathSeparator ); | |||
for( int i = 0; i < split.length; i++ ) | |||
{ | |||
final String s = split[ i ]; | |||
final File file = new File( s ).getAbsoluteFile(); | |||
files.add( file ); | |||
} | |||
} | |||
// Check each one | |||
for( int i = 0; i < files.size(); i++ ) | |||
{ | |||
File file = (File)files.get( i ); | |||
checkDirectory( file, name ); | |||
} | |||
return (File[])files.toArray( new File[ files.size() ] ); | |||
} | |||
/** | |||
@@ -9,7 +9,8 @@ debug.opt=Equivalent to --log-level=DEBUG. | |||
listener.opt=Specify the listener for log events. | |||
noprefix.opt=Do not prefix output with the task name. Equivalent to --listener noprefix. | |||
version.opt=Display version. | |||
tasklib.opt=Specify the task lib directory to scan for .atl files. | |||
tasklib.opt=Specify the path to use to search for antlib libraries. | |||
extlib.opt=Specify the path to use to search for optional packages. | |||
incremental.opt=Run in incremental mode. | |||
home.opt=Specify Ant home directory. | |||
define.opt=Define a property (ie -Dfoo=var). | |||
@@ -29,5 +30,6 @@ repeat.notice=Continue ? (Enter no to stop) | |||
homedir.notice=Ant Home Directory: {0} | |||
buildfile.notice=Ant Build File: {0} | |||
home-dir.name=Ant home directory | |||
task-lib-dir.name=Task library directory | |||
ext-dir.name=Extension library directory | |||
lib-dir.name=Library directory | |||
task-lib-dir.name=Antlib directory | |||
ext-dir.name=Extension directory |
@@ -7,19 +7,22 @@ | |||
*/ | |||
package org.apache.myrmidon.components; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
import java.io.File; | |||
import java.util.Map; | |||
import org.apache.aut.converter.Converter; | |||
import org.apache.avalon.framework.activity.Initializable; | |||
import org.apache.avalon.framework.context.Context; | |||
import org.apache.avalon.framework.context.Contextualizable; | |||
import org.apache.avalon.framework.context.DefaultContext; | |||
import org.apache.avalon.framework.logger.LogEnabled; | |||
import org.apache.avalon.framework.logger.Logger; | |||
import org.apache.avalon.framework.service.DefaultServiceManager; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
import org.apache.avalon.framework.service.Serviceable; | |||
import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.avalon.framework.parameters.Parameterizable; | |||
import org.apache.avalon.framework.activity.Initializable; | |||
import org.apache.myrmidon.AbstractMyrmidonTest; | |||
import org.apache.myrmidon.components.classloader.DefaultClassLoaderManager; | |||
import org.apache.myrmidon.components.configurer.DefaultConfigurer; | |||
@@ -124,26 +127,26 @@ public abstract class AbstractComponentTest | |||
} | |||
} | |||
// Compose the components | |||
// Contextualise the components | |||
final Context context = new DefaultContext( getParameters() ); | |||
for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||
{ | |||
Object obj = iterator.next(); | |||
if( obj instanceof Serviceable ) | |||
if( obj instanceof Contextualizable ) | |||
{ | |||
final Serviceable serviceable = (Serviceable)obj; | |||
serviceable.service( m_serviceManager ); | |||
final Contextualizable contextualizable = (Contextualizable)obj; | |||
contextualizable.contextualize( context ); | |||
} | |||
} | |||
// Parameterise the components | |||
final Parameters parameters = getParameters(); | |||
// Compose the components | |||
for( Iterator iterator = components.iterator(); iterator.hasNext(); ) | |||
{ | |||
Object obj = iterator.next(); | |||
if( obj instanceof Parameterizable ) | |||
if( obj instanceof Serviceable ) | |||
{ | |||
final Parameterizable parameterizable = (Parameterizable)obj; | |||
parameterizable.parameterize( parameters ); | |||
final Serviceable serviceable = (Serviceable)obj; | |||
serviceable.service( m_serviceManager ); | |||
} | |||
} | |||
@@ -173,12 +176,12 @@ public abstract class AbstractComponentTest | |||
* Creates the parameters for the test. Sub-classes can override this | |||
* method to set-up the parameters. | |||
*/ | |||
protected Parameters getParameters() | |||
protected Map getParameters() | |||
{ | |||
final Parameters parameters = new Parameters(); | |||
final String homeDir = getInstallDirectory().getAbsolutePath(); | |||
parameters.setParameter( "myrmidon.home", homeDir ); | |||
parameters.setParameter( "myrmidon.ext.path", homeDir + File.separatorChar + "ext" ); | |||
final Map parameters = new HashMap(); | |||
final File homeDir = getInstallDirectory(); | |||
parameters.put( "myrmidon.home", homeDir ); | |||
parameters.put( "myrmidon.ext.path", new File[] { new File ( homeDir, "ext" ) } ); | |||
return parameters; | |||
} | |||
@@ -11,12 +11,12 @@ import java.io.File; | |||
import java.net.URL; | |||
import java.net.URLClassLoader; | |||
import java.util.Enumeration; | |||
import java.util.Map; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.myrmidon.components.AbstractComponentTest; | |||
import org.apache.myrmidon.components.classloader.DefaultClassLoaderManager; | |||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager; | |||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderException; | |||
import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.myrmidon.interfaces.classloader.ClassLoaderManager; | |||
/** | |||
* Test cases for the DefaultClassLoaderManager. | |||
@@ -87,10 +87,10 @@ public class DefaultClassLoaderManagerTestCase | |||
* Creates the parameters for the test. Sub-classes can override this | |||
* method to set-up the parameters. | |||
*/ | |||
protected Parameters getParameters() | |||
protected Map getParameters() | |||
{ | |||
final Parameters parameters = super.getParameters(); | |||
parameters.setParameter( "myrmidon.ext.path", getTestDirectory( "ext" ).getAbsolutePath() ); | |||
final Map parameters = super.getParameters(); | |||
parameters.put( "myrmidon.ext.path", new File[] { getTestDirectory( "ext" ) } ); | |||
return parameters; | |||
} | |||
@@ -9,7 +9,7 @@ package org.apache.myrmidon.components.embeddor.test; | |||
import java.io.File; | |||
import java.util.HashMap; | |||
import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.avalon.framework.context.DefaultContext; | |||
import org.apache.avalon.framework.logger.Logger; | |||
import org.apache.myrmidon.AbstractProjectTest; | |||
import org.apache.myrmidon.LogMessageTracker; | |||
@@ -62,10 +62,9 @@ public class DefaultEmbeddorTest | |||
m_embeddor = new DefaultEmbeddor(); | |||
m_embeddor.enableLogging( logger ); | |||
final Parameters params = new Parameters(); | |||
final File instDir = getInstallDirectory(); | |||
params.setParameter( "myrmidon.home", instDir.getAbsolutePath() ); | |||
m_embeddor.parameterize( params ); | |||
final DefaultContext context = new DefaultContext(); | |||
context.put( "myrmidon.home", getInstallDirectory() ); | |||
m_embeddor.contextualize( context ); | |||
m_embeddor.initialize(); | |||
m_embeddor.start(); | |||
} | |||
@@ -7,10 +7,10 @@ | |||
*/ | |||
package org.apache.myrmidon.components.service.test; | |||
import org.apache.avalon.excalibur.i18n.ResourceManager; | |||
import org.apache.avalon.excalibur.i18n.Resources; | |||
import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.avalon.framework.service.ServiceException; | |||
import org.apache.avalon.framework.context.DefaultContext; | |||
import org.apache.myrmidon.components.AbstractComponentTest; | |||
import org.apache.myrmidon.components.service.InstantiatingServiceManager; | |||
import org.apache.myrmidon.interfaces.role.RoleInfo; | |||
@@ -31,7 +31,6 @@ public class InstantiatingServiceManagerTestCase | |||
private final static Resources REZ = getResourcesForTested( InstantiatingServiceManagerTestCase.class ); | |||
private InstantiatingServiceManager m_serviceManager; | |||
private Parameters m_parameters = new Parameters(); | |||
public InstantiatingServiceManagerTestCase( final String name ) | |||
{ | |||
@@ -47,8 +46,9 @@ public class InstantiatingServiceManagerTestCase | |||
// Set-up the service manager | |||
m_serviceManager = new InstantiatingServiceManager(); | |||
m_serviceManager.enableLogging( getLogger() ); | |||
m_serviceManager.contextualize( new DefaultContext() ); | |||
m_serviceManager.service( getServiceManager() ); | |||
m_serviceManager.parameterize( m_parameters ); | |||
m_serviceManager.parameterize( new Parameters() ); | |||
} | |||
/** | |||
@@ -101,7 +101,14 @@ public class InstantiatingServiceManagerTestCase | |||
assertTrue( service.getClass() == TestServiceImpl2.class ); | |||
// Assert the service has been setup correctly | |||
service.doWork(); | |||
LifecycleValidator validate = (LifecycleValidator)service; | |||
validate.assertSetup(); | |||
// Cleanup | |||
m_serviceManager.dispose(); | |||
// Assert the service has been shutdown correctly | |||
validate.assertDisposed(); | |||
} | |||
/** | |||
@@ -9,6 +9,7 @@ package org.apache.myrmidon.components.service.test; | |||
import junit.framework.Assert; | |||
import org.apache.avalon.framework.activity.Initializable; | |||
import org.apache.avalon.framework.activity.Disposable; | |||
import org.apache.avalon.framework.logger.LogEnabled; | |||
import org.apache.avalon.framework.logger.Logger; | |||
import org.apache.avalon.framework.parameters.ParameterException; | |||
@@ -17,6 +18,9 @@ import org.apache.avalon.framework.parameters.Parameters; | |||
import org.apache.avalon.framework.service.ServiceException; | |||
import org.apache.avalon.framework.service.ServiceManager; | |||
import org.apache.avalon.framework.service.Serviceable; | |||
import org.apache.avalon.framework.context.Contextualizable; | |||
import org.apache.avalon.framework.context.Context; | |||
import org.apache.avalon.framework.context.ContextException; | |||
/** | |||
* A basic class that asserts that the object is correctly set-up. | |||
@@ -26,7 +30,7 @@ import org.apache.avalon.framework.service.Serviceable; | |||
*/ | |||
public class LifecycleValidator | |||
extends Assert | |||
implements LogEnabled, Serviceable, Parameterizable, Initializable | |||
implements LogEnabled, Contextualizable, Serviceable, Parameterizable, Initializable, Disposable | |||
{ | |||
private String m_state = STATE_NOT_INIT; | |||
@@ -34,7 +38,9 @@ public class LifecycleValidator | |||
private final static String STATE_LOG_ENABLED = "log-enabled"; | |||
private final static String STATE_SERVICED = "serviced"; | |||
private final static String STATE_PARAMETERISED = "parameterised"; | |||
protected final static String STATE_INITIALISED = "initialised"; | |||
private final static String STATE_INITIALISED = "initialised"; | |||
private final static String STATE_CONTEXTUALISED = "contextualised"; | |||
private final static String STATE_DISPOSED = "disposed"; | |||
public void enableLogging( final Logger logger ) | |||
{ | |||
@@ -42,13 +48,19 @@ public class LifecycleValidator | |||
m_state = STATE_LOG_ENABLED; | |||
} | |||
public void service( final ServiceManager serviceManager ) throws ServiceException | |||
public void contextualize( final Context context ) throws ContextException | |||
{ | |||
assertEquals( STATE_LOG_ENABLED, m_state ); | |||
m_state = STATE_CONTEXTUALISED; | |||
} | |||
public void service( final ServiceManager serviceManager ) throws ServiceException | |||
{ | |||
assertEquals( STATE_CONTEXTUALISED, m_state ); | |||
m_state = STATE_SERVICED; | |||
} | |||
public void parameterize( Parameters parameters ) throws ParameterException | |||
public void parameterize( final Parameters parameters ) throws ParameterException | |||
{ | |||
assertEquals( STATE_SERVICED, m_state ); | |||
m_state = STATE_PARAMETERISED; | |||
@@ -60,8 +72,19 @@ public class LifecycleValidator | |||
m_state = STATE_INITIALISED; | |||
} | |||
public void dispose() | |||
{ | |||
assertEquals( STATE_INITIALISED, m_state ); | |||
m_state = STATE_DISPOSED; | |||
} | |||
protected void assertSetup() | |||
{ | |||
assertEquals( STATE_INITIALISED, m_state ); | |||
} | |||
protected void assertDisposed() | |||
{ | |||
assertEquals( STATE_DISPOSED, m_state ); | |||
} | |||
} |