CVS: jcontainer/loom/launcher/src/java/org/jcontainer/loom/launcher Main.java,1.4,1.5 LauncherUtils.java,1.4,1.5
Peter Donald <pdonald-yCVjj/[email protected]> Sun, 2 Nov 2003 22:55:17 -0600
| Newsgroups | gmane.comp.java.jcontainer.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/jcontainer/jcontainer/loom/launcher/src/java/org/jcontainer/loom/launcher
In directory hogshead.codehaus.org:/tmp/cvs-serv19378
Modified Files:
Main.java LauncherUtils.java
Log Message:
Start to refactor launcher utils to be useful outside loom
Index: Main.java
===================================================================
RCS file: /cvsroot/jcontainer/jcontainer/loom/launcher/src/java/org/jcontainer/loom/launcher/Main.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Main.java 5 Oct 2003 08:10:20 -0000 1.4
+++ Main.java 3 Nov 2003 04:55:14 -0000 1.5
@@ -106,6 +106,7 @@
"org.jcontainer.loom.frontends.CLIMain";
private static Object c_frontend;
+ static final String LOADER_JAR = "loom-launcher.jar";
/**
* Main entry point for Loom.
@@ -143,12 +144,16 @@
Policy.setPolicy( new FreeNEasyPolicy() );
//Create engine ClassLoader
- final URL[] urls = LauncherUtils.getEngineClassPath();
+ final File homeDir =
+ LauncherUtils.findLoomHome( "loom.home", "loom-launcher.jar" );
+
+ final URL[] urls =
+ LauncherUtils.generateClassPath( homeDir, "container/lib" );
final URLClassLoader classLoader = new URLClassLoader( urls );
data.put( ClassLoader.class.getName() + "/common", ClassLoader.getSystemClassLoader() );
data.put( ClassLoader.class.getName() + "/container", classLoader );
- data.put( "loom.home", new File( LauncherUtils.findLoomHome() ) );
+ data.put( File.class.getName() + "/home", homeDir );
//Setup context classloader
Thread.currentThread().setContextClassLoader( classLoader );
Index: LauncherUtils.java
===================================================================
RCS file: /cvsroot/jcontainer/jcontainer/loom/launcher/src/java/org/jcontainer/loom/launcher/LauncherUtils.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- LauncherUtils.java 17 Aug 2003 18:27:33 -0000 1.4
+++ LauncherUtils.java 3 Nov 2003 04:55:14 -0000 1.5
@@ -99,20 +99,19 @@
*/
public class LauncherUtils
{
- private static final String LOADER_JAR = "loom-launcher.jar";
-
/**
* Create a ClassPath for the engine.
*
* @return the set of URLs that engine uses to load
- * @throws java.lang.Exception if unable to aquire classpath
+ * @throws Exception if unable to aquire classpath
*/
- static URL[] getEngineClassPath()
+ static URL[] generateClassPath( final File homeDir,
+ final String libDirectory )
throws Exception
{
final ArrayList urls = new ArrayList();
- final File dir = findEngineLibDir();
+ final File dir = findLibDir( homeDir, libDirectory );
final File[] files = dir.listFiles();
for( int i = 0; i < files.length; i++ )
{
@@ -130,18 +129,17 @@
* Find directory to load engine specific libraries from.
*
* @return the lib dir
- * @throws java.lang.Exception if unable to aquire directory
+ * @throws Exception if unable to aquire directory
*/
- private static File findEngineLibDir()
+ static File findLibDir( final File homeDir,
+ final String libDirectory )
throws Exception
{
- final String loomHome = findLoomHome();
- final String engineLibDir =
- loomHome + File.separator + "container" + File.separator + "lib";
- final File dir = new File( engineLibDir ).getCanonicalFile();
+ final String engineLibDir = libDirectory.replace( '/', File.separatorChar );
+ final File dir = new File( homeDir, engineLibDir ).getCanonicalFile();
if( !dir.exists() )
{
- throw new Exception( "Unable to locate engine lib directory at " + engineLibDir );
+ throw new Exception( "Unable to locate library directory at " + engineLibDir );
}
return dir;
}
@@ -152,27 +150,30 @@
* set to it.
*
* @return the location of loom directory
- * @throws java.lang.Exception if unable to locate directory
+ * @throws Exception if unable to locate directory
*/
- static String findLoomHome()
+ static File findLoomHome( final String systemProperty,
+ final String loaderJar )
throws Exception
{
- String loomHome = System.getProperty( "loom.home", null );
+ String loomHome = System.getProperty( systemProperty, null );
if( null == loomHome )
{
- final File loaderDir = findLoaderDir();
- loomHome = loaderDir.getAbsoluteFile().getParentFile() + File.separator;
+ final File loaderDir =
+ findLoaderDir( systemProperty, loaderJar );
+ return loaderDir.getCanonicalFile().getParentFile();
+ }
+ else
+ {
+ return new File( loomHome ).getCanonicalFile();
}
-
- loomHome = ( new File( loomHome ) ).getCanonicalFile().toString();
- System.setProperty( "loom.home", loomHome );
- return loomHome;
}
/**
- * Finds the LOADER_JAR file in the classpath.
+ * Finds the loaderJar file in the classpath.
*/
- private static final File findLoaderDir()
+ private static final File findLoaderDir( final String systemProperty,
+ final String loaderJar )
throws Exception
{
final String classpath = System.getProperty( "java.class.path" );
@@ -183,7 +184,7 @@
{
final String element = tokenizer.nextToken();
- if( element.endsWith( LOADER_JAR ) )
+ if( element.endsWith( loaderJar ) )
{
File file = ( new File( element ) ).getCanonicalFile();
file = file.getParentFile();
@@ -191,8 +192,8 @@
}
}
- throw new Exception( "Unable to locate " + LOADER_JAR +
+ throw new Exception( "Unable to locate " + loaderJar +
" in classpath. User must specify " +
- "loom.home system property." );
+ systemProperty + " system property." );
}
}