mcconnell 2003/12/04 17:29:05
Modified: kernel/api/src/java/org/apache/avalon/merlin
KernelCriteria.java
kernel/impl/src/java/org/apache/avalon/merlin/impl
DefaultCriteria.java DefaultFactory.java
DefaultKernel.java
kernel/test merlin.properties
kernel/test/src/test/org/apache/avalon/merlin
MerlinEmbeddedTest.java
Log:
Addition of the configuration override solution.
Revision Changes Path
1.3 +2 -2
avalon-sandbox/kernel/api/src/java/org/apache/avalon/merlin/KernelCriteria.java
Index: KernelCriteria.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/api/src/java/org/apache/avalon/merlin/KernelCriteria.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- KernelCriteria.java 4 Dec 2003 00:25:03 -0000 1.2
+++ KernelCriteria.java 5 Dec 2003 01:29:05 -0000 1.3
@@ -101,7 +101,7 @@
* Return the url to the configuration override targets.
* @return the override url
*/
- URL getOverrideURL();
+ String getOverridePath();
/**
* Return the working client directory.
1.6 +5 -5
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultCriteria.java
Index: DefaultCriteria.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultCriteria.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultCriteria.java 4 Dec 2003 00:25:03 -0000 1.5
+++ DefaultCriteria.java 5 Dec 2003 01:29:05 -0000 1.6
@@ -141,7 +141,7 @@
"merlin.kernel";
/**
- * Merlin target configuration override url
+ * Merlin target configuration override path.
*/
public static final String MERLIN_OVERRIDE =
"merlin.override";
@@ -217,7 +217,7 @@
new Parameter(
MERLIN_KERNEL, URL.class, null ),
new Parameter(
- MERLIN_OVERRIDE, URL.class, null ),
+ MERLIN_OVERRIDE, String.class, null ),
new Parameter(
MERLIN_DIR, File.class, USER_DIR ),
new Parameter(
@@ -415,9 +415,9 @@
* Return the url to the configuration override targets.
* @return the override url
*/
- public URL getOverrideURL()
+ public String getOverridePath()
{
- return (URL) get( MERLIN_OVERRIDE );
+ return (String) get( MERLIN_OVERRIDE );
}
/**
1.6 +85 -39
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java
Index: DefaultFactory.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultFactory.java 4 Dec 2003 00:25:03 -0000 1.5
+++ DefaultFactory.java 5 Dec 2003 01:29:05 -0000 1.6
@@ -40,6 +40,7 @@
import org.apache.avalon.composition.model.impl.DefaultContainmentModel;
import org.apache.avalon.composition.model.impl.DefaultClassLoaderModel;
import org.apache.avalon.composition.model.impl.DefaultClassLoaderContext;
+import org.apache.avalon.composition.util.StringHelper;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
@@ -52,6 +53,7 @@
import org.apache.avalon.merlin.Kernel;
import org.apache.avalon.merlin.KernelException;
+import org.apache.avalon.merlin.KernelRuntimeException;
import org.apache.avalon.merlin.KernelCriteria;
import org.apache.avalon.repository.Repository;
@@ -321,49 +323,62 @@
getContainmentProfile(
kernelConfig.getChild( "container" ) ) ) );
- URL overridesURL = criteria.getOverrideURL();
- TargetDirective[] overrides = getTargetOverrides( overridesURL );
+ //
+ // install any blocks declared within the kernel context
+ //
- for( int i=0; i<overrides.length; i++ )
+ getLogger().debug( "install phase" );
+ URL[] urls = criteria.getDeploymentURLs();
+ for( int i=0; i<urls.length; i++ )
{
- TargetDirective target = overrides[i];
- final String path = target.getPath();
- Object model = application.getModel( path );
- if( model != null )
+ URL url = urls[i];
+
+ if( getLogger().isInfoEnabled() )
{
- if( model instanceof DeploymentModel )
- {
- DeploymentModel deployment = (DeploymentModel) model;
- if( target.getConfiguration() != null )
- {
- deployment.setConfiguration( target.getConfiguration() );
- }
- if( target.getCategoriesDirective() != null )
- {
- deployment.setCategories( target.getCategoriesDirective() );
- }
- }
- else if( model instanceof ContainmentModel )
- {
- ContainmentModel containment = (ContainmentModel) model;
- if( target.getCategoriesDirective() != null )
- {
- containment.setCategories( target.getCategoriesDirective()
);
- }
- }
+ getLogger().info(
+ "installing: "
+ + StringHelper.toString( url ) );
}
- else
+
+ try
{
- final String warning =
- "Ignoring target directive as the path does not refer to a known
component: "
- + path;
- getLogger().warn( warning );
+ application.addModel( url );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Install failure: " + url;
+ throw new KernelException( error, e );
}
}
+ //
+ // customize the meta model
+ //
+
+ try
+ {
+ final String path = criteria.getOverridePath();
+ if( null == path ) return new TargetDirective[0];
+ File base = criteria.getWorkingDirectory();
+ URL url = resolveURL( base, path );
+ application.applyTargets( url );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Target override assignment failure.";
+ throw new KernelException( error, e );
+ }
+
+ //
+ // instantiate the runtime root application block
+ //
+
try
{
- m_application = AbstractBlock.createRootBlock( services, application );
+ m_application =
+ AbstractBlock.createRootBlock( services, application );
}
catch( Throwable e )
{
@@ -371,9 +386,13 @@
"Composition failure.";
throw new KernelException( error, e );
}
-
- Kernel kernel = createKernel( getLogger(), criteria, m_system,
m_application );
+ //
+ // instantiate the kernel
+ //
+
+ Kernel kernel =
+ createKernel( getLogger(), criteria, m_system, m_application );
if( criteria.isAutostartEnabled() )
{
try
@@ -391,12 +410,14 @@
return kernel;
}
- private Kernel createKernel( Logger logger, KernelCriteria criteria, Block
system, Block application )
+ private Kernel createKernel(
+ Logger logger, KernelCriteria criteria, Block system, Block application )
throws KernelException
{
try
{
- return new DefaultKernel( getLogger(), criteria, m_system,
m_application );
+ return new DefaultKernel(
+ logger, criteria, system, application );
}
catch( Throwable e )
{
@@ -674,10 +695,13 @@
}
}
- private TargetDirective[] getTargetOverrides( final URL url )
+ private TargetDirective[] getTargetOverrides( KernelCriteria criteria )
throws KernelException
{
- if( null == url ) return new TargetDirective[0];
+ final String path = criteria.getOverridePath();
+ if( null == path ) return new TargetDirective[0];
+ File base = criteria.getWorkingDirectory();
+ URL url = resolveURL( base, path );
try
{
@@ -691,6 +715,28 @@
final String error =
"Could not load the targets directive: " + url;
throw new KernelException( error, e );
+ }
+ }
+
+ private URL resolveURL( File base, String path )
+ {
+ try
+ {
+ if( path.indexOf( ":" ) > 0 )
+ {
+ return new URL( path );
+ }
+ else
+ {
+ return new File( base, path ).toURL();
+ }
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to convert the supplied path ["
+ + path + "] to a url.";
+ throw new KernelRuntimeException( error, e );
}
}
1.3 +5 -32
avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java
Index: DefaultKernel.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/impl/src/java/org/apache/avalon/merlin/impl/DefaultKernel.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultKernel.java 4 Dec 2003 00:25:03 -0000 1.2
+++ DefaultKernel.java 5 Dec 2003 01:29:05 -0000 1.3
@@ -138,6 +138,8 @@
final Block system,
final Block application ) throws KernelException
{
+ if( logger == null )
+ throw new NullPointerException( "logger" );
if( criteria == null )
throw new NullPointerException( "criteria" );
if( system == null )
@@ -150,41 +152,12 @@
m_application = application;
m_logger = logger;
- //
- // install any block declared within the kernel context
- //
-
- getLogger().debug( "install phase" );
- ContainmentModel model = (ContainmentModel) m_application.getModel();
- URL[] urls = m_criteria.getDeploymentURLs();
- for( int i=0; i<urls.length; i++ )
- {
- URL url = urls[i];
-
- if( getLogger().isInfoEnabled() )
- {
- getLogger().info(
- "installing: "
- + StringHelper.toString( url ) );
- }
-
- try
- {
- m_application.addModel( url );
- }
- catch( Throwable e )
- {
- final String error =
- "Block install failure: " + url;
- throw new KernelException( error, e );
- }
- }
-
setState( INITIALIZED );
if( getLogger().isDebugEnabled() )
{
- int count = model.getModels().length;
+ int count =
+ m_application.getContainmentModel().getModels().length;
if( count == 0 )
{
getLogger().debug( "kernel established" );
1.6 +1 -0 avalon-sandbox/kernel/test/merlin.properties
Index: merlin.properties
===================================================================
RCS file: /home/cvs/avalon-sandbox/kernel/test/merlin.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- merlin.properties 4 Dec 2003 00:25:03 -0000 1.5
+++ merlin.properties 5 Dec 2003 01:29:05 -0000 1.6
@@ -2,3 +2,4 @@
merlin.info = true
merlin.debug = false
merlin.deployment = conf/test.block,conf/test-2.block,conf/hello.block
+merlin.override = conf/override.xml
1.12 +13 -2
avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin/MerlinEmbeddedTest.java
Index: MerlinEmbeddedTest.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/kernel/test/src/test/org/apache/avalon/merlin/MerlinEmbeddedTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MerlinEmbeddedTest.java 3 Dec 2003 20:44:26 -0000 1.11
+++ MerlinEmbeddedTest.java 5 Dec 2003 01:29:05 -0000 1.12
@@ -111,8 +111,19 @@
Builder builder = new DefaultBuilder( context, artifact );
Factory factory = builder.getFactory();
Map criteria = factory.createDefaultCriteria();
- applyLocalProperties( criteria );
+ //
+ // set the base directory to the Maven ${basedir}
+ //
+
+ criteria.put( "merlin.dir", getBaseDirectory() );
+
+ //
+ // read in any properties declared under the path
+ // ${basedir}/merlin.properties
+ //
+
+ applyLocalProperties( criteria );
Object app = factory.create( criteria );
assertNotNull( "app", app );
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]