You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2002/08/23 11:23:03 UTC

cvs commit: jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel DefaultKernel.java Kernel.java

mcconnell    2002/08/23 02:23:03

  Modified:    assembly build.xml default.properties
               assembly/src/etc kernel.xml
               assembly/src/java/org/apache/excalibur/merlin/assembly
                        ContainerManager.java DefaultLoggerManager.java
                        TypeManager.java
               assembly/src/java/org/apache/excalibur/merlin/kernel
                        DefaultKernel.java Kernel.java
  Log:
  Updates to handle Merlin running in Phoenix as a managed block.
  
  Revision  Changes    Path
  1.53      +23 -0     jakarta-avalon-excalibur/assembly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/build.xml,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- build.xml	23 Aug 2002 06:57:48 -0000	1.52
  +++ build.xml	23 Aug 2002 09:23:02 -0000	1.53
  @@ -190,6 +190,29 @@
   
       </target>
   
  +    <!-- Creates all the .sar file -->
  +    <target name="sar" depends="deploy" description="Generates the sar files">
  +
  +        <mkdir dir="${build.lib}"/>
  +
  +        <jar jarfile="${build.lib}/${sar.name}"
  +            compress="${build.compress}"
  +            manifest="${src.dir}/etc/project.mf">
  +            <zipfileset dir="${build.conf}" prefix="META-INF/">
  +                <include name="LICENSE.txt"/>
  +            </zipfileset>
  +            <zipfileset dir="${src.dir}/etc/conf" prefix="SAR-INF/">
  +                <include name="assembly.xml"/>
  +                <include name="config.xml"/>
  +                <include name="environment.xml"/>
  +            </zipfileset>
  +            <zipfileset dir="${extension.dir}" prefix="SAR-INF/lib">
  +                <include name="*.jar"/>
  +            </zipfileset>
  +        </jar>
  +
  +    </target>
  +
       <!-- Creates all the Javadocs -->
       <target name="javadocs" depends="compile" description="Generates the javadocs" unless="skip.javadocs">
           <mkdir dir="${build.javadocs}"/>
  
  
  
  1.7       +1 -1      jakarta-avalon-excalibur/assembly/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/default.properties,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- default.properties	21 Aug 2002 23:19:35 -0000	1.6
  +++ default.properties	23 Aug 2002 09:23:02 -0000	1.7
  @@ -130,6 +130,6 @@
   extension.dir = extensions
   demo.name = demo
   demo.jar = ${demo.name}.jar
  -
  +sar.name = ${name}-${version}.sar
   
   
  
  
  
  1.38      +2 -5      jakarta-avalon-excalibur/assembly/src/etc/kernel.xml
  
  Index: kernel.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/etc/kernel.xml,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- kernel.xml	23 Aug 2002 03:41:52 -0000	1.37
  +++ kernel.xml	23 Aug 2002 09:23:02 -0000	1.38
  @@ -31,17 +31,14 @@
   
      <!--
      Declaration of installed extension directories and kernel level classpath.
  +   In this demo we are referencing the Merlin classes in the embedded demo so 
  +   we need at least to include Merlin in the extensions directory.
      -->
   
      <library dir=".">
        <include name="extensions"/>
      </library>
   
  -   <classpath>
  -     <fileset dir="build/lib">
  -       <include name="merlin-2.0a.jar"/>
  -     </fileset>
  -   </classpath>
   
      <!--
      Defintion of the lifestyle manager.
  
  
  
  1.27      +5 -2      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/ContainerManager.java
  
  Index: ContainerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/ContainerManager.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- ContainerManager.java	23 Aug 2002 06:25:13 -0000	1.26
  +++ ContainerManager.java	23 Aug 2002 09:23:02 -0000	1.27
  @@ -190,6 +190,9 @@
       */
       private DeploymentHelper m_deployment;
   
  +   /**
  +    * The base directory.
  +    */
       private File m_home;
   
       //===================================================================
  @@ -239,7 +242,7 @@
       //=======================================================================
   
      /**
  -    * Declaration of the logging manager.
  +    * Declaration of the base directory and logging manager.
       * @param context the context object containing the inital parameters
       * @exception ContextException if the context criterai is not met
       */
  
  
  
  1.9       +6 -7      jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/DefaultLoggerManager.java
  
  Index: DefaultLoggerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/DefaultLoggerManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DefaultLoggerManager.java	22 Aug 2002 06:11:57 -0000	1.8
  +++ DefaultLoggerManager.java	23 Aug 2002 09:23:02 -0000	1.9
  @@ -89,12 +89,12 @@
       * Creation of a new LoggerManager.
       * @exception Exception is an error occurs
       */
  -    public DefaultLoggerManager() throws Exception
  +    public DefaultLoggerManager( File base ) throws Exception
       {
           this( 
             new LoggingDescriptor( 
               "", null, null, new TargetDescriptor[0], 
  -            new Category("logging", "WARN", null ) ) );
  +            new Category("logging", "WARN", null ) ), base );
       }
   
      /**
  @@ -102,7 +102,7 @@
       * @param descriptor the logging system description
       * @exception Exception is an error occurs
       */
  -    public DefaultLoggerManager( final LoggingDescriptor descriptor ) throws Exception
  +    public DefaultLoggerManager( final LoggingDescriptor descriptor, File base ) throws Exception
       {
    
           //
  @@ -110,7 +110,7 @@
           //
   
           m_stream = new StreamTarget( System.out, new AvalonFormatter( DEFAULT_FORMAT ) );
  -        m_baseDirectory = new File( System.getProperty("user.dir") );
  +        m_baseDirectory = base;
           m_logHierarchy = new Hierarchy();
           getHierarchy().setDefaultLogTarget( m_stream );
           m_targets.put( DEFAULT_TARGET, m_stream );
  @@ -344,7 +344,6 @@
   
       private void addTarget( TargetDescriptor target ) throws Exception
       {
  -         File base = new File( System.getProperty("user.dir") );
            final String name = target.getName();
            TargetProvider provider = target.getProvider();
            if( provider instanceof FileTargetProvider )
  @@ -352,16 +351,16 @@
                FileTargetProvider fileProvider = (FileTargetProvider) provider;
                String filename = fileProvider.getLocation();
                final AvalonFormatter formatter = new AvalonFormatter( DEFAULT_FORMAT );
  +             File file = new File( m_baseDirectory, filename );
                try
                {
  -                 File file = new File( base, filename );
                    FileTarget logTarget = new FileTarget( file.getAbsoluteFile(), false, formatter );
                    m_targets.put( name, logTarget );
                }
                catch( final IOException ioe )
                {
                    final String message =
  -                     REZ.getString( "target.nocreate", name, filename, ioe.getMessage() );
  +                     REZ.getString( "target.nocreate", name, file, ioe.getMessage() );
                    throw new TypeException( message, ioe );
                }
            }
  
  
  
  1.16      +11 -6     jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/TypeManager.java
  
  Index: TypeManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/TypeManager.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TypeManager.java	22 Aug 2002 10:13:39 -0000	1.15
  +++ TypeManager.java	23 Aug 2002 09:23:02 -0000	1.16
  @@ -118,6 +118,11 @@
       */
       private TypeRegistry m_types;
   
  +   /**
  +    * The base directory.
  +    */
  +    private File m_home;
  +
       //===================================================================
       // constructor
       //===================================================================
  @@ -169,12 +174,14 @@
       //=======================================================================
   
      /**
  -    * Declaration of the extensions and classpath descriptors.
  +    * Declaration of the base directory, extensions, classpath descriptors.
       * @param context the context object containing the inital parameters
       * @exception ContextException if a context related error occurs
       */
       public void contextualize( Context context ) throws ContextException
       {
  +        m_home = (File) context.get("avalon:home");
  +
           try
           {
               m_extensions = (LibraryDescriptor) context.get( EXTENSIONS_DESCRIPTOR_KEY );
  @@ -221,8 +228,7 @@
               getLocalLogger().debug( "initializing extensions libraries" );
               ArrayList list = new ArrayList();
   
  -            File dir = new File( System.getProperty("user.dir") );
  -            File base = new File( dir, m_extensions.getBaseDirectory() );
  +            File base = new File( m_home, m_extensions.getBaseDirectory() );
   
               IncludeDescriptor[] includes = m_extensions.getIncludeDescriptors();
               for( int j=0; j<includes.length; j++ )
  @@ -379,12 +385,11 @@
           getLocalLogger().debug( "adding classpath" );
           List list = new ArrayList();
           Vector stack = new Vector();
  -        File dir = new File( System.getProperty("user.dir") );
           FilesetDescriptor[] dirs = classpath.getFilesetDescriptors();
           for( int i=0; i<dirs.length; i++ )
           {
               FilesetDescriptor descriptor = dirs[i];
  -            File base = new File( dir, descriptor.getBaseDirectory() );
  +            File base = new File( m_home, descriptor.getBaseDirectory() );
               if( !base.exists() )
               {
                   final String error = 
  
  
  
  1.45      +64 -22    jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/DefaultKernel.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- DefaultKernel.java	23 Aug 2002 06:25:13 -0000	1.44
  +++ DefaultKernel.java	23 Aug 2002 09:23:03 -0000	1.45
  @@ -10,6 +10,8 @@
   
   import java.io.File;
   import java.util.ArrayList;
  +import java.io.FileInputStream;
  +import java.io.InputStream;
   
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.logger.LogEnabled;
  @@ -17,6 +19,8 @@
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Startable;
   import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.context.Context;
  @@ -106,20 +110,6 @@
     Disposable
   {
       //=======================================================================
  -    // static
  -    //=======================================================================
  -
  -   /**
  -    * The context key for the working directory.
  -    */
  -    public static final String DIR_KEY = "avalon:home";
  -
  -   /**
  -    * The context key for the path to the configuration.
  -    */
  -    public static final String PATH_KEY = "path";
  -
  -    //=======================================================================
       // state
       //=======================================================================
   
  @@ -194,6 +184,8 @@
   
       private ContainerManager m_parent;
   
  +    private File m_baseDirectory;
  +
       //=======================================================================
       // Contextualizable
       //=======================================================================
  @@ -210,22 +202,22 @@
       {
           try
           {
  -            context.get( DIR_KEY );
  +            m_baseDirectory = (File) context.get( DIR_KEY );
               m_context = context;
           }
           catch( ContextException contextException )
           {
               // this situation is possible if the Merlin Kernel is being
               // execution inside a container such a Phoenix which does not 
  -            // provide ontext management - the only solution is to attempt
  +            // provide context management - the only solution is to attempt
               // to guess the environment - otherwise we will throw a context 
               // exception
   
               try
               {
  -                File appHome = (File) context.get("app.home");
  +                m_baseDirectory = (File) context.get("app.home");
                   DefaultContext c = new DefaultContext( context );
  -                c.put( DIR_KEY, appHome );
  +                c.put( DIR_KEY, m_baseDirectory );
                   c.makeReadOnly();
                   m_context = c;
               }
  @@ -244,9 +236,38 @@
       * Configuration of the kernel.
       * @param config the configuration
       */
  -    public void configure( Configuration config )
  +    public void configure( Configuration config ) throws ConfigurationException
       {
  -        m_config = config;
  +        if( config.getName().equals("merlin") )
  +        {
  +            //
  +            // we are running in a foreign environment so we need to 
  +            // take care of configuration loading ourselves
  +            //
  +   
  +            File base = m_baseDirectory;
  +            String path = config.getAttribute( "path", "kernel.xml" );
  +            File file = new File( base, path );
  +            try
  +            {
  +                m_config = getBootstrapConfiguration( file );
  +            }
  +            catch( Throwable be )
  +            {
  +                final String error = 
  +                  "Could not load a kernel configuration from the path: '" 
  +                  + file + "' due to an unexpected error.";
  +                throw new ConfigurationException( error, be );
  +            }
  +        }
  +        else
  +        {
  +            //
  +            // classic execution scenario
  +            //
  +
  +            m_config = config;
  +        }
       }
   
       //=======================================================================
  @@ -297,7 +318,7 @@
           {
               LoggingDescriptor logging =
                 m_creator.createLoggingDescriptor( m_config.getChild("logging"), name );
  -            c_logging = new DefaultLoggerManager( logging );
  +            c_logging = new DefaultLoggerManager( logging, m_baseDirectory );
               m_base = name;
   
               //
  @@ -619,4 +640,25 @@
           getLogger().debug("commencing assembly verification");
           verifier.verifyAssembly( profiles );
       }
  +
  +    private Configuration getBootstrapConfiguration( final File file ) throws Exception
  +    {
  +        try
  +        {
  +            DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  +            InputStream is = new FileInputStream( file );
  +            if( is == null )
  +            {
  +                throw new RuntimeException(
  +                    "Could not load the configuration resource \"" + file + "\"" );
  +            }
  +            return builder.build( is );
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = "Unable to create configuration from file: " + file;
  +            throw new KernelException( error, e );
  +        }
  +    }
  +
   }
  
  
  
  1.14      +18 -1     jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/Kernel.java
  
  Index: Kernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/kernel/Kernel.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Kernel.java	22 Aug 2002 13:43:02 -0000	1.13
  +++ Kernel.java	23 Aug 2002 09:23:03 -0000	1.14
  @@ -21,6 +21,23 @@
    */
   public interface Kernel
   {
  +    //=======================================================================
  +    // static
  +    //=======================================================================
  +
  +   /**
  +    * The context key for the working directory.
  +    */
  +    public static final String DIR_KEY = "avalon:home";
  +
  +   /**
  +    * The context key for the path to the configuration.
  +    */
  +    public static final String PATH_KEY = "path";
  +
  +    //=======================================================================
  +    // interface
  +    //=======================================================================
   
      /**
       * Method invoked to request type level validation of the application.
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>