mcconnell 2002/12/27 08:37:10
Modified: merlin/src/java/org/apache/avalon/merlin Main.java
Log:
Removed resolution of configuration (now handled by the kernel). Main simply
handles the resolution of the base directory.
Revision Changes Path
1.5 +56 -53
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Main.java 19 Dec 2002 10:50:16 -0000 1.4
+++ Main.java 27 Dec 2002 16:37:10 -0000 1.5
@@ -32,12 +32,28 @@
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.merlin.block.Block;
import org.apache.avalon.merlin.block.DefaultBlock;
+import org.apache.avalon.merlin.kernel.Kernel;
import org.apache.avalon.merlin.kernel.DefaultKernel;
import org.apache.avalon.merlin.kernel.KernelException;
import org.apache.avalon.assembly.util.ExceptionHelper;
+/**
+ * Merlin commandline bootstrap handler.
+ * @see DefaultKernel
+ */
public class Main
{
+ /**
+ * 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.
+ *
+ * @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.
+ * @see DefaultKernel
+ */
public static void main( String[] args )
{
Main main = new Main( args );
@@ -45,8 +61,25 @@
private DefaultKernel m_kernel;
- public Main( String[] args )
+ 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 );
+ }
+
m_kernel = new DefaultKernel();
try
@@ -92,33 +125,12 @@
return;
}
- File base = getWorkingDirectory();
DefaultContext context = new DefaultContext();
context.put( "urn:assembly:home", base );
context.makeReadOnly();
- File file = getConfigurationFile( base, args );
- if( !file.exists() )
- {
- final String error =
- "Missing kernel configuration: " + file;
- throw new RuntimeException( error );
- }
-
- Configuration config;
try
{
- config = getConfiguration( file );
- }
- catch( Throwable e )
- {
- final String error = "Problem loading kernel configuration form file: "
+ file;
- throw new RuntimeException( error );
- }
-
- try
- {
- m_kernel.configure( config );
m_kernel.contextualize( context );
m_kernel.initialize();
m_kernel.start();
@@ -137,11 +149,12 @@
}
/**
- * Get the target configuration file.
+ * Get the base directory.
* @param args the command line arguments
*/
- public File getConfigurationFile( File base, String[] args )
+ private File getBaseDirectory( String[] args ) throws IOException
{
+ File base = new File( System.getProperty( "user.dir" ) );
String filename;
if( args.length > 0 )
{
@@ -149,40 +162,30 @@
}
else
{
- filename = "kernel.xml";
+ filename = ".";
+ }
+ File result = new File( base, filename );
+ if( result.isFile() )
+ {
+ result = result.getParentFile();
}
- return new File( base, filename );
- }
-
- /**
- * Get the target configuration file.
- * @param args the command line arguments
- */
- public File getWorkingDirectory( )
- {
- return new File( System.getProperty( "user.dir" ) );
- }
-
- private Configuration getConfiguration( final File file ) throws
ConfigurationException
- {
- try
+ if( !result.exists() )
{
- DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
- InputStream is = new FileInputStream( file );
- if( is == null )
+ final String error =
+ "Supplied path does not refer to a directory: ";
+ String message;
+ try
{
- throw new ConfigurationException(
- "Could not load the configuration resource \"" + file + "\"" );
+ message = error + result.getCanonicalFile();
}
- return builder.build( is );
- }
- catch( Throwable e )
- {
- final String error = "Unable to create configuration from file: " +
file;
- throw new ConfigurationException( error, e );
+ catch( Throwable e )
+ {
+ message = error + filename;
+ }
+ throw new IOException( message );
}
- }
-
+ return result.getCanonicalFile();
+ }
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>