Changeset 159 in josm for src/org/openstreetmap/josm/plugins
- Timestamp:
- 2006-10-13T13:02:57+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm/plugins
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/plugins/Plugin.java
r154 r159 1 1 package org.openstreetmap.josm.plugins; 2 2 3 import java.io.File; 3 4 import java.io.FileNotFoundException; 4 5 import java.io.FileOutputStream; … … 71 72 */ 72 73 public void copy(String from, String to) throws FileNotFoundException, IOException { 74 File pluginDir = new File(getPluginDir()); 75 if (!pluginDir.exists()) 76 pluginDir.mkdirs(); 73 77 FileOutputStream out = new FileOutputStream(getPluginDir()+to); 74 78 InputStream in = getClass().getResourceAsStream(from); -
src/org/openstreetmap/josm/plugins/PluginInformation.java
r157 r159 6 6 import java.net.URL; 7 7 import java.net.URLClassLoader; 8 import java.util.Map; 9 import java.util.TreeMap; 10 import java.util.jar.Attributes; 8 11 import java.util.jar.JarInputStream; 9 12 import java.util.jar.Manifest; … … 20 23 public final String className; 21 24 public final String description; 25 public final boolean early; 26 public final String author; 27 28 public final Map<String, String> attr = new TreeMap<String, String>(); 22 29 23 30 public PluginInformation(File file) { … … 25 32 name = file.getName().substring(0, file.getName().length()-4); 26 33 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 } 34 JarInputStream jar = new JarInputStream(new FileInputStream(file)); 35 Manifest manifest = jar.getManifest(); 36 Attributes attr = manifest.getMainAttributes(); 37 className = attr.getValue("Plugin-Class"); 38 description = attr.getValue("Plugin-Description"); 39 early = Boolean.parseBoolean(attr.getValue("Plugin-Early")); 40 author = attr.getValue("Author"); 41 for (Object o : attr.keySet()) 42 this.attr.put(o.toString(), attr.getValue(o.toString())); 43 jar.close(); 44 } catch (IOException e) { 45 throw new PluginException(null, name, e); 46 } 47 } 36 48 37 49 /** 38 50 * Load and instantiate the plugin 39 51 */ 40 public PluginProxy load() { 52 public PluginProxy load(Class<?> klass) { 53 try { 54 return new PluginProxy(klass.newInstance(), this); 55 } catch (Exception e) { 56 throw new PluginException(null, name, e); 57 } 58 } 59 60 /** 61 * Load the class of the plugin 62 */ 63 public Class<?> loadClass() { 41 64 try { 42 65 ClassLoader loader = URLClassLoader.newInstance( 43 66 new URL[]{new URL(getURLString())}, 44 67 getClass().getClassLoader()); 45 Object plugin= Class.forName(className, true, loader).newInstance();46 return new PluginProxy(plugin, this);68 Class<?> realClass = Class.forName(className, true, loader); 69 return realClass; 47 70 } catch (Exception e) { 48 71 throw new PluginException(null, name, e); … … 54 77 return "file:/"+file.getAbsolutePath(); 55 78 return "file://"+file.getAbsolutePath(); 56 79 } 57 80 }
Note:
See TracChangeset
for help on using the changeset viewer.