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/09/14 15:11:35 UTC
cvs commit: avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl CLIKernelLoader.java DefaultKernel.java DefaultKernelContext.java Resources.properties
mcconnell 2003/09/14 06:11:35
Modified: merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl
CLIKernelLoader.java DefaultKernel.java
DefaultKernelContext.java Resources.properties
Log:
Update to kernel context and cli handler to support seperation of system and user repository.
Revision Changes Path
1.18 +59 -92 avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/CLIKernelLoader.java
Index: CLIKernelLoader.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/CLIKernelLoader.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- CLIKernelLoader.java 9 Sep 2003 14:59:30 -0000 1.17
+++ CLIKernelLoader.java 14 Sep 2003 13:11:34 -0000 1.18
@@ -28,6 +28,7 @@
import org.apache.avalon.merlin.kernel.KernelException;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
+import org.apache.avalon.repository.BlockManifest;
import org.apache.avalon.repository.Repository;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
@@ -55,8 +56,6 @@
private static final File HOME = new File( System.getProperty( "user.dir" ) );
- private static final File SYSTEM = getSystemDefaultDirectory();
-
private static Resources REZ =
ResourceManager.getPackageResources( CLIKernelLoader.class );
@@ -72,11 +71,11 @@
* line arguments, the repository established for runtime deployment
* may be changed.
*
- * @param repository the bootstrap repository from which merlin
+ * @param system the bootstrap repository from which merlin
* system jar files have been resolved
* @param args the set of command line arguments
*/
- public CLIKernelLoader( final Repository repository, String[] args )
+ public CLIKernelLoader( final Repository system, String[] args )
throws Exception
{
//
@@ -124,7 +123,7 @@
KernelContext context = null;
try
{
- context = createContext( repository, line );
+ context = createContext( system, line );
}
catch( FileNotFoundException e )
{
@@ -151,6 +150,33 @@
return;
}
+ //
+ // With the kernel context established we can now handle the
+ // the runtime objective. If the commandline contains the
+ // -install switch we use the repository established by the
+ // context to install a bar file, otherwise this is a normal
+ // runtime deployment scenario.
+ //
+
+ if( line.hasOption( "install" ) )
+ {
+ String path = line.getOptionValue( "install" );
+ Logger log = context.getKernelLogger().getChildLogger( "installer" );
+ URL url = resolveURL( path );
+ log.info( "installing: " + url );
+ StringBuffer buffer = new StringBuffer();
+ BlockManifest manifest = context.getRepository().install( url, buffer );
+ log.info( buffer.toString() );
+ return;
+ }
+
+ //
+ // This is a classic deployment scenario under which we are launching a
+ // kernel and processing executable block descriptors. Two approaches
+ // are provided, one is a direct instantiation of the kernel and the
+ // other is a jmx managed startup.
+ //
+
if( line.hasOption( "jmx" ) )
{
managedStartup( context );
@@ -276,11 +302,11 @@
/**
* Create the kernel context using the supplied command line arguments.
- * @param repository the bootstrap repository
+ * @param system the system repository
* @param args the command line arguments
* @return the kernel context
*/
- private KernelContext createContext( final Repository repository, CommandLine line )
+ private KernelContext createContext( final Repository system, CommandLine line )
throws Exception
{
File base = HOME;
@@ -342,14 +368,13 @@
// the kernel configuration (used by the kernel loader)
//
- URL kernel = kernel = getKernelPath( line );
+ URL kernel = getKernelPath( line );
//
- // get the system path for extension resolution
+ // get the system path
//
-
- File system = getSystemPath( line );
+ File repository = getUserRepositoryPath( line );
//
// get the library path
@@ -376,7 +401,7 @@
try
{
return new DefaultKernelContext(
- repository, system, library, home, kernel,
+ system, repository, library, home, kernel,
blocks, config, server, info, debug );
}
catch( KernelException e )
@@ -489,8 +514,7 @@
private static void doHelp()
{
HelpFormatter formatter = new HelpFormatter();
- final String description = REZ.getString( "cli-description" );
- formatter.printHelp( "merlin [block]", description, CL_OPTIONS, "", true );
+ formatter.printHelp( "merlin [block]", " ", CL_OPTIONS, "", true );
}
/**
@@ -540,73 +564,17 @@
private File getLibraryPath( CommandLine command, File system ) throws IOException
{
final String key = "library";
- if( command.hasOption( key ) )
- {
- String path = command.getOptionValue( key );
- try
- {
- return getFile( system, path );
- }
- catch( FileNotFoundException fnfe )
- {
- final String error =
- "Supplied library path does not exist: " + path;
- throw new FileNotFoundException( error );
- }
- }
- else
- {
- return system;
- }
- }
-
- private File getSystemPath( CommandLine command ) throws IOException
- {
- File file = getSysPath( command );
- if( file == null )
- {
- return null;
- }
- else
- {
- if( !file.exists() )
- {
- final String error =
- "Supplied system path does not exist: " + file;
- throw new IllegalArgumentException( error );
- }
- if( !file.isDirectory() )
- {
- final String error =
- "Supplied system path does not refer to a directory: " + file;
- throw new IllegalArgumentException( error );
- }
- return file;
- }
+ if( !command.hasOption( key ) ) return null;
+ final String path = command.getOptionValue( key );
+ return getFile( HOME, path );
}
- private File getSysPath( CommandLine command ) throws IOException
+ private File getUserRepositoryPath( CommandLine command ) throws IOException
{
- String path = null;
- final String key = "system";
- if( command.hasOption( key ) )
- {
- path = command.getOptionValue( key );
- try
- {
- return getFile( SYSTEM, path );
- }
- catch( FileNotFoundException fnfe )
- {
- final String error =
- "Supplied home path does not exist: " + path;
- throw new FileNotFoundException( error );
- }
- }
- else
- {
- return null;
- }
+ final String key = "repository";
+ if( !command.hasOption( key ) ) return null;
+ final String path = command.getOptionValue( key );
+ return getFile( HOME, path );
}
private File getFile( File base, String path ) throws IOException
@@ -671,11 +639,11 @@
.withDescription( REZ.getString( "cli-home-description" ) )
.create( "home" );
- Option sys = OptionBuilder
+ Option repository = OptionBuilder
.hasArg()
.withArgName( REZ.getString( "directory" ) )
- .withDescription( REZ.getString( "cli-system-description" ) )
- .create( "system" );
+ .withDescription( REZ.getString( "cli-repository-description" ) )
+ .create( "repository" );
Option library = OptionBuilder
.hasArg()
@@ -685,16 +653,22 @@
Option config = OptionBuilder
.hasArg()
- .withArgName( REZ.getString( "file" ) )
+ .withArgName( REZ.getString( "url" ) )
.withDescription( REZ.getString( "cli-config-description" ) )
.create( "config" );
Option kernel = OptionBuilder
.hasArg()
- .withArgName( REZ.getString( "file" ) )
+ .withArgName( REZ.getString( "url" ) )
.withDescription( REZ.getString( "cli-kernel-description" ) )
.create( "kernel" );
+ Option install = OptionBuilder
+ .hasArg()
+ .withArgName( REZ.getString( "url" ) )
+ .withDescription( REZ.getString( "cli-install-description" ) )
+ .create( "install" );
+
options.addOption( help );
options.addOption( locale );
options.addOption( execute );
@@ -702,19 +676,12 @@
options.addOption( info );
options.addOption( debug );
options.addOption( jmx );
+ options.addOption( install );
options.addOption( home );
- options.addOption( sys );
+ options.addOption( repository );
options.addOption( library );
options.addOption( config );
options.addOption( kernel );
return options;
- }
-
- private static File getSystemDefaultDirectory()
- {
- final String local =
- System.getProperty( "merlin.home",
- System.getProperty( "user.home" ) + "/.merlin" );
- return new File( local );
}
}
1.15 +2 -6 avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java
Index: DefaultKernel.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernel.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DefaultKernel.java 12 Sep 2003 21:10:55 -0000 1.14
+++ DefaultKernel.java 14 Sep 2003 13:11:34 -0000 1.15
@@ -336,11 +336,7 @@
*/
public String getRepositoryDirectoryPath()
{
- if( m_context.getRepositoryPath() != null )
- {
- return m_context.getRepositoryPath().toString();
- }
- return "";
+ return m_context.getRepository().getLocation();
}
/**
1.29 +97 -78 avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelContext.java
Index: DefaultKernelContext.java
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/DefaultKernelContext.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- DefaultKernelContext.java 12 Sep 2003 21:38:41 -0000 1.28
+++ DefaultKernelContext.java 14 Sep 2003 13:11:34 -0000 1.29
@@ -134,9 +134,9 @@
private final Repository m_repository;
/**
- * The library path
+ * The runtime user repository path
*/
- private final File m_system;
+ private final File m_user;
/**
* The library path
@@ -202,14 +202,16 @@
private final ContainmentContext m_root;
+ private final String m_bootstrap;
+
//--------------------------------------------------------------
// constructor
//--------------------------------------------------------------
/**
* Creation of a new default kernel context.
- * @param repository the bootstrap repository
- * @param system the parent directory of the runtime repository
+ * @param bootstrap the system repository
+ * @param user the user repository directory
* @param library directory against which extension jar
* directives shall be anchored
* @param home local working directory
@@ -223,14 +225,15 @@
* @exception KernelException if an error occurs during context creation
*/
public DefaultKernelContext(
- Repository repository, File system, File library, File home,
+ Repository bootstrap, File user, File library, File home,
URL kernel, URL[] blocks, URL config, boolean server, boolean info, boolean debug )
throws NullPointerException, KernelException
{
- if( repository == null ) throw new NullPointerException( "repository" );
+ if( bootstrap == null ) throw new NullPointerException( "bootstrap" );
- m_library = library;
- m_system = system;
+ m_bootstrap = bootstrap.getLocation();
+ m_temp = new File( System.getProperty( "java.io.tmpdir" ) );
+ final File base = new File( System.getProperty( "user.dir" ) );
if( home != null )
{
@@ -238,20 +241,44 @@
}
else
{
- final File base = new File( System.getProperty( "user.dir" ) );
m_home = new File( base, "home" );
}
- m_temp = new File( System.getProperty( "java.io.tmpdir" ) );
+ if( library != null )
+ {
+ m_library = library;
+ }
+ else
+ {
+ m_library = base;
+ }
+
+ if( user != null )
+ {
+ m_user = user;
+ }
+ else
+ {
+ m_user = getMerlinLocalRepositoryDirectory();
+ }
Configuration kernelConfig = null;
if( kernel != null )
{
+
+ //
+ // a kernel defintion has been supplied
+ //
+
m_kernelURL = kernel.toString();
kernelConfig = getKernelConfiguration( kernel );
}
else
{
+ //
+ // use the kernel.xml file in ${merlin.home}/config/kernel.xml
+ //
+
String kernelURL = null;
File standard = new File( getMerlinHomeDirectory(), "config/kernel.xml" );
if( standard.exists() )
@@ -270,14 +297,24 @@
}
else
{
+ //
+ // umm, making things hard for us - try a locate a kernel from
+ // system repository
+ //
+
try
{
- URL url = loadKernelDirective( repository );
+ URL url = loadKernelDirective( bootstrap );
kernelURL = url.toString();
kernelConfig = getKernelConfiguration( url );
}
catch( Throwable e )
{
+ //
+ // last resort - get the static default from the
+ // jar file
+ //
+
kernelURL = "resource:/kernel.xml";
try
{
@@ -328,45 +365,29 @@
getLogger().debug( "logging system established" );
//
- // if the debug flag is enabled then print the context object
+ // if the kernel configuration declares a repository then we build
+ // a repository based on that defintion otherwise we default to the
+ // standard user repository
//
- if( info )
- {
- System.out.println( "\n" + toString() + "\n" );
- }
+ Configuration repositoryConfig = kernelConfig.getChild( "repository" );
+ m_repository = createRepository( m_user, repositoryConfig );
+ getLogger().debug( "repository established: " + m_repository.getLocation() );
//
- // if the kernel configuration declares a repository then we build
- // a repository based on that defintion otherwise we default to the
- // bootstrap repository declared under the constructor
+ // if the debug flag is enabled then print the context object
//
- if( system != null )
- {
- Configuration repositoryConfig = kernelConfig.getChild( "repository" );
- m_repository = createRepository( system, repositoryConfig );
- getLogger().debug( "repository established" );
- }
- else
+ if( info )
{
- if( kernelConfig.getChild( "repository", false ) != null )
- {
- File repo = getSystemDefaultDirectory();
- Configuration repositoryConfig = kernelConfig.getChild( "repository" );
- getLogger().debug( "using kernel defined repository" );
- m_repository = createRepository( repo, repositoryConfig );
- }
- else
- {
- m_repository = repository;
- }
+ System.out.println( "\n" + this.toString() + "\n" );
}
//
// setup the pool manager
// TODO: an implementation following more thinking (pools should
// probably be declared at the component directive level)
+ //
m_pool = null;
@@ -421,12 +442,12 @@
if( cache != null )
{
base = new File( cache );
- getLogger().debug( "setting repository cache: " + base );
+ getLogger().debug( "setting runtime repository cache: " + base );
}
else
{
- base = new File( root, "repository" );
- getLogger().debug( "setting repository to: " + base );
+ base = root;
+ getLogger().debug( "setting runtime repository to: " + base );
}
if( !base.exists() ) base.mkdirs();
@@ -451,7 +472,7 @@
final String warning =
"\n#"
+ "\n# WARNING:" + path
- + "\n# Your kernel file is using a depricated <host> format. "
+ + "\n# The kernel file is using a depricated <host> format. "
+ "\n# Please replace all <host>...</host> references "
+ "\n# with <host path=\"...\"/>."
+ "\n#"
@@ -565,7 +586,7 @@
}
/**
- * Return the bootstrap repository.
+ * Return the runtime repository.
* @return the repository
*/
public Repository getRepository()
@@ -676,16 +697,9 @@
* Return the runtime repository directory.
* @return the repository path
*/
- public File getRepositoryPath()
+ public String getBootstrapRepositoryPath()
{
- if( m_system != null )
- {
- return m_system;
- }
- else
- {
- return getSystemDefaultDirectory();
- }
+ return m_bootstrap;
}
//--------------------------------------------------------------
@@ -703,15 +717,8 @@
+ System.getProperty( "os.version" ) + " Java "
+ System.getProperty( "java.version" ) );
buffer.append( "\n Deployment Home: " + StringHelper.toString( getHomePath() ) );
- buffer.append( "\n Runtime Repository: " );
- if( m_system != null )
- {
- buffer.append( m_system );
- }
- else
- {
- buffer.append( getSystemDefaultDirectory() );
- }
+ buffer.append( "\n System Repository: " + getBootstrapRepositoryPath() );
+ buffer.append( "\n Runtime Repository: " + getRepository().getLocation() );
buffer.append( "\n Library Anchor: " + StringHelper.toString( getLibraryPath() ) );
buffer.append( "\n Kernel Path: " + StringHelper.toString( m_kernelURL ) );
buffer.append( "\n Deployment Blocks: " + StringHelper.toString( m_blocks ) );
@@ -915,32 +922,44 @@
return repository.getArtifact( "merlin", "kernel", "", "xml" );
}
- private File getSystemDefaultDirectory()
+ /**
+ * If the user has declare a local repository then return that (based on the
+ * merlin.local.repository sytem property, otherwise return the merlin.home
+ * repository directory.
+ *
+ * @return the local repository directory
+ */
+ public static File getMerlinLocalRepositoryDirectory()
{
- final String local =
- System.getProperty(
- "merlin.repository.local",
- getMerlinHomeDirectory().toString() );
- return new File( local );
+ final String local = System.getProperty( "merlin.local.repository" );
+ if( local != null )
+ {
+ return new File( local );
+ }
+ else
+ {
+ return new File( getMerlinHomeDirectory(), "repository" );
+ }
}
- private File getMerlinHomeDirectory()
+ /**
+ * Return the merlin.home directory. If undefined, return the
+ * ${user.home}/.merlin directory.
+ *
+ * @return the merlin home directory
+ */
+ public static File getMerlinHomeDirectory()
{
- if( m_system == null )
+ final String home = System.getProperty( "merlin.home" );
+ if( home != null )
{
- return getDefaultMerlinHomeDirectory();
+ return new File( home );
}
else
{
- return m_system;
+ File root = new File( System.getProperty( "user.home" ) );
+ return new File( root, ".merlin" );
}
}
- private File getDefaultMerlinHomeDirectory()
- {
- final String local =
- System.getProperty( "merlin.home",
- System.getProperty( "user.home" ) + "/.merlin" );
- return new File( local );
- }
}
1.8 +4 -1 avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/avalon-sandbox/merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl/Resources.properties,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Resources.properties 7 Sep 2003 11:34:14 -0000 1.7
+++ Resources.properties 14 Sep 2003 13:11:35 -0000 1.8
@@ -1,3 +1,4 @@
+url=url
directory=directory
@@ -15,6 +16,8 @@
cli-jmx-description=Bootstrap Merlin under a JMX server.
+cli-install-description=Install a block archive into the local repository.
+
cli-debug-description=Enables debug mode.
cli-home-description=A relative or absolute path to a working home directory. If not suppled, the system will default to the current directory.
@@ -25,7 +28,7 @@
cli-config-description=The filename of the configuration target override.
-cli-system-description=An absolute or relative path to a repository parent directory.
+cli-repository-description=An absolute or relative path to a alternative runtime repository.
cli-library-description=A directory that serves as the anchor for relative library references.
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org