Changeset 2278 for trunk/autoquest-plugin-core/src/main/java/de/ugoe
- Timestamp:
- 08/02/19 10:58:48 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-core/src/main/java/de/ugoe/cs/autoquest/plugin/PluginLoader.java
r2260 r2278 16 16 17 17 import java.io.File; 18 import java.io.FileInputStream; 19 import java.io.FileNotFoundException; 18 20 import java.io.FilenameFilter; 21 import java.io.IOException; 19 22 import java.lang.reflect.InvocationTargetException; 20 23 import java.net.MalformedURLException; … … 25 28 import java.util.LinkedList; 26 29 import java.util.List; 30 import java.util.jar.JarInputStream; 31 import java.util.jar.Manifest; 27 32 28 33 /** … … 96 101 if (jarFiles != null) { 97 102 for (File jarFile : jarFiles) { 98 updateClassLoader(jarFile);103 ClassLoader loader = getClassLoader(jarFile); 99 104 100 105 String pluginName = jarFile.getName().split("-")[2]; … … 104 109 Class<?> pluginClass = null; 105 110 try { 106 pluginClass = Class.forName(pluginClassName);111 pluginClass = loader.loadClass(pluginClassName); 107 112 } 108 113 catch (ClassNotFoundException e) { … … 150 155 * </p> 151 156 */ 152 /* 153 * protected String[] getClassPathFromJar(File jarFile) { String[] classPath; 154 * 155 * JarInputStream jarInputStream = null; Manifest manifest = null; try { FileInputStream 156 * fileStream = new FileInputStream(jarFile); try { jarInputStream = new 157 * JarInputStream(fileStream); manifest = jarInputStream.getManifest(); } finally { 158 * jarInputStream.close(); fileStream.close(); } } catch (FileNotFoundException e) { throw new 159 * AssertionError( "FileNotFoundException should be impossible!"); } catch (IOException e) { 160 * throw new PluginLoaderException(e); } 161 * 162 * String jarClassPath = manifest.getMainAttributes().getValue( "Class-Path"); 163 * 164 * if (jarClassPath != null) { String[] jarClassPathElements = jarClassPath.split(" "); 165 * classPath = new String[jarClassPathElements.length]; for (int i = 0; i < 166 * jarClassPathElements.length; i++) { classPath[i] = "file:" + 167 * jarFile.getParentFile().getAbsolutePath() + "/" + jarClassPathElements[i]; } try { 168 * jarInputStream.close(); } catch (IOException e) { throw new PluginLoaderException(e); } } 169 * else { classPath = new String[] {}; } return classPath; } 170 */ 157 158 protected String[] getClassPathFromJar(File jarFile) { 159 String[] classPath; 160 JarInputStream jarInputStream = null; 161 Manifest manifest = null; 162 try { 163 FileInputStream fileStream = new FileInputStream(jarFile); 164 try { 165 jarInputStream = new JarInputStream(fileStream); 166 manifest = jarInputStream.getManifest(); 167 } 168 finally { 169 jarInputStream.close(); 170 fileStream.close(); 171 } 172 } 173 catch (FileNotFoundException e) { 174 throw new AssertionError("FileNotFoundException should be impossible!"); 175 } 176 catch (IOException e) { 177 throw new PluginLoaderException(e); 178 } 179 180 String jarClassPath = manifest.getMainAttributes().getValue("Class-Path"); 181 182 if (jarClassPath != null) { 183 String[] jarClassPathElements = jarClassPath.split(" "); 184 classPath = new String[jarClassPathElements.length]; 185 for (int i = 0; i < jarClassPathElements.length; i++) { 186 classPath[i] = "file:" + jarFile.getParentFile().getAbsolutePath() + "/" + 187 jarClassPathElements[i]; 188 } 189 try { 190 jarInputStream.close(); 191 } 192 catch (IOException e) { 193 throw new PluginLoaderException(e); 194 } 195 } 196 else { 197 classPath = new String[] { }; 198 } 199 return classPath; 200 } 171 201 172 202 /** … … 182 212 * thrown if there is a problem updating the class loader or loading the plug-in jar 183 213 */ 184 private void updateClassLoader(File jarFile) throws PluginLoaderException {185 // String[] classPath= getClassPathFromJar(jarFile);214 private ClassLoader getClassLoader(File jarFile) throws PluginLoaderException { 215 String[] otherJars = getClassPathFromJar(jarFile); 186 216 187 217 try { 218 URL[] urls = new URL[otherJars.length + 1]; 219 urls[0] = new URL("jar:file:" + jarFile.getAbsoluteFile() + "!/"); 220 221 int index = 1; 222 for (String jar : otherJars) { 223 urls[index++] = new URL("jar:file:" + new File(jar).getAbsoluteFile() + "!/"); 224 } 225 188 226 URLClassLoader loader = new URLClassLoader(new URL[] 189 { new URL(" file:" + jarFile.getAbsoluteFile()) },227 { new URL("jar:file:" + jarFile.getAbsoluteFile() + "!/") }, 190 228 ClassLoader.getSystemClassLoader()); 191 229 192 230 instantiatedClassLoaders.add(loader); 231 232 return loader; 193 233 } 194 234 catch (MalformedURLException e) {
Note: See TracChangeset
for help on using the changeset viewer.