1 87 package org.codehaus.loom.launcher; 88 89 import java.io.File ; 90 import java.net.URL ; 91 import java.util.ArrayList ; 92 import java.util.StringTokenizer ; 93 94 99 public class LauncherUtils 100 { 101 107 static URL [] generateClassPath( final File homeDir, 108 final String libDirectory ) 109 throws Exception 110 { 111 final ArrayList urls = new ArrayList (); 112 113 final File dir = findLibDir( homeDir, libDirectory ); 114 final File [] files = dir.listFiles(); 115 for( int i = 0; i < files.length; i++ ) 116 { 117 final File file = files[ i ]; 118 if( file.getName().endsWith( ".jar" ) ) 119 { 120 urls.add( file.toURL() ); 121 } 122 } 123 124 return (URL [])urls.toArray( new URL [ urls.size() ] ); 125 } 126 127 133 static File findLibDir( final File homeDir, 134 final String libDirectory ) 135 throws Exception 136 { 137 final String engineLibDir = libDirectory.replace( '/', 138 File.separatorChar ); 139 final File dir = new File ( homeDir, engineLibDir ).getCanonicalFile(); 140 if( !dir.exists() ) 141 { 142 throw new Exception ( 143 "Unable to locate library directory at " + engineLibDir ); 144 } 145 return dir; 146 } 147 148 155 static File findLoomHome( final String systemProperty, 156 final String loaderJar ) 157 throws Exception 158 { 159 String loomHome = System.getProperty( systemProperty, null ); 160 if( null == loomHome ) 161 { 162 final File loaderDir = 163 findLoaderDir( systemProperty, loaderJar ); 164 return loaderDir.getCanonicalFile().getParentFile(); 165 } 166 else 167 { 168 return new File ( loomHome ).getCanonicalFile(); 169 } 170 } 171 172 175 private static final File findLoaderDir( final String systemProperty, 176 final String loaderJar ) 177 throws Exception 178 { 179 final String classpath = System.getProperty( "java.class.path" ); 180 final String pathSeparator = System.getProperty( "path.separator" ); 181 final StringTokenizer tokenizer = new StringTokenizer ( classpath, 182 pathSeparator ); 183 184 while( tokenizer.hasMoreTokens() ) 185 { 186 final String element = tokenizer.nextToken(); 187 188 if( element.endsWith( loaderJar ) ) 189 { 190 File file = ( new File ( element ) ).getCanonicalFile(); 191 file = file.getParentFile(); 192 return file; 193 } 194 } 195 196 throw new Exception ( "Unable to locate " + 197 loaderJar + 198 " in classpath. User must specify " + 199 systemProperty + " system property." ); 200 } 201 } 202 | Popular Tags |