Changeset 267 in josm for src/org/openstreetmap/josm
- Timestamp:
- 2007-06-30T22:01:02+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r266 r267 234 234 // iterate all plugins and collect all libraries of all plugins: 235 235 List<URL> allPluginLibraries = new ArrayList<URL>(); 236 for (Collection<PluginInformation> c : p.values()) { 237 for (PluginInformation info : c) { 238 allPluginLibraries.addAll(info.getLibraries()); 239 } 240 } 236 for (Collection<PluginInformation> c : p.values()) 237 for (PluginInformation info : c) 238 allPluginLibraries.addAll(info.libraries); 241 239 // create a classloader for all plugins: 242 240 URL[] jarUrls = new URL[allPluginLibraries.size()]; 243 241 jarUrls = allPluginLibraries.toArray(jarUrls); 244 242 URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader()); 245 246 243 247 244 for (Collection<PluginInformation> c : p.values()) { 248 245 for (PluginInformation info : c) { 249 246 try { 250 info.setClassLoader(pluginClassLoader); // set the common classloader 251 Class<?> klass = info.loadClass(); 247 Class<?> klass = info.loadClass(pluginClassLoader); 252 248 ImageProvider.sources.add(0, klass); 253 249 System.out.println("loading "+info.name); -
src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r203 r267 72 72 } 73 73 }; 74 74 75 /** 75 76 * Main table. 3 columns: … … 80 81 81 82 private Map<OsmPrimitive, List<HistoryItem>> cache = new HashMap<OsmPrimitive, List<HistoryItem>>(); 82 private JLabel notLoaded = new JLabel("<html><i> <p align=\"center\">"+tr("Click Reload to refresh list")+"</p></i></html>");83 private JLabel notLoaded = new JLabel("<html><i>"+tr("Click Reload to refresh list")+"</i></html>"); 83 84 private JButton reloadButton = new JButton(tr("Reload"), ImageProvider.get("dialogs/refresh")); 84 85 private JButton revertButton = new JButton(tr("Revert"), ImageProvider.get("dialogs/revert")); … … 88 89 historyPane.setVisible(false); 89 90 notLoaded.setVisible(true); 91 notLoaded.setHorizontalAlignment(JLabel.CENTER); 90 92 91 93 history.setDefaultRenderer(Object.class, new DefaultTableCellRenderer(){ … … 131 133 reloadButton.setToolTipText(tr("Reload all currently selected objects and refresh the list.")); 132 134 reloadButton.putClientProperty("help", "Dialog/History/Reload"); 135 133 136 revertButton.addActionListener(new ActionListener(){ 134 137 public void actionPerformed(ActionEvent e) { -
src/org/openstreetmap/josm/plugins/Plugin.java
r237 r267 40 40 public abstract class Plugin { 41 41 42 privateString name;42 String name; 43 43 44 44 public Plugin() { 45 URL[] urls = ((URLClassLoader)getClass().getClassLoader()).getURLs(); 46 name = urls[urls.length-1].toString(); 47 if (name.toLowerCase().endsWith(".jar")) { 48 int lastSlash = name.lastIndexOf('/'); 49 name = name.substring(lastSlash+1, name.length()-4); 50 } 45 try { 46 URL[] urls = ((URLClassLoader)getClass().getClassLoader()).getURLs(); 47 name = urls[urls.length-1].toString(); 48 if (name.toLowerCase().endsWith(".jar")) { 49 int lastSlash = name.lastIndexOf('/'); 50 name = name.substring(lastSlash+1, name.length()-4); 51 } 52 } catch (RuntimeException e) { 53 name = "unknown"; 54 } 51 55 } 52 56 53 57 /** 54 58 * @return The name of this plugin. This is the name of the .jar file. 59 * @deprecated Plugins have to know their name by themself. 55 60 */ 56 public final String getName() { 61 @Deprecated public final String getName() { 57 62 return name; 58 63 } 59 64 /** 60 65 * @return The directory for the plugin to store all kind of stuff. 66 * @deprecated Use <code>Main.pref.getPreferencesDir()+"plugins/"+name+"/";</code> instead. 61 67 */ 62 public final String getPluginDir() { 68 @Deprecated public final String getPluginDir() { 63 69 return Main.pref.getPreferencesDir()+"plugins/"+name+"/"; 64 70 } -
src/org/openstreetmap/josm/plugins/PluginException.java
r149 r267 11 11 */ 12 12 public class PluginException extends RuntimeException { 13 p rivatefinal PluginProxy plugin;14 p rivatefinal String name;13 public final PluginProxy plugin; 14 public final String name; 15 15 16 16 public PluginException(PluginProxy plugin, String name, Throwable cause) { … … 19 19 this.name = name; 20 20 } 21 22 public PluginProxy getPlugin() {23 return plugin;24 }25 public String getName() {26 return name;27 }28 21 } -
src/org/openstreetmap/josm/plugins/PluginInformation.java
r250 r267 6 6 import java.io.InputStream; 7 7 import java.net.URL; 8 import java.net.URLClassLoader;9 8 import java.util.ArrayList; 10 9 import java.util.Collection; … … 33 32 public final String author; 34 33 public final int stage; 35 protected final List<URL> libraries = new ArrayList<URL>(); 36 protected ClassLoader classLoader; 34 public final List<URL> libraries = new ArrayList<URL>(); 37 35 38 36 public final Map<String, String> attr = new TreeMap<String, String>(); … … 82 80 s = entry.toString(); 83 81 entry = new StringBuilder(); 84 if (!s.startsWith("/") && !s.startsWith("\\") && !s.matches("^.\\:")) 82 if (!s.startsWith("/") && !s.startsWith("\\") && !s.matches("^.\\:") && file != null) 85 83 s = file.getParent() + File.separator + s; 86 84 libraries.add(new URL(getURLString(s))); … … 111 109 * Load the class of the plugin 112 110 */ 113 public Class<?> loadClass() { 111 public Class<?> loadClass(ClassLoader classLoader) { 114 112 try { 115 Class<?> realClass = Class.forName(className, true, getClassLoader());113 Class<?> realClass = Class.forName(className, true, classLoader); 116 114 return realClass; 117 115 } catch (Exception e) { … … 126 124 } 127 125 128 /**129 * Returns all libraries the plugin needs (the plugin's jar file itself and all jars declared130 * 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 classLoader139 */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 set152 */153 public void setClassLoader(ClassLoader classLoader) {154 this.classLoader = classLoader;155 }156 157 126 /** 158 127 * Try to find a plugin after some criterias. Extract the plugin-information -
src/org/openstreetmap/josm/plugins/PluginProxy.java
r238 r267 24 24 this.plugin = plugin; 25 25 this.info = info; 26 27 // setting name of the plugin by reflection 28 if (plugin instanceof Plugin) { 29 try { 30 Plugin.class.getDeclaredField("name").set(plugin, info.name); 31 } catch (Exception e) { 32 if (e instanceof RuntimeException) 33 throw (RuntimeException)e; 34 throw new RuntimeException(e); 35 } 36 } 26 37 } 27 38 -
src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r243 r267 43 43 // Check for an explicit problem when calling a plugin function 44 44 if (e instanceof PluginException) { 45 PluginProxy plugin = ((PluginException)e). getPlugin();45 PluginProxy plugin = ((PluginException)e).plugin; 46 46 if (plugin != null && !plugin.misbehaving) { 47 47 JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} throwed an exception: {1}\nIt may be outdated. Please contact the plugin's autor.\nThis message will not shown again until JOSM is restarted.", plugin.info.name, e.getMessage()));
Note:
See TracChangeset
for help on using the changeset viewer.