avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel DefaultKernel.java
Date Wed, 11 Dec 2002 08:12:25 GMT
mcconnell    2002/12/11 00:12:25

  Modified:    merlin   build.xml kernel.xml
               merlin/src/java/org/apache/avalon/merlin/block
                        BlockLoader.java
               merlin/src/java/org/apache/avalon/merlin/container/builder
                        XMLContainerCreator.java
               merlin/src/java/org/apache/avalon/merlin/kernel
                        DefaultKernel.java
  Log:
  Addition of support for subsidiary engine creation and deployment.
  
  Revision  Changes    Path
  1.6       +1 -2      avalon-sandbox/merlin/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/build.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- build.xml	11 Dec 2002 01:23:14 -0000	1.5
  +++ build.xml	11 Dec 2002 08:12:24 -0000	1.6
  @@ -40,13 +40,12 @@
   
     <path id="test.class.path">
       <path refid="project.class.path"/>
  -    <pathelement location="${build.dir}/lib/${demo.jar}"/>
  +    <pathelement location="${build.dir}/lib/${jar.name}"/>
       <pathelement location="${build.testclasses}"/>
     </path>
   
     <path id="runtime.class.path">
       <pathelement location="${build.dir}/lib/${jar.name}"/>
  -    <pathelement location="${build.dir}/lib/${demo.jar}"/>
       <pathelement location="${build.testclasses}"/>
     </path>
   
  
  
  
  1.6       +5 -2      avalon-sandbox/merlin/kernel.xml
  
  Index: kernel.xml
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/kernel.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- kernel.xml	11 Dec 2002 04:59:46 -0000	1.5
  +++ kernel.xml	11 Dec 2002 08:12:24 -0000	1.6
  @@ -14,15 +14,18 @@
   
      <engine>
   
  +     <!--
        <library dir=".">
          <include name="build/lib"/>
        </library>
  -
  +     -->
  +     <!--
        <classpath>
          <fileset dir="build/lib">
  -         <!--<include name="avalon-merlin-demo-1.0.jar"/>-->
  +         <include name="avalon-merlin-demo-1.0.jar"/>
          </fileset>
        </classpath>
  +     -->
   
      </engine>
   
  
  
  
  1.2       +108 -39   avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/BlockLoader.java
  
  Index: BlockLoader.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/block/BlockLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BlockLoader.java	11 Dec 2002 04:58:55 -0000	1.1
  +++ BlockLoader.java	11 Dec 2002 08:12:24 -0000	1.2
  @@ -87,7 +87,6 @@
   import org.apache.avalon.assembly.logging.LoggingDescriptor;
   import org.apache.avalon.assembly.logging.DefaultLoggingManager;
   import org.apache.avalon.assembly.engine.EngineClassLoader;
  -import org.apache.avalon.assembly.engine.Engine;
   import org.apache.avalon.assembly.engine.model.LibraryDescriptor;
   import org.apache.avalon.assembly.engine.model.ClasspathDescriptor;
   import org.apache.avalon.assembly.util.ExceptionHelper;
  @@ -125,7 +124,7 @@
       // BlockLoader
       //==============================================================
   
  -    protected Block[] install( Engine engine, File home, URL[] urls ) throws Exception
  +    protected Block[] install( EngineClassLoader parent, File home, URL[] urls ) throws
Exception
       {
           ArrayList blocks = new ArrayList();
           for( int i=0; i<urls.length; i++ )
  @@ -133,18 +132,27 @@
               URL url = urls[i];
               try
               {
  -                blocks.add( installBlock( engine, home, url ) );
  +                Block block = installBlock( parent, home, url );
  +                blocks.add( block );
               }
               catch( Throwable e )
               {
                   final String error = 
                     "Error during block deployment for url: " + url;
  +                throw new BlockException( error, e );
               }
           }
   
  -        Block[] result = (Block[]) blocks.toArray( new Block[0] );
  +        if( urls.length != blocks.size() )
  +        {
  +            getLogger().warn(
  +              "inconsistent load count - supplied: " 
  +              + urls.length 
  +              + " installed: " 
  +              + blocks.size() );
  +        }
   
  -        int n = result.length;
  +        int n = blocks.size();
           if( n > 0 )
           {
               if( n > 1 )
  @@ -157,42 +165,52 @@
               }
           }
   
  -        return result;
  +        return (Block[]) blocks.toArray( new Block[0] );
       }
   
  -    private Block installBlock( Engine engine, File home, URL url ) throws Exception
  +    private Block installBlock( EngineClassLoader parent, File home, URL url ) throws Exception
       {
  -         JarFile jar = getJarFile( url );
  -         Manifest manifest = jar.getManifest();
  -         if( !isBlock( manifest ) )
  -         {
  -             final String warning = 
  -               "Manifest does not declare a block on resource: " + url;
  -             throw new IllegalArgumentException( warning );
  -         }
  -
  -         Configuration blockConfig = getBlockConfiguration( jar );
  -
  -         String name = DefaultBlock.getName( manifest );
  -         if( name == null )
  -         {
  -             final String error = "Missing name in block: " + url;
  -             throw new IllegalArgumentException( error );
  -         }
  -
  -         Logger logger = getLogger().getChildLogger( name ) ;
  -         logger.debug( "[" + name + "]");
  -         DefaultBlock block = new DefaultBlock();
  -         block.enableLogging( logger );
  -         DefaultContext context = new DefaultContext();
  -         context.put( "urn:assembly:classloader", engine );
  -         context.put( "urn:merlin:block.manifest", manifest );
  -         context.put( "urn:merlin:block.url", url );
  -         context.put( "urn:avalon:home", home );
  -         context.makeReadOnly();
  -         block.contextualize( context );
  -         block.initialize();
  -         return block;
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            getLogger().debug( "block: " + url );
  +        }
  +        
  +        JarFile jar = getJarFile( url );
  +        Manifest manifest = jar.getManifest();
  +        if( !isBlock( manifest ) )
  +        {
  +            final String warning = 
  +              "Manifest does not declare a block within the resource: " + url;
  +            throw new IllegalArgumentException( warning );
  +        }
  +
  +        String name = DefaultBlock.getName( manifest );
  +        if( name == null )
  +        {
  +            final String error = "Missing name in block: " + url;
  +            throw new IllegalArgumentException( error );
  +        }
  +
  +        Logger logger = getLogger().getChildLogger( name ) ;
  +        logger.debug( "[" + name + "]");
  +
  +        Configuration blockConfig = getBlockConfiguration( jar );
  +        Configuration config = blockConfig.getChild( "engine" );
  +        EngineClassLoader engine = createChildEngine( parent, home, config, logger );
  +
  +
  +        DefaultContext context = new DefaultContext();
  +        context.put( "urn:assembly:classloader", engine );
  +        context.put( "urn:merlin:block.manifest", manifest );
  +        context.put( "urn:merlin:block.url", url );
  +        context.put( "urn:avalon:home", home );
  +        context.makeReadOnly();
  +
  +        DefaultBlock block = new DefaultBlock();
  +        block.enableLogging( logger );
  +        block.contextualize( context );
  +        block.initialize();
  +        return block;
       }
   
       protected boolean isBlock( Manifest manifest )
  @@ -252,6 +270,57 @@
           {
               final String error = "Unable to create configuration from jar file: " + jar.getName();
               throw new BlockException( error, e );
  +        }
  +    }
  +
  +    protected EngineClassLoader createChildEngine( 
  +      EngineClassLoader parent, File home, Configuration config, Logger logger ) 
  +      throws BlockException, ConfigurationException
  +    {
  +        LibraryDescriptor extensions;
  +        try
  +        {
  +            extensions =
  +              CREATOR.createLibraryDescriptor( 
  +                config.getChild( "library" ) );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "Bad library descriptor.";
  +            throw new BlockException( error, e );
  +        }
  +
  +        ClasspathDescriptor classpath;
  +        try
  +        {
  +            classpath =
  +              CREATOR.createClasspathDescriptor( 
  +                config.getChild( "classpath" ) );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "Bad classpath descriptor.";
  +            throw new BlockException( error, e );
  +        }
  +
  +        try
  +        {
  +            EngineClassLoader engine = new EngineClassLoader( parent );
  +            engine.enableLogging( logger.getChildLogger( "engine" ) );
  +            engine.configure( config );
  +            DefaultContext context = new DefaultContext();
  +            context.put( "urn:avalon:home", home );
  +            context.put( "urn:assembly:engine.extensions", extensions );
  +            context.put( "urn:assembly:engine.classpath", classpath );
  +            context.makeReadOnly();
  +            engine.contextualize( context );
  +            engine.initialize();
  +            return engine;
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "Engine bootstrap failure.";
  +             throw new BlockException( error, e );
           }
       }
   }
  
  
  
  1.4       +2 -24     avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/container/builder/XMLContainerCreator.java
  
  Index: XMLContainerCreator.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/container/builder/XMLContainerCreator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLContainerCreator.java	11 Dec 2002 04:59:46 -0000	1.3
  +++ XMLContainerCreator.java	11 Dec 2002 08:12:24 -0000	1.4
  @@ -229,11 +229,6 @@
           LoggingDirective categories =
               createLoggingDirective( name, profile.getChild( "categories" ) );
   
  -        //final boolean enabled =
  -        //    profile.getAttributeAsBoolean( "enabled", true );
  -        //final boolean activation =
  -        //    getActivationMode( profile );
  -
           final Parameters params =
               Parameters.fromConfiguration( profile.getChild( "parameters" ) );
           final ContextDirective context =
  @@ -384,24 +379,7 @@
       public LibraryDescriptor createLibraryDescriptor( Configuration config )
           throws ConfigurationException
       {
  -
  -        if( config == null )
  -        {
  -            return new LibraryDescriptor();
  -        }
  -
  -        String base = config.getAttribute( "dir" );
  -
  -        ArrayList list = new ArrayList();
  -        Configuration[] configs = config.getChildren( "include" );
  -        for( int i = 0; i < configs.length; i++ )
  -        {
  -            Configuration c = configs[ i ];
  -            list.add( createIncludeDescriptor( c ) );
  -        }
  -        IncludeDescriptor[] dirs =
  -            (IncludeDescriptor[])list.toArray( new IncludeDescriptor[ 0 ] );
  -        return new LibraryDescriptor( base, dirs );
  +        return EngineConfigurationHelper.createLibraryDescriptor( config );
       }
   
   }
  
  
  
  1.7       +9 -3      avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultKernel.java	11 Dec 2002 04:59:46 -0000	1.6
  +++ DefaultKernel.java	11 Dec 2002 08:12:25 -0000	1.7
  @@ -151,7 +151,7 @@
       /**
        * The assembly engine.
        */
  -    private Engine m_engine;
  +    private EngineClassLoader m_engine;
   
       //==============================================================
       // Contextualizable
  @@ -285,6 +285,12 @@
           ClasspathDescriptor path = 
             CREATOR.createClasspathDescriptor( m_config.getChild( "blocks" ) );
           URL[] urls = ClasspathDescriptor.expand( m_home, path );
  +
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            getLogger().debug( "blocks: " + urls.length );
  +        }
  +
           Block[] blocks = install( m_engine, m_home, urls );
   
       }
  @@ -387,7 +393,7 @@
           }
       }
   
  -    private Engine bootstrapEngine( LoggingManager logging, Configuration config ) 
  +    private EngineClassLoader bootstrapEngine( LoggingManager logging, Configuration config
) 
         throws Exception
       {
           if( m_home == null )
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message