source: josm/src/org/openstreetmap/josm/plugins/PluginInformation.java@ 157

Last change on this file since 157 was 157, checked in by imi, 18 years ago
  • fixed plugin loader for Windows (again)
File size: 1.7 KB
Line 
1package org.openstreetmap.josm.plugins;
2
3import java.io.File;
4import java.io.FileInputStream;
5import java.io.IOException;
6import java.net.URL;
7import java.net.URLClassLoader;
8import java.util.jar.JarInputStream;
9import java.util.jar.Manifest;
10
11/**
12 * Encapsulate general information about a plugin. This information is available
13 * without the need of loading any class from the plugin jar file.
14 *
15 * @author imi
16 */
17public class PluginInformation {
18 public final File file;
19 public final String name;
20 public final String className;
21 public final String description;
22
23 public PluginInformation(File file) {
24 this.file = file;
25 name = file.getName().substring(0, file.getName().length()-4);
26 try {
27 JarInputStream jar = new JarInputStream(new FileInputStream(file));
28 Manifest manifest = jar.getManifest();
29 className = manifest.getMainAttributes().getValue("Plugin-Class");
30 description = manifest.getMainAttributes().getValue("Plugin-Description");
31 jar.close();
32 } catch (IOException e) {
33 throw new PluginException(null, name, e);
34 }
35 }
36
37 /**
38 * Load and instantiate the plugin
39 */
40 public PluginProxy load() {
41 try {
42 ClassLoader loader = URLClassLoader.newInstance(
43 new URL[]{new URL(getURLString())},
44 getClass().getClassLoader());
45 Object plugin = Class.forName(className, true, loader).newInstance();
46 return new PluginProxy(plugin, this);
47 } catch (Exception e) {
48 throw new PluginException(null, name, e);
49 }
50 }
51
52 private String getURLString() {
53 if (System.getProperty("os.name").startsWith("Windows"))
54 return "file:/"+file.getAbsolutePath();
55 return "file://"+file.getAbsolutePath();
56 }
57}
Note: See TracBrowser for help on using the repository browser.