Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 11 package org.eclipse.core.internal.plugins; 12 13 import java.io.IOException ; 14 import java.net.*; 15 import org.eclipse.core.internal.runtime.InternalPlatform; 16 import org.eclipse.core.runtime.ILibrary; 17 import org.eclipse.core.runtime.Platform; 18 import org.osgi.framework.Bundle; 19 20 public class PluginClassLoader extends URLClassLoader { 21 private Bundle bundle; private PluginDescriptor descriptor; 23 24 PluginClassLoader(PluginDescriptor descriptor) { 25 super(computeURLs(descriptor)); 26 this.descriptor = descriptor; 27 this.bundle = InternalPlatform.getDefault().getBundle(descriptor.getUniqueIdentifier()); 28 if (bundle == null) 29 throw new IllegalArgumentException (); 30 } 31 32 private static URL[] computeURLs(PluginDescriptor descriptor) { 33 Bundle bundle = InternalPlatform.getDefault().getBundle(descriptor.getUniqueIdentifier()); 34 if (bundle == null) 35 throw new IllegalArgumentException (); 36 37 ILibrary[] libs = descriptor.getRuntimeLibraries(); 38 String [] devPath = computeDevPath(bundle); 39 URL pluginBase = descriptor.getInstallURL(); 40 try { 41 pluginBase = Platform.resolve(descriptor.getInstallURL()); 42 } catch (IOException e1) { 43 } 45 46 URL[] urls = new URL[devPath.length + libs.length]; 47 int j = 0; 48 for (int i = 0; i < devPath.length; i++) { 49 try { 50 urls[j++] = new URL(pluginBase, devPath[i]); 51 } catch (MalformedURLException e) { 52 } 54 } 55 for (int i = 0; i < libs.length; i++) { 56 try { 57 urls[j++] = new URL(pluginBase, libs[i].getPath().toOSString()); 58 } catch (MalformedURLException e) { 59 } 61 } 62 return urls; 63 } 64 65 private static String [] computeDevPath(Bundle bundle) { 66 if (!DevClassPathHelper.inDevelopmentMode()) 67 return new String [0]; 68 69 String pluginId = bundle.getSymbolicName(); 70 if (pluginId == null) 71 return new String [0]; 72 return DevClassPathHelper.getDevClassPath(pluginId); 73 } 74 75 protected Class findClass(String name) throws ClassNotFoundException { 76 return bundle.loadClass(name); } 78 79 public URL findResource(String name) { 80 return bundle.getResource(name); 81 } 82 83 public PluginDescriptor getPluginDescriptor() { 84 return descriptor; 85 } 86 } 87
| Popular Tags
|