mcconnell 2003/08/18 08:11:33
Modified: merlin/kernel/impl/src/java/org/apache/avalon/merlin/kernel/impl
CLIKernelLoader.java DefaultKernelContext.java
Resources.properties
merlin/merlin-plugin/src/java/org/apache/avalon/merlin/tools
MerlinBean.java
Log:
Improvements to commandline handling.
Revision Changes Path
1.6 +148 -121
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CLIKernelLoader.java 18 Aug 2003 11:26:05 -0000 1.5
+++ CLIKernelLoader.java 18 Aug 2003 15:11:33 -0000 1.6
@@ -10,6 +10,7 @@
import java.io.InputStream;
import java.util.Map;
import java.util.Locale;
+import java.net.MalformedURLException;
import java.net.URL;
import org.apache.avalon.composition.util.ExceptionHelper;
@@ -61,11 +62,75 @@
//--------------------------------------------------------------------------
public CLIKernelLoader( final Repository repository, String[] args )
- throws KernelException
+ throws Exception
{
-
- KernelContext context = createContext( repository, args );
- if( context == null ) return;
+ //
+ // parse the commandline
+ //
+
+ CommandLineParser parser = new BasicParser();
+ CommandLine line = parser.parse( CL_OPTIONS, args );
+
+ //
+ // check for a language override fromm the commandline
+ // and reset the cache if needed
+ //
+
+ if( line.hasOption( "lang" ) )
+ {
+ ResourceManager.clearResourceCache();
+ String language = line.getOptionValue( "lang" );
+ Locale locale = new Locale( language, "" );
+
+ Locale.setDefault( locale );
+ REZ = ResourceManager.getPackageResources( CLIKernelLoader.class );
+ }
+
+ //
+ // check for quick exit commands - help and version and if
+ // present - print content and return
+ //
+
+ if( line.hasOption( "help" ) )
+ {
+ doHelp();
+ return;
+ }
+ else if( line.hasOption( "version" ) )
+ {
+ System.out.println( "Version: " + getVersionString() );
+ return;
+ }
+
+ //
+ // build the kernel context
+ //
+
+ KernelContext context = null;
+ try
+ {
+ context = createContext( repository, line );
+ }
+ catch( FileNotFoundException e )
+ {
+ System.out.println( "");
+ System.out.println( "FILE-NOT-FOUND: " + e.getMessage() );
+ System.out.println( "");
+ return;
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "\nInternal error while attempting to create kernel context.";
+ String msg =
+ ExceptionHelper.packException( error, e, context.getDebugFlag() );
+ System.err.println( msg );
+ return;
+ }
+
+ //
+ // if the debug flag is enabled then print the context object
+ //
if( context.getDebugFlag() )
{
@@ -74,6 +139,11 @@
System.out.println( "");
}
+ //
+ // ready to roll -
+ // create the kernel and set a shutdown hook
+ //
+
try
{
Kernel kernel = new DefaultKernel( context );
@@ -84,7 +154,7 @@
final String error =
"\nInternal error during kernel instantiation.";
String msg =
- ExceptionHelper.packException( error, e, true );
+ ExceptionHelper.packException( error, e, context.getDebugFlag() );
System.err.println( msg );
}
}
@@ -99,127 +169,104 @@
* @param args the command line arguments
* @return the kernel context
*/
- private KernelContext createContext( final Repository repository, String[] args
)
- throws KernelException
+ private KernelContext createContext( final Repository repository, CommandLine
line )
+ throws Exception
{
- CommandLineParser parser = new BasicParser();
- CommandLine line = null;
-
File base = HOME;
URL[] blocks = null;
- try
+ boolean server = !line.hasOption( "execute" );
+ String[] arguments = line.getArgs();
+ if( arguments.length == 0 )
{
- line = parser.parse( CL_OPTIONS, args );
-
- boolean server = !line.hasOption( "execute" );
-
- if( line.hasOption( "lang" ) )
- {
- //
- // reset the i18n cache and rebuild trhe command line options
- //
-
- ResourceManager.clearResourceCache();
- String language = line.getOptionValue( "lang" );
- Locale locale = new Locale( language, "" );
-
- Locale.setDefault( locale );
- REZ = ResourceManager.getPackageResources( CLIKernelLoader.class );
- CL_OPTIONS = buildCommandLineOptions();
- }
-
- if( line.hasOption( "help" ) )
+ if( !server )
{
- doHelp();
- return null;
- }
- else if( line.hasOption( "version" ) )
- {
- System.out.println( "Version: " + getVersionString() );
- return null;
- }
- else
- {
-
- String[] arguments = line.getArgs();
- if( arguments.length == 0 )
+ File target = new File( HOME, "block.xml" );
+ if( target.exists() )
{
- if( !server )
+ try
{
- File target = new File( HOME, "block.xml" );
- if( target.exists() )
- {
- blocks = new URL[]{ target.toURL() };
- }
- else
- {
- System.out.println( "\nFILE-NOT-FOUND: " + target );
- return null;
- }
+ blocks = new URL[]{ target.toURL() };
}
- else
+ catch( MalformedURLException mue )
{
- blocks = new URL[0];
+ final String error =
+ "Unable to establish url to target: " + target;
+ throw new KernelException( error, mue );
}
}
else
{
- blocks = new URL[ arguments.length ];
- for( int i=0; i<arguments.length; i++ )
- {
- String blockarg = arguments[i];
- URL url = getFile( HOME, blockarg ).toURL();
- blocks[i] = url;
- }
+ throw new FileNotFoundException( target.toString() );
+ }
+ }
+ else
+ {
+ blocks = new URL[0];
+ }
+ }
+ else
+ {
+ blocks = new URL[ arguments.length ];
+ for( int i=0; i<arguments.length; i++ )
+ {
+ String blockarg = arguments[i];
+ try
+ {
+ URL url = getFile( HOME, blockarg ).toURL();
+ blocks[i] = url;
+ }
+ catch( MalformedURLException mue )
+ {
+ final String error =
+ "Unable to establish url to target: " + blockarg;
+ throw new KernelException( error, mue );
}
}
+ }
- //
- // get the debug flag
- //
+ //
+ // get the debug flag
+ //
- boolean debug = line.hasOption( "debug" );
+ boolean debug = line.hasOption( "debug" );
- //
- // the kernel configuration (used by the kernel loader)
- //
+ //
+ // the kernel configuration (used by the kernel loader)
+ //
+
+ URL kernel = kernel = getKernelPath( repository, line );
- URL kernel = getKernelPath( repository, line );
+ //
+ // get the system path for extension resolution
+ //
- //
- // get the system path for extension resolution
- //
+ File system = getSystemPath( line );
- File system = getSystemPath( line );
+ //
+ // get the library path
+ //
- //
- // get the library path
- //
+ File library = getLibraryPath( line, system );
- File library = getLibraryPath( line, system );
+ //
+ // get the working home directory
+ //
- //
- // get the working home directory
- //
+ File home = getHomePath( line );
- File home = getHomePath( line );
+ //
+ // get the optional configuration override
+ //
- //
- // get the optional configuration override
- //
+ URL config = getConfigPath( line );
- URL config = getConfigPath( base.getParentFile(), line );
+ //
+ // create the kernel
+ //
- return new DefaultKernelContext(
+ return new DefaultKernelContext(
repository, system, library, home, kernel, blocks, config, server,
debug );
- }
- catch( Throwable e )
- {
- final String error =
- "Internal error during kernel context creation.";
- throw new KernelException( error, e );
- }
}
/**
@@ -286,18 +333,11 @@
* @param command the command line
* @return the target override configuration (possibly null)
*/
- private URL getConfigPath( File block, CommandLine command ) throws IOException
+ private URL getConfigPath( CommandLine command ) throws IOException
{
- String filename = null;
final String key = "config";
- if( command.hasOption( key ) )
- {
- filename = command.getOptionValue( key );
- }
- else
- {
- filename = "config.xml";
- }
+ if( !command.hasOption( key ) ) return null;
+ String filename = command.getOptionValue( key );
File file = getFile( HOME, filename );
if( file.exists() )
{
@@ -305,15 +345,7 @@
}
else
{
- File config = new File( block, "config.xml" );
- if( config.exists() )
- {
- return config.toURL();
- }
- else
- {
- return null;
- }
+ throw new FileNotFoundException( file.toString() );
}
}
@@ -479,10 +511,6 @@
"execute",
REZ.getString( "cli-execute-description" ) );
- Option server = new Option(
- "server",
- REZ.getString( "cli-server-description" ) );
-
Option debug = new Option(
"debug",
REZ.getString( "cli-debug-description" ) );
@@ -524,8 +552,8 @@
.create( "kernel" );
options.addOption( help );
+ options.addOption( locale );
options.addOption( execute );
- options.addOption( server );
options.addOption( version );
options.addOption( debug );
options.addOption( home );
@@ -533,7 +561,6 @@
options.addOption( library );
options.addOption( config );
options.addOption( kernel );
- options.addOption( locale );
return options;
}
1.8 +3 -5
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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultKernelContext.java 18 Aug 2003 11:26:05 -0000 1.7
+++ DefaultKernelContext.java 18 Aug 2003 15:11:33 -0000 1.8
@@ -195,14 +195,12 @@
/**
* Creation of a new default kernel context.
* @param repository the bootstrap repository
- * @param install the merlin install directory
* @param system the parent directory of the runtime repository
* @param library directory against which extension jar
- * directives are resolved
+ * directives shall be anchored
* @param home local working directory
* @param kernel the kernel configuration URL - if null, the
- * default kernel repository will be loaded from the supplied
- * repository
+ * default kernel profile will be loaded from the bootstrap repository
* @param blocks a sequence of block urls
* @param config a url to a configuration override descriptor
* @param server server mode flag
1.4 +8 -10
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Resources.properties 17 Aug 2003 15:06:41 -0000 1.3
+++ Resources.properties 18 Aug 2003 15:11:33 -0000 1.4
@@ -9,25 +9,23 @@
cli-execute-description=If present the kernel will initiate shutdown immediately
following deployment.
-cli-server-description=Overrides the default execute flag.
+cli-version-description=Prints version information.
-cli-version-description=Lists Merlin version information.
+cli-debug-description=Enables debug mode.
-cli-debug-description=Enable debug messages during the bootstrap phase.
+cli-home-description=A relative or absolute path to a working home directory. If
not suppled, the system will default to the current directory.
-cli-home-description=A relative or absolute path to a working home directory. If
not suppled, the system will default to the current directory. If the resolved home
path does not exist it will be created.
+cli-kernel-description=The filename of a custom kernel profile.
-cli-kernel-description=The filename of the kernel configuration. The value
defaults to the system kernel.xml file.
+cli-block-description=An absolute or relative filename of a block descriptor or
block jar file.
-cli-block-description=An absolute or relative filename of a block descriptor or
block jar file (required).
-
-cli-config-description=The filename of the block configuration. If not specified
the value defaults to a file name config.xml in the same directory as the block.
+cli-config-description=The filename of the configuration target override.
cli-system-description=An absolute or relative path to a repository parent
directory.
-cli-library-description=A directory that serves as the anchor for relative library
directory references.
+cli-library-description=A directory that serves as the anchor for relative library
references.
-cli-description=\nDescription: The merlin command executes the deployment of a
component block. The [block] argument may be either an block descriptor file or a jar
file containing a block descriptor. If no value if declared, Merlin will attempt to
execute a file named 'block.xml' in the current directory.
+cli-description=\nDescription: The merlin command executes the deployment of one or
more component blocks. The [block] argument may be either an block descriptor file or
a jar file containing a block descriptor. If no value if declared, Merlin will
attempt to execute a file named 'block.xml' in the current directory.
1.10 +9 -3
avalon-sandbox/merlin/merlin-plugin/src/java/org/apache/avalon/merlin/tools/MerlinBean.java
Index: MerlinBean.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/merlin/merlin-plugin/src/java/org/apache/avalon/merlin/tools/MerlinBean.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MerlinBean.java 12 Aug 2003 10:51:09 -0000 1.9
+++ MerlinBean.java 18 Aug 2003 15:11:33 -0000 1.10
@@ -288,7 +288,7 @@
return m_system;
}
- public boolean getDebugFlag()
+ public boolean getDebugFlag()
{
return m_debug.equalsIgnoreCase( "debug" );
}
@@ -300,9 +300,15 @@
Repository repository = new DefaultFileRepository( m_repository );
DefaultKernelContext context =
new DefaultKernelContext(
- repository, m_system, m_home, m_kernelPath.toURL(),
+ repository,
+ m_system,
+ m_home,
+ m_home,
+ m_kernelPath.toURL(),
new URL[]{ getTarget() },
- getConfigurationURL(), m_deploy, getDebugFlag() );
+ getConfigurationURL(),
+ m_deploy,
+ getDebugFlag() );
m_kernel = new DefaultKernel( context );
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]