- Timestamp:
- 2010-01-12T18:27:40+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/Plugin.java
r2817 r2830 15 15 16 16 /** 17 * All plugins *must* have an standard constructor taking no arguments.18 *19 * This constructor is called at JOSM startup, after all Main-objects have been initialized.20 17 * For all purposes of loading dynamic resources, the Plugin's class loader should be used 21 18 * (or else, the plugin jar will not be within the class path). … … 47 44 * is a bit hacky, but it works). 48 45 */ 49 public final PluginInformation info = PluginInformation.currentPluginInitialization; 46 private PluginInformation info = null; 47 48 /** 49 * The no-arg constructor is deprecated. 50 * 51 * @deprecated use {@see Plugin(PluginInformation)} instead 52 */ 53 @Deprecated 54 public Plugin() { 55 56 } 57 /** 58 * Creates the plugin 59 * 60 * @param info the plugin information describing the plugin. 61 */ 62 public Plugin(PluginInformation info) { 63 this.info = info; 64 } 65 66 /** 67 * Replies the plugin information object for this plugin 68 * 69 * @return the plugin information object 70 */ 71 public PluginInformation getPluginInformation() { 72 return info; 73 } 74 75 /** 76 * Sets the plugin information object for this plugin 77 * 78 * @parma info the plugin information object 79 */ 80 public void setPluginInformation(PluginInformation info) { 81 this.info = info; 82 } 50 83 51 84 /** … … 79 112 */ 80 113 public void copy(String from, String to) throws FileNotFoundException, IOException { 81 String pluginDirName = Main.pref.getP referencesDir()+"plugins/"+info.name+"/";114 String pluginDirName = Main.pref.getPluginsDirectory() + "/" + info.name + "/"; 82 115 File pluginDir = new File(pluginDirName); 83 116 if (!pluginDir.exists()) { -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r2817 r2830 1 //License: GPL. Copyright 2007 by Immanuel Scholz and others2 1 package org.openstreetmap.josm.plugins; 3 2 … … 598 597 public static Object getPlugin(String name) { 599 598 for (PluginProxy plugin : pluginList) 600 if(plugin. info.name.equals(name))599 if(plugin.getPluginInformation().name.equals(name)) 601 600 return plugin.plugin; 602 601 return null; … … 666 665 for (PluginProxy p : pluginList) 667 666 { 668 String baseClass = p. info.className;667 String baseClass = p.getPluginInformation().className; 669 668 int i = baseClass.lastIndexOf("."); 670 669 baseClass = baseClass.substring(0, i); … … 693 692 dialog.setContent( 694 693 tr("<html>") + 695 tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin. info.name)694 tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", plugin.getPluginInformation().name) 696 695 + "<br>" 697 + (plugin. info.author != null698 ? tr("According to the information within the plugin, the author is {0}.", plugin. info.author)696 + (plugin.getPluginInformation().author != null 697 ? tr("According to the information within the plugin, the author is {0}.", plugin.getPluginInformation().author) 699 698 : "") 700 699 + "<br>" … … 709 708 if (answer == 1) { 710 709 List<String> plugins = new ArrayList<String>(Main.pref.getCollection("plugins", Collections.<String>emptyList())); 711 if (plugins.contains(plugin. info.name)) {712 while (plugins.remove(plugin. info.name)) {}710 if (plugins.contains(plugin.getPluginInformation().name)) { 711 while (plugins.remove(plugin.getPluginInformation().name)) {} 713 712 Main.pref.putCollection("plugins", plugins); 714 713 JOptionPane.showMessageDialog(Main.parent, … … 738 737 for (final PluginProxy pp : pluginList) { 739 738 text += "Plugin " 740 + pp. info.name741 + (pp. info.version != null && !pp.info.version.equals("") ? " Version: " + pp.info.version + "\n"739 + pp.getPluginInformation().name 740 + (pp.getPluginInformation().version != null && !pp.getPluginInformation().version.equals("") ? " Version: " + pp.getPluginInformation().version + "\n" 742 741 : "\n"); 743 742 } … … 748 747 JPanel pluginTab = new JPanel(new GridBagLayout()); 749 748 for (final PluginProxy p : pluginList) { 750 String name = p.info.name 751 + (p.info.version != null && !p.info.version.equals("") ? " Version: " + p.info.version : ""); 749 final PluginInformation info = p.getPluginInformation(); 750 String name = info.name 751 + (info.version != null && !info.version.equals("") ? " Version: " + info.version : ""); 752 752 pluginTab.add(new JLabel(name), GBC.std()); 753 753 pluginTab.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL)); … … 755 755 public void actionPerformed(ActionEvent event) { 756 756 StringBuilder b = new StringBuilder(); 757 for (Entry<String, String> e : p.info.attr.entrySet()) {757 for (Entry<String, String> e : info.attr.entrySet()) { 758 758 b.append(e.getKey()); 759 759 b.append(": "); … … 769 769 }), GBC.eol()); 770 770 771 JTextArea description = new JTextArea(( p.info.description == null ? tr("no description available")772 : p.info.description));771 JTextArea description = new JTextArea((info.description == null ? tr("no description available") 772 : info.description)); 773 773 description.setEditable(false); 774 774 description.setFont(new JLabel().getFont().deriveFont(Font.ITALIC)); -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r2817 r2830 8 8 import java.io.IOException; 9 9 import java.io.InputStream; 10 import java.lang.reflect.Constructor; 11 import java.lang.reflect.InvocationTargetException; 12 import java.lang.reflect.Method; 10 13 import java.net.MalformedURLException; 11 14 import java.net.URL; … … 48 51 49 52 public final Map<String, String> attr = new TreeMap<String, String>(); 50 51 /**52 * Used in the Plugin constructor to make the information of the plugin53 * that is currently initializing available.54 *55 * If you think this is hacky, you are probably right. But it is56 * convinient anyway ;-)57 */58 static PluginInformation currentPluginInitialization = null;59 53 60 54 /** … … 193 187 /** 194 188 * Load and instantiate the plugin 189 * 190 * @param the plugin class 191 * @return the instantiated and initialized plugin 195 192 */ 196 193 public PluginProxy load(Class<?> klass) throws PluginException{ 197 194 try { 198 currentPluginInitialization = this; 199 return new PluginProxy(klass.newInstance(), this); 195 try { 196 Constructor<?> c = klass.getDeclaredConstructor(PluginInformation.class); 197 Object plugin = c.newInstance(this); 198 return new PluginProxy(plugin, this); 199 } catch(NoSuchMethodException e) { 200 // do nothing - try again with the noarg constructor for legacy support 201 } 202 // FIXME: This is legacy support. It is necessary because of a former ugly hack in the 203 // plugin bootstrap procedure. Plugins should be migrated to the new required 204 // constructor with PluginInformation as argument, new plugins should only use this 205 // constructor. The following is legacy support and should be removed by Q2/2010. 206 // Note that this is not fool proof because it isn't 207 // completely equivalent with the former hack: plugins derived from the Plugin 208 // class can't access their local "info" object any more from within the noarg- 209 // constructor. It is only set *after* constructor invocation. 210 // 211 Constructor<?> c = klass.getConstructor(); 212 Object plugin = c.newInstance(); 213 if (plugin instanceof Plugin) { 214 Method m = klass.getMethod("setPluginInformation", PluginInformation.class); 215 m.invoke(plugin, this); 216 } 217 return new PluginProxy(plugin, this); 218 } catch(NoSuchMethodException e) { 219 throw new PluginException(name, e); 200 220 } catch(IllegalAccessException e) { 201 221 throw new PluginException(name, e); 202 222 } catch (InstantiationException e) { 203 223 throw new PluginException(name, e); 224 } catch(InvocationTargetException e) { 225 throw new PluginException(name, e); 204 226 } 205 227 } … … 207 229 /** 208 230 * Load the class of the plugin 231 * 232 * @param classLoader the class loader to use 233 * @return the loaded class 209 234 */ 210 235 public Class<?> loadClass(ClassLoader classLoader) throws PluginException { … … 215 240 return realClass; 216 241 } catch (ClassNotFoundException e) { 242 throw new PluginException(name, e); 243 } catch(ClassCastException e) { 217 244 throw new PluginException(name, e); 218 245 } -
trunk/src/org/openstreetmap/josm/plugins/PluginProxy.java
r1326 r2830 19 19 20 20 public final Object plugin; 21 public final PluginInformation info;22 21 23 22 public PluginProxy(Object plugin, PluginInformation info) { 23 super(info); 24 24 this.plugin = plugin; 25 this.info = info;26 25 } 27 26 … … 31 30 } catch (NoSuchMethodException e) { 32 31 } catch (Exception e) { 33 BugReportExceptionHandler.handleException(new PluginException(this, info.name, e));32 BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e)); 34 33 } 35 34 } … … 41 40 return null; 42 41 } catch (Exception e) { 43 BugReportExceptionHandler.handleException(new PluginException(this, info.name, e));42 BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e)); 44 43 } 45 44 return null; … … 52 51 // ignore 53 52 } catch (Exception e) { 54 BugReportExceptionHandler.handleException(new PluginException(this, info.name, e));53 BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e)); 55 54 } 56 55 } -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r2819 r2830 161 161 protected void analyseInProcessPlugins() { 162 162 for (PluginProxy proxy : PluginHandler.pluginList) { 163 PluginInformation info = proxy.getPluginInformation(); 163 164 if (canceled)return; 164 if (!availablePlugins.containsKey( proxy.info.name)) {165 availablePlugins.put( proxy.info.name, proxy.info);165 if (!availablePlugins.containsKey(info.name)) { 166 availablePlugins.put(info.name, info); 166 167 } else { 167 availablePlugins.get( proxy.info.name).localversion = proxy.info.version;168 availablePlugins.get(info.name).localversion = info.version; 168 169 } 169 170 }
Note:
See TracChangeset
for help on using the changeset viewer.