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 2003/01/06 02:05:53 UTC
cvs commit: avalon-sandbox/merlin/src/test/org/apache/avalon/playground StandardComponent.java
mcconnell 2003/01/05 17:05:53
Modified: merlin build.xml default.properties
merlin/src/java/org/apache/avalon/merlin Main.java
merlin/src/java/org/apache/avalon/merlin/kernel
DefaultKernel.java DefaultKernel.xinfo
merlin/src/test/org/apache/avalon/playground
StandardComponent.java
Added: merlin merlin.properties
merlin/src/java/org/apache/avalon/merlin/bootstrap
BootstrapRuntimeException.java Merlin.java
package.html
Log:
Updates to eliminate dependency on extension directories during bootstrap enabling support for java WebStart.
Revision Changes Path
1.8 +58 -14 avalon-sandbox/merlin/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/build.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- build.xml 27 Dec 2002 16:35:42 -0000 1.7
+++ build.xml 6 Jan 2003 01:05:53 -0000 1.8
@@ -49,7 +49,7 @@
<pathelement location="${build.testclasses}"/>
</path>
- <target name="main" depends="jar,jar-playground" description="Build the project"/>
+ <target name="main" depends="jar,jar-playground,deploy" description="Build the project"/>
<target name="rebuild" depends="clean,main" description="Rebuild the project"/>
<target name="all" depends="rebuild,docs" description="Rebuild the project"/>
@@ -92,6 +92,18 @@
</uptodate>
</target>
+ <target name="context-bootstrap">
+ <mkdir dir="${lib.dir}"/>
+ <uptodate property="uptodate-bootstrap" targetfile="${build.lib}/${bootstrap.jar}">
+ <srcfiles dir="${src.dir}">
+ <include name="**/bootstrap/**/*.*"/>
+ </srcfiles>
+ <srcfiles dir="${lib.dir}">
+ <include name="**/*.*"/>
+ </srcfiles>
+ </uptodate>
+ </target>
+
<!-- Compiles the source code -->
<target name="compile" depends="context,dependencies"
description="Compiles the source code" unless="uptodate">
@@ -110,6 +122,7 @@
<src path="${java.dir}" />
<classpath refid="project.class.path" />
<exclude name="**/playground/**/*.java"/>
+ <exclude name="**/bootstrap/**/*.java"/>
<include name="**/*.java"/>
</javac>
@@ -124,8 +137,29 @@
</target>
- <!-- Creates all the .jar file -->
- <target name="jar" depends="compile, deploy" description="Generates the jar files" unless="uptodate">
+ <!-- Compiles the bootstrap source code -->
+ <target name="compile-bootstrap" depends="context-bootstrap"
+ description="Compiles the bootstrap source code" unless="uptodate-bootstrap">
+
+ <echo message="compiling bootstrap"/>
+ <mkdir dir="${build.bootstrap}"/>
+
+ <javac srcdir="${java.dir}"
+ destdir="${build.bootstrap}"
+ debug="${build.debug}"
+ optimize="${build.optimize}"
+ deprecation="${build.deprecation}"
+ target="1.2">
+ <src path="${java.dir}" />
+ <include name="**/bootstrap/**/*.java"/>
+ </javac>
+
+ </target>
+
+ <!-- Creates the merlin jar files -->
+ <target name="jar" depends="merlin.jar,bootstrap.jar" description="Generates the jar files"/>
+
+ <target name="merlin.jar" depends="compile" description="Generates the merlin jar file" unless="uptodate">
<mkdir dir="${build.conf}"/>
<copy todir="${build.conf}" flatten="true">
@@ -153,25 +187,28 @@
<include name="kernel.xml"/>
</zipfileset>
</jar>
+
+ </target>
+
+ <target name="bootstrap.jar" depends="compile-bootstrap" description="Generates the jar files" unless="uptodate-bootstrap">
+ <mkdir dir="${build.lib}"/>
+ <jar jarfile="${build.lib}/${bootstrap.jar}"
+ basedir="${build.bootstrap}"
+ compress="${build.compress}" >
+ </jar>
</target>
- <target name="deploy">
+ <target name="deploy" depends="jar">
<mkdir dir="${common.dir}"/>
<copy todir="${common.dir}" file="${avalon-framework.jar}"/>
- <copy todir="${common.dir}" file="${avalon-meta.jar}"/>
- <copy todir="${common.dir}" file="${excalibur-configuration.jar}"/>
<copy todir="${common.dir}" file="${excalibur-i18n.jar}"/>
- <copy todir="${common.dir}" preservelastmodified="true">
- <fileset dir="${tools.dir}/lib">
- <include name="xerces-2.0.1.jar"/>
- <include name="xml-apis.jar"/>
- <include name="xalan-2.3.1.jar"/>
- </fileset>
- </copy>
+ <copy todir="${common.dir}" file="${excalibur-configuration.jar}"/>
+ <copy todir="${common.dir}" file="${avalon-meta.jar}"/>
+ <copy todir="${common.dir}" file="${logkit.jar}"/>
<mkdir dir="${lib.dir}"/>
- <copy todir="${lib.dir}" file="${logkit.jar}"/>
+ <copy todir="${lib.dir}" file="${build.lib}/${jar.name}"/>
<copy todir="${lib.dir}" file="${excalibur-extension.jar}"/>
<copy todir="${lib.dir}" file="${excalibur-logger.jar}"/>
<copy todir="${lib.dir}" file="${excalibur-event.jar}"/>
@@ -180,6 +217,13 @@
<copy todir="${lib.dir}" file="${excalibur-thread.jar}"/>
<copy todir="${lib.dir}" file="${avalon-lifecycle.jar}"/>
<copy todir="${lib.dir}" file="${avalon-assembly.jar}"/>
+ <copy todir="${lib.dir}" preservelastmodified="true">
+ <fileset dir="${tools.dir}/lib">
+ <include name="xerces-2.0.1.jar"/>
+ <include name="xml-apis.jar"/>
+ <include name="xalan-2.3.1.jar"/>
+ </fileset>
+ </copy>
</target>
1.5 +2 -0 avalon-sandbox/merlin/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/default.properties,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- default.properties 11 Dec 2002 02:53:40 -0000 1.4
+++ default.properties 6 Jan 2003 01:05:53 -0000 1.5
@@ -93,6 +93,7 @@
# location of intermediate products
build.dir = build
build.testsrc = ${build.dir}/testsrc
+build.bootstrap = ${build.dir}/bootstrap
build.playground = ${build.dir}/playground
build.testclasses = ${build.dir}/testclasses
build.lib = ${build.dir}/lib
@@ -123,6 +124,7 @@
# name of jar file
jar.name = ${name}-${version}.jar
+bootstrap.jar = ${name}-bootstrap-${version}.jar
# property indicating directory where all distribution archives are placed
dist.base = distributions
1.1 avalon-sandbox/merlin/merlin.properties
Index: merlin.properties
===================================================================
# -------------------------------------------------------------------
# MERLIN PROPERTIES
# -------------------------------------------------------------------
# Specifies the default location of the directories containing the Merlin
# container libraries and common libraries, and the default block
# configuration file.
#
#
# merlin.home.path
# Declaration of the default working directory. The default working
# directory is a file resolved from the System property "user.dir".
#
#merlin.home.path=D:\merlin
#
# merlin.library.path
# Contains a path declaration relative to the merlin home directory.
# The lib path refers to the a directory containing the set of internal
# Merlin jar files. The default value is [lib]
#
#merlin.lib.path=lib
#
# merlin.common.path
# Contains a path declaration relative to the merlin home directory.
# The common path refers to a directory containing the set of shared jar
# files. The default value is [common].
#
#merlin.common.path=common
#
# merlin.blocks.xml
# Filename of the blocks configuration. The file will be resolved relative
# to the Merlin home directory. The default value is [blocks.xml]
#
#merlin.blocks.xml=blocks.xml
#
# merlin.bootstrap.debug
# If true, debug messages occuring the bootstrap phase (prior to the establishement
# of a logger) will be sent to System.out. If false, not bootstrap messages will
# be displayed. Default value is false.
#
#merlin.bootstrap.debug=false
1.6 +124 -34 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/Main.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Main.java 27 Dec 2002 16:37:10 -0000 1.5
+++ Main.java 6 Jan 2003 01:05:53 -0000 1.6
@@ -45,13 +45,11 @@
{
/**
* Command line entry point to the Merlin system.
- * The main method handles the establishment of a root {@link Kernel}
- * and the supply to the kernel of working directory derived from the
- * command line argument.
+ * The main method handles the establishment of a bootstrap classloader,
+ * installation directory and base working directory from which a root
+ * {@link Kernel} is instantiated.
*
- * @param args a set command line arguments - currently the first value
- * contains the filename of working directory from which the kernel
- * and block configuration are resolved.
+ * @param args a set command line arguments
* @see DefaultKernel
*/
public static void main( String[] args )
@@ -63,22 +61,24 @@
private Main( String[] args )
{
- File base;
- try
- {
- base = getBaseDirectory( args );
- }
- catch( Throwable e )
- {
- System.err.println( "\n " + e.getMessage() + "\n" );
- return;
- }
- if( !base.exists() )
- {
- final String error =
- "Supplied base directory does not exist: " + base;
- throw new RuntimeException( error );
- }
+ //
+ // setup the default filename for the base directory
+ // (the deployment directory that should contain a kernel.xml file)
+ //
+
+ File base = getBaseDirectory( args );
+
+ //
+ // setup the default filename for the system directory
+ // (the system directory that should contain a common and lib directory)
+ //
+
+ File sys = getSystemDirectory( base, args );
+
+ //
+ // create the bootstrap classloader
+ //
+
m_kernel = new DefaultKernel();
@@ -149,12 +149,14 @@
}
/**
- * Get the base directory.
+ * Get the base directory. If the base directory is not qualified using the -base
+ * command line argument, the "user.dir" is implied.
+ *
* @param args the command line arguments
+ * @exception RuntimeException if the base deployment directory cannot be resolved
*/
- private File getBaseDirectory( String[] args ) throws IOException
+ private File getBaseDirectory( String[] args ) throws RuntimeException
{
- File base = new File( System.getProperty( "user.dir" ) );
String filename;
if( args.length > 0 )
{
@@ -162,30 +164,118 @@
}
else
{
- filename = ".";
+ filename = System.getProperty( "user.dir" );
}
- File result = new File( base, filename );
- if( result.isFile() )
+ String basename = getValue( args, "-deployment", filename );
+ File base = new File( basename );
+ System.out.println( "base: " + base );
+ if( base.isFile() )
{
- result = result.getParentFile();
+ base = base.getParentFile();
}
- if( !result.exists() )
+ if( !base.exists() )
{
final String error =
- "Supplied path does not refer to a directory: ";
+ "Supplied path does not exist: ";
String message;
try
{
- message = error + result.getCanonicalFile();
+ message = error + base.getCanonicalFile();
}
catch( Throwable e )
{
message = error + filename;
}
- throw new IOException( message );
+ throw new RuntimeException( message );
}
- return result.getCanonicalFile();
+ try
+ {
+ return base.getCanonicalFile();
+ }
+ catch( Throwable e )
+ {
+ final String error = e.toString();
+ final String message = error + " file: " + filename;
+ throw new RuntimeException( message );
+ }
+ }
+
+ /**
+ * Get the base directory. If the base directory is not qualified using the -base
+ * command line argument, the "user.dir" is implied.
+ *
+ * @param args the command line arguments
+ * @exception RuntimeException if the base deployment directory cannot be resolved
+ */
+ private File getSystemDirectory( File base, String[] args ) throws RuntimeException
+ {
+ //
+ // setup the default filename for the system directory
+ // (the system directory that should contain a common and lib directories)
+ //
+
+ String name = getValue( args, "-system", base.toString() );
+ File sys = new File( name );
+ System.out.println( "sys: " + sys );
+ if( sys.isFile() )
+ {
+ sys = sys.getParentFile();
+ }
+
+ if( !sys.exists() )
+ {
+ final String error =
+ "Supplied system path does not exist: ";
+ String message;
+ try
+ {
+ message = error + sys.getCanonicalFile();
+ }
+ catch( Throwable e )
+ {
+ message = error + name;
+ }
+ throw new RuntimeException( message );
+ }
+
+ File common = new File( sys, "common" );
+ if( !common.exists() )
+ {
+ final String error = "System directory " + sys + " does not contain a 'common' directory.";
+ throw new RuntimeException( error );
+ }
+
+ File lib = new File( sys, "lib" );
+ if( !lib.exists() )
+ {
+ final String error = "System directory " + sys + " does not contain a 'lib' directory.";
+ throw new RuntimeException( error );
+ }
+
+ try
+ {
+ return sys.getCanonicalFile();
+ }
+ catch( Throwable e )
+ {
+ final String error = e.toString();
+ final String message = error + " file: " + name;
+ throw new RuntimeException( message );
+ }
+ }
+
+ private static String getValue( String[] args, String key, String defaultValue )
+ {
+ for( int i=0; i<args.length; i++ )
+ {
+ String s = args[i];
+ if( s.startsWith( key ) && ( args.length > i+1 ) )
+ {
+ return args[ i+1 ];
+ }
+ }
+ return defaultValue;
}
}
1.1 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/bootstrap/BootstrapRuntimeException.java
Index: BootstrapRuntimeException.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.merlin.bootstrap;
/**
* Exception to indicate that there was a bootstrap related runtime error.
*
* @author <a href="mailto:avalon-dev@jakarta.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/01/06 01:05:53 $
*/
public final class BootstrapRuntimeException
extends RuntimeException
{
private Throwable m_cause;
private String[] m_actions = new String[0];
/**
* Construct a new <code>BootstrapRuntimeException</code> instance.
*
* @param message The detail message for this exception.
*/
public BootstrapRuntimeException( final String message )
{
this( message, (String) null, (Throwable) null );
}
/**
* Construct a new <code>BootstrapRuntimeException</code> instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public BootstrapRuntimeException( final String message, final Throwable throwable )
{
this( message, (String) null, throwable );
}
/**
* Construct a new <code>BootstrapRuntimeException</code> instance.
*
* @param message The detail message for this exception.
* @param action recommended action
*/
public BootstrapRuntimeException( final String message, String action )
{
this( message, action, null );
}
/**
* Construct a new <code>BootstrapRuntimeException</code> instance.
*
* @param message The detail message for this exception.
* @param action recommended action
* @param throwable the root cause of the exception
*/
public BootstrapRuntimeException( final String message, String action, final Throwable throwable )
{
this( message, new String[]{ action }, null );
}
/**
* Construct a new <code>BootstrapRuntimeException</code> instance.
*
* @param message The detail message for this exception.
* @param action recommended action
* @param throwable the root cause of the exception
*/
public BootstrapRuntimeException( final String message, String[] actions, final Throwable throwable )
{
super( message );
m_cause = throwable;
m_actions = actions;
}
/**
* Returns the cause of the error.
* @return the causal exception
*/
public Throwable getCause()
{
return m_cause;
}
/**
* Returns the recommended corrective action pertaining to the error condition.
* @return the recommended corrective action.
*/
public String[] getActions()
{
return m_actions;
}
}
1.1 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/bootstrap/Merlin.java
Index: Merlin.java
===================================================================
package org.apache.avalon.merlin.bootstrap;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import java.util.List;
import java.util.ArrayList;
import java.net.URL;
import java.net.URLClassLoader;
import java.lang.reflect.Constructor;
/**
* Merlin commandline bootstrap handler.
* @see DefaultKernel
*/
public class Merlin
{
//--------------------------------------------------------------------------
// static
//--------------------------------------------------------------------------
public static final String MERLIN_PROPS_BASEDIR = System.getProperty( "user.dir" );
public static final String MERLIN_PROPS_FILENAME = "merlin.properties";
public static final String MERLIN_LIB_PATH = "lib";
public static final String MERLIN_COMMON_PATH = "common";
public static final String MERLIN_BLOCKS_FILENAME = "blocks.xml";
public static final String MERLIN_KERNEL_LOADER_CLASSNAME = "org.apache.avalon.merlin.kernel.KernelLoader";
public static final String MERLIN_PROPS_PATH =
MERLIN_PROPS_BASEDIR + File.separator
+ MERLIN_PROPS_FILENAME;
private static final Properties DEFAULT_PROPERTIES = new Properties();
static
{
DEFAULT_PROPERTIES.setProperty( "merlin.base.path", MERLIN_PROPS_BASEDIR );
DEFAULT_PROPERTIES.setProperty( "merlin.lib.path", MERLIN_LIB_PATH );
DEFAULT_PROPERTIES.setProperty( "merlin.common.path", MERLIN_COMMON_PATH );
}
//--------------------------------------------------------------------------
// state
//--------------------------------------------------------------------------
private boolean m_debug;
private Properties m_properties;
/**
* Command line entry point to the Merlin system.
* The main method handles the establishment of a bootstrap classloader,
* installation directory and base working directory from which a root
* {@link Kernel} is instantiated.
*
* @param args a set command line arguments
* @see DefaultKernel
*/
public static void main( String[] args )
{
Merlin main = new Merlin( args );
}
private Merlin( String[] args )
{
File base = null;
File lib = null;
File common = null;
File blocks = null;
Properties props = null;
boolean trace = false;
try
{
props = getProperties( args );
base = getBasePath( props );
lib = getLibraryPath( base, props );
common = getCommonPath( base, props );
blocks = getBlocksPath( base, props );
trace = getTraceMode( props );
}
catch( BootstrapRuntimeException e )
{
final String error =
"\n\tBootstrap failure.";
System.out.println( error );
if( e.getMessage() != null )
{
System.err.println( "\tMESSAGE: " + e.getMessage() );
}
if( e.getCause() != null )
{
System.err.println( "\tCAUSE: " + e.getCause() );
}
String[] actions = e.getActions();
for( int i=0; i<actions.length; i++ )
{
System.err.println( "\tRECOMMENDATION: " + actions[i] );
}
System.exit( 1 );
}
catch( Throwable e )
{
final String error =
"\n\tBootstrap failure.";
e.printStackTrace();
}
if( trace )
{
System.out.println("\n\tPROPS: " + props );
System.out.println("\tBASE: " + base );
System.out.println("\tLIB: " + lib );
System.out.println("\tCOMMON: " + common );
System.out.println("\tBLOCKS: " + blocks );
}
//
// get the list of common jar files and create the
// context classloader
//
URL[] urls = getJarFiles( common );
URLClassLoader context = new URLClassLoader( urls );
Thread.currentThread().setContextClassLoader( context );
if( trace )
{
System.out.println("\tCOMMON LOADER: " + context );
System.out.println("\tURLS\n" );
}
URL[] targets = context.getURLs();
for( int i=0; i<targets.length; i++ )
{
if( trace )
{
System.out.println("\t " + targets[i] );
}
}
//
// get the list of container jar files and setup container classloader
//
List list = new ArrayList();
urls = getJarFiles( lib );
URLClassLoader internal = new URLClassLoader( urls, context );
if( trace )
{
System.out.println("\n\tCONTAINER LOADER: " + internal );
System.out.println("\tURLS:\n" );
}
targets = internal.getURLs();
for( int i=0; i<targets.length; i++ )
{
if( trace )
{
System.out.println("\t " + targets[i] );
}
}
if( trace )
{
System.out.println("\n" );
}
//
// create a kernel loader
//
Object kernelLoader = null;
Class clazz;
try
{
clazz = internal.loadClass( MERLIN_KERNEL_LOADER_CLASSNAME );
}
catch( Throwable e )
{
final String error =
"Internal error during loader class creation.";
throw new BootstrapRuntimeException( error, e );
}
try
{
Constructor constructor = clazz.getConstructor(
new Class[]{ClassLoader.class, File.class} );
kernelLoader = constructor.newInstance( new Object[]{ internal, base } );
}
catch( Throwable e )
{
final String error =
"Internal error during loader instantiation.";
throw new BootstrapRuntimeException( error, e );
}
}
private URL[] getJarFiles( File base )
{
List list = new ArrayList();
populateJars( list, base );
return (URL[]) list.toArray( new URL[0] );
}
private void populateJars( List list, File base )
{
try
{
File[] files = base.listFiles();
for( int i=0; i<files.length; i++ )
{
File file = files[i];
if( file.getName().endsWith( ".jar" ) )
{
list.add( file.toURL() );
}
}
}
catch( Throwable e )
{
final String error =
"Unexpected error while scanning files in common directory: " + base;
throw new BootstrapRuntimeException( error, e );
}
}
private boolean getTraceMode( Properties props )
{
return props.getProperty( "merlin.bootstrap.debug", "false" ).equals( "true" );
}
private File getBasePath( Properties props )
{
File base = new File( props.getProperty( "merlin.base.path" ) );
if( !base.exists() )
{
final String error =
"Unable to locate the merlin base directory from the path: "
+ packFile( base );
throw new BootstrapRuntimeException( error );
}
if( !base.isDirectory() )
{
final String error =
"Base directory is not a directory: "
+ packFile( base );
throw new BootstrapRuntimeException( error );
}
return packFile( base );
}
private File getLibraryPath( File base, Properties props )
{
String filename = props.getProperty( "merlin.lib.path" );
File file = new File( base, filename );
if( !file.exists() )
{
final String error =
"Library directory [" + filename
+ "] does not exist within the base directory: "
+ base;
final String action =
"Check the bootstrap property value for 'merlin.lib.path'.";
throw new BootstrapRuntimeException( error, action );
}
return packFile( file );
}
private File getCommonPath( File base, Properties props )
{
File file = new File( base, props.getProperty("merlin.common.path") );
if( !file.isDirectory() )
{
final String error =
"Merlin common directory is not a directory: "
+ packFile( file );
final String action =
"Check the bootstrap property value for 'merlin.common.path'.";
throw new BootstrapRuntimeException( error, action );
}
return packFile( file );
}
private File getBlocksPath( File base, Properties props )
{
String path = props.getProperty( "merlin.blocks.xml", null ) ;
if( path == null )
{
return new File( base, MERLIN_BLOCKS_FILENAME );
}
else
{
File file = new File( base, path );
if( !file.isFile() )
{
final String error =
"Block configuration is not a file: "
+ packFile( file );
final String action1 =
"Check the bootstrap property value for 'merlin.common.path'.";
final String action2 =
"Make sure the filename is correct.";
final String action3 =
"Make sure the blocks configuration file exists.";
final String[] actions =
new String[]{ action1, action2, action3 };
throw new BootstrapRuntimeException( error, actions, null );
}
return packFile( file );
}
}
/**
* Get the runtime properties.
*
* @param args the command line arguments
* @exception BootstrapRuntimeException if the supplied arguments are inconsistent
*/
private Properties getProperties( String[] args ) throws BootstrapRuntimeException
{
String filename;
File file;
if( args.length > 0 )
{
filename = args[ 0 ];
file = new File( filename );
if( !file.isAbsolute() )
{
File base = new File( MERLIN_PROPS_BASEDIR );
file = new File( base, filename );
}
if( !file.exists() )
{
final String error =
"Unable to locate merlin properties from the path: "
+ packFile( file );
final String action1 =
"Check the bootstrap property value for 'merlin.home.path'.";
final String action2 =
"Check that supplied property file argument refers to an existing file.";
throw new BootstrapRuntimeException( error, new String[]{ action1, action2 }, null );
}
if( file.isDirectory() )
{
file = new File( file, MERLIN_PROPS_FILENAME );
Properties props = new Properties( DEFAULT_PROPERTIES );
props.setProperty( "merlin.base.path", filename );
return props;
}
if( !file.canRead() )
{
final String error =
"Unable to read merlin properties from the file: "
+ packFile( file );
final String action =
"Check access permission of the property file or parent directories.";
throw new BootstrapRuntimeException( error, action );
}
try
{
FileInputStream input = new FileInputStream( file );
Properties props = new Properties( DEFAULT_PROPERTIES );
props.load( input );
return props;
}
catch( Throwable e )
{
final String error =
"Unable to load properties from file: "
+ packFile( file );
throw new BootstrapRuntimeException( error, e );
}
}
else
{
return DEFAULT_PROPERTIES;
}
}
private File packFile( File file )
{
try
{
return file.getCanonicalFile( );
}
catch( Throwable e )
{
return file;
}
}
}
1.1 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/bootstrap/package.html
Index: package.html
===================================================================
<body>
Classes support the bootstrapping of a kernel.
</body>
1.19 +11 -4 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.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- DefaultKernel.java 28 Dec 2002 08:06:43 -0000 1.18
+++ DefaultKernel.java 6 Jan 2003 01:05:53 -0000 1.19
@@ -196,6 +196,11 @@
private Logger m_local;
/**
+ * The bootstrap classloader.
+ */
+ private ClassLoader m_bootstrap;
+
+ /**
* The assembly engine.
*/
private EngineClassLoader m_engine;
@@ -241,6 +246,7 @@
public void contextualize( Context context ) throws ContextException
{
m_home = (File) context.get( "urn:assembly:home" );
+ m_bootstrap = (ClassLoader) context.get( "urn:avalon:classloader" );
}
//==============================================================
@@ -255,7 +261,7 @@
*
* @exception Exception if an initialization error occurs.
*/
- public void initialize() throws Exception
+ public void initialize() throws Exception
{
if( m_home == null )
{
@@ -897,7 +903,8 @@
}
}
- private EngineClassLoader bootstrapEngine( LoggingManager logging, Configuration config )
+ private EngineClassLoader bootstrapEngine(
+ LoggingManager logging, Configuration config )
throws Exception
{
if( m_home == null )
@@ -927,7 +934,7 @@
try
{
- EngineClassLoader engine = new EngineClassLoader();
+ EngineClassLoader engine = new EngineClassLoader( m_bootstrap );
engine.enableLogging( getLogger().getChildLogger( "engine" ) );
engine.configure( config );
Context system = getSystemContext();
1.3 +2 -1 avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.xinfo
Index: DefaultKernel.xinfo
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/src/java/org/apache/avalon/merlin/kernel/DefaultKernel.xinfo,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultKernel.xinfo 19 Dec 2002 10:50:17 -0000 1.2
+++ DefaultKernel.xinfo 6 Jan 2003 01:05:53 -0000 1.3
@@ -21,7 +21,8 @@
</info>
<context>
- <entry key="urn:assembly:home" type="java.io.File" optional="false"/>
+ <entry key="urn:assembly:home" type="java.io.File" />
+ <entry key="urn:avalon:classloader" type="java.lang.ClassLoader" />
</context>
<services>
1.5 +1 -1 avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardComponent.java
Index: StandardComponent.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/src/test/org/apache/avalon/playground/StandardComponent.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StandardComponent.java 27 Dec 2002 16:47:28 -0000 1.4
+++ StandardComponent.java 6 Jan 2003 01:05:53 -0000 1.5
@@ -165,7 +165,7 @@
public void printMessage()
{
getLogger().info( m_config.getChild("message").getValue("") );
- getLogger().info( "listing context" + m_message );
+ getLogger().info( "listing context\n" + m_message + "\n");
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>