- Timestamp:
- 2007-05-31T00:29:59+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r243 r250 12 12 import java.net.URISyntaxException; 13 13 import java.util.Arrays; 14 import java.net.URL; 15 import java.net.URLClassLoader; 16 import java.util.ArrayList; 14 17 import java.util.Collection; 15 18 import java.util.LinkedList; … … 208 211 if (plugins.isEmpty()) 209 212 return; 210 211 213 SortedMap<Integer, Collection<PluginInformation>> p = new TreeMap<Integer, Collection<PluginInformation>>(); 212 214 for (String pluginName : plugins) { … … 225 227 } 226 228 } 229 230 // iterate all plugins and collect all libraries of all plugins: 231 List<URL> allPluginLibraries = new ArrayList<URL>(); 232 for (Collection<PluginInformation> c : p.values()) { 233 for (PluginInformation info : c) { 234 allPluginLibraries.addAll(info.getLibraries()); 235 } 236 } 237 // create a classloader for all plugins: 238 URL[] jarUrls = new URL[allPluginLibraries.size()]; 239 jarUrls = allPluginLibraries.toArray(jarUrls); 240 URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader()); 241 242 227 243 for (Collection<PluginInformation> c : p.values()) { 228 244 for (PluginInformation info : c) { 229 245 try { 246 info.setClassLoader(pluginClassLoader); // set the common classloader 230 247 Class<?> klass = info.loadClass(); 231 248 ImageProvider.sources.add(0, klass); -
src/org/openstreetmap/josm/plugins/PluginInformation.java
r243 r250 33 33 public final String author; 34 34 public final int stage; 35 public final List<URL> libraries = new ArrayList<URL>(); 35 protected final List<URL> libraries = new ArrayList<URL>(); 36 protected ClassLoader classLoader; 36 37 37 38 public final Map<String, String> attr = new TreeMap<String, String>(); … … 68 69 if (file != null) 69 70 libraries.add(new URL(getURLString(file.getAbsolutePath()))); 70 String classPath = attr.getValue( "Class-Path");71 String classPath = attr.getValue(Attributes.Name.CLASS_PATH); 71 72 if (classPath != null) { 72 73 String[] cp = classPath.split(" "); … … 112 113 public Class<?> loadClass() { 113 114 try { 114 URL[] urls = new URL[libraries.size()]; 115 urls = libraries.toArray(urls); 116 ClassLoader loader = URLClassLoader.newInstance(urls, getClass().getClassLoader()); 117 Class<?> realClass = Class.forName(className, true, loader); 115 Class<?> realClass = Class.forName(className, true, getClassLoader()); 118 116 return realClass; 119 117 } catch (Exception e) { … … 127 125 return "file://"+fileName; 128 126 } 127 128 /** 129 * Returns all libraries the plugin needs (the plugin's jar file itself and all jars declared 130 * in the manifest's Class-Path section). 131 * @return the libraries a list of URLs to the libraries. 132 */ 133 public List<URL> getLibraries() { 134 return libraries; 135 } 136 137 /** 138 * @return the classLoader 139 */ 140 public ClassLoader getClassLoader() { 141 // if I have no classloader set, create one for me and my libraries: 142 if(classLoader == null) { 143 URL[] urls = new URL[libraries.size()]; 144 urls = libraries.toArray(urls); 145 classLoader = URLClassLoader.newInstance(urls, getClass().getClassLoader()); 146 } 147 return classLoader; 148 } 149 150 /** 151 * @param classLoader the classLoader to set 152 */ 153 public void setClassLoader(ClassLoader classLoader) { 154 this.classLoader = classLoader; 155 } 129 156 130 157 /** … … 190 217 } 191 218 } 219
Note:
See TracChangeset
for help on using the changeset viewer.