- Timestamp:
- 2015-02-09T08:43:18+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r8015 r8017 423 423 424 424 monitor.indeterminateSubTask(tr("Loading early plugins")); 425 PluginHandler.loadEarlyPlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false)); 425 PluginHandler.loadEarlyPlugins(splash, pluginsToLoad, monitor.createSubTaskMonitor(1, false)); 426 426 427 427 monitor.indeterminateSubTask(tr("Setting defaults")); … … 432 432 433 433 monitor.indeterminateSubTask(tr("Loading plugins")); 434 PluginHandler.loadLatePlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false)); 434 PluginHandler.loadLatePlugins(splash, pluginsToLoad, monitor.createSubTaskMonitor(1, false)); 435 435 toolbar.refreshToolbarControl(); 436 436 -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
r7509 r8017 318 318 public void run() { 319 319 boolean requiresRestart = false; 320 if (task != null && !task.isCanceled()) {321 if (!task.getDownloadedPlugins().isEmpty()) {322 requiresRestart = true;323 }324 }325 320 326 321 for (PreferenceSetting setting : settingsInitialized) { … … 370 365 ); 371 366 } 367 368 // load the plugins that can be loaded at runtime 369 List<PluginInformation> newPlugins = preference.getNewlyActivatedPlugins(); 370 if (newPlugins != null) { 371 Collection<PluginInformation> downloadedPlugins = null; 372 if (task != null && !task.isCanceled()) { 373 downloadedPlugins = task.getDownloadedPlugins(); 374 } 375 List<PluginInformation> toLoad = new ArrayList<>(); 376 for (PluginInformation pi : newPlugins) { 377 if (toDownload.contains(pi) && downloadedPlugins != null && !downloadedPlugins.contains(pi)) { 378 continue; // failed download 379 } 380 if (pi.canloadatruntime) { 381 toLoad.add(pi); 382 } 383 } 384 if (!toLoad.isEmpty()) { 385 PluginHandler.loadPlugins(PreferenceTabbedPane.this, toLoad, null); // FIXME: progress bar 386 } 387 } 388 372 389 Main.parent.repaint(); 373 390 } -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
r7668 r8017 123 123 * @since 6797 124 124 */ 125 public staticvoid notifyDownloadResults(final Component parent, PluginDownloadTask task) {125 public void notifyDownloadResults(final Component parent, PluginDownloadTask task) { 126 126 final Collection<PluginInformation> downloaded = task.getDownloadedPlugins(); 127 127 final Collection<PluginInformation> failed = task.getFailedPlugins(); … … 129 129 sb.append("<html>"); 130 130 sb.append(buildDownloadSummary(task)); 131 if (!downloaded.isEmpty()) { 131 boolean restartRequired = false; 132 for (PluginInformation pi : downloaded) { 133 if (!model.getNewlyActivatedPlugins().contains(pi) || !pi.canloadatruntime) { 134 restartRequired = true; 135 break; 136 } 137 } 138 if (restartRequired) { 132 139 sb.append(tr("Please restart JOSM to activate the downloaded plugins.")); 133 140 } … … 276 283 } 277 284 285 public List<PluginInformation> getNewlyActivatedPlugins() { 286 return model != null ? model.getNewlyActivatedPlugins() : null; 287 } 288 278 289 @Override 279 290 public boolean ok() { … … 285 296 Collections.sort(l); 286 297 Main.pref.putCollection("plugins", l); 287 return true; 298 if (!model.getNewlyDeactivatedPlugins().isEmpty()) return true; 299 for (PluginInformation pi : model.getNewlyActivatedPlugins()) { 300 if (!pi.canloadatruntime) return true; 301 } 288 302 } 289 303 return false; … … 436 450 // 437 451 Iterator<PluginInformation> it = toUpdate.iterator(); 438 while(it.hasNext()) { 452 while (it.hasNext()) { 439 453 PluginInformation pi = it.next(); 440 454 if (!pi.isUpdateRequired()) { … … 590 604 } 591 605 } 606 607 592 608 } -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java
r7005 r8017 25 25 */ 26 26 public class PluginPreferencesModel extends Observable { 27 // remember the initial list of active plugins 28 private final Set<String> currentActivePlugins; 27 29 private final List<PluginInformation> availablePlugins = new ArrayList<>(); 30 private String filterExpression; 28 31 private final List<PluginInformation> displayedPlugins = new ArrayList<>(); 29 32 private final Map<PluginInformation, Boolean> selectedPluginsMap = new HashMap<>(); 33 // plugins that still require an update/download 30 34 private Set<String> pendingDownloads = new HashSet<>(); 31 private String filterExpression;32 private Set<String> currentActivePlugins;33 35 34 36 /** … … 197 199 PluginInformation pi = getPluginInformation(name); 198 200 if (pi != null) { 199 selectedPluginsMap.put(pi,selected); 201 selectedPluginsMap.put(pi, selected); 200 202 if (pi.isUpdateRequired()) { 201 203 pendingDownloads.add(pi.name); … … 213 215 * @param plugins the list of plugins to clear for a pending download 214 216 */ 215 public void clearPendingPlugins(Collection<PluginInformation> plugins){ 217 public void clearPendingPlugins(Collection<PluginInformation> plugins) { 216 218 if (plugins == null || plugins.isEmpty()) return; 217 for(PluginInformation pi: plugins) { 219 for (PluginInformation pi: plugins) { 218 220 pendingDownloads.remove(pi.name); 219 221 } -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
r7597 r8017 187 187 188 188 /** 189 * Replies the list of successfullydownloaded plugins190 * 191 * @return the list of successfullydownloaded plugins189 * Replies the list of plugins whose download has failed. 190 * 191 * @return the list of plugins whose download has failed 192 192 */ 193 193 public Collection<PluginInformation> getFailedPlugins() { … … 196 196 197 197 /** 198 * Replies the list of plugins whosedownloadhas failed199 * 200 * @return the list of plugins whosedownloadhas failed198 * Replies the list of successfully downloaded plugins. 199 * 200 * @return the list of successfully downloaded plugins 201 201 */ 202 202 public Collection<PluginInformation> getDownloadedPlugins() { -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r7956 r8017 187 187 188 188 /** 189 * ClassLoader that makes the addURL method of URLClassLoader public. 190 * 191 * Like URLClassLoader, but allows to add more URLs after construction. 192 */ 193 public static class DynamicURLClassLoader extends URLClassLoader { 194 195 public DynamicURLClassLoader(URL[] urls, ClassLoader parent) { 196 super(urls, parent); 197 } 198 199 @Override 200 public void addURL(URL url) { 201 super.addURL(url); 202 } 203 } 204 205 /** 189 206 * List of unmaintained plugins. Not really up-to-date as the vast majority of plugins are not really maintained after a few months, sadly... 190 207 */ … … 200 217 */ 201 218 public static final Collection<PluginProxy> pluginList = new LinkedList<>(); 219 220 /** 221 * Global plugin ClassLoader. 222 */ 223 private static DynamicURLClassLoader pluginClassLoader; 202 224 203 225 /** … … 536 558 537 559 /** 538 * Creates a class loader for loading plugin code. 539 * 540 * @param plugins the collection of plugins which are going to be loaded with this 541 * class loader 560 * Get the class loader for loading plugin code. 561 * 542 562 * @return the class loader 543 563 */ 544 public static ClassLoader createClassLoader(Collection<PluginInformation> plugins) { 564 public static DynamicURLClassLoader getPluginClassLoader() { 565 if (pluginClassLoader == null) { 566 pluginClassLoader = AccessController.doPrivileged(new PrivilegedAction<DynamicURLClassLoader>() { 567 public DynamicURLClassLoader run() { 568 return new DynamicURLClassLoader(new URL[0], Main.class.getClassLoader()); 569 } 570 }); 571 sources.add(0, pluginClassLoader); 572 } 573 return pluginClassLoader; 574 } 575 576 /** 577 * Add more plugins to the plugin class loader. 578 * 579 * @param plugins the plugins that should be handled by the plugin class loader 580 */ 581 public static void extendPluginClassLoader(Collection<PluginInformation> plugins) { 545 582 // iterate all plugins and collect all libraries of all plugins: 546 List<URL> allPluginLibraries = new LinkedList<>();547 583 File pluginDir = Main.pref.getPluginsDirectory(); 548 549 // Add all plugins already loaded (to include early plugins in the classloader, allowing late plugins to rely on early ones) 550 Collection<PluginInformation> allPlugins = new HashSet<>(plugins); 551 for (PluginProxy proxy : pluginList) { 552 allPlugins.add(proxy.getPluginInformation()); 553 } 554 555 for (PluginInformation info : allPlugins) { 584 DynamicURLClassLoader cl = getPluginClassLoader(); 585 586 for (PluginInformation info : plugins) { 556 587 if (info.libraries == null) { 557 588 continue; 558 589 } 559 allPluginLibraries.addAll(info.libraries); 590 for (URL libUrl : info.libraries) { 591 cl.addURL(libUrl); 592 } 560 593 File pluginJar = new File(pluginDir, info.name + ".jar"); 561 594 I18n.addTexts(pluginJar); 562 595 URL pluginJarUrl = Utils.fileToURL(pluginJar); 563 allPluginLibraries.add(pluginJarUrl); 564 } 565 566 // create a classloader for all plugins: 567 final URL[] jarUrls = allPluginLibraries.toArray(new URL[allPluginLibraries.size()]); 568 return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 569 public ClassLoader run() { 570 return new URLClassLoader(jarUrls, Main.class.getClassLoader()); 571 } 572 }); 596 cl.addURL(pluginJarUrl); 597 } 573 598 } 574 599 … … 614 639 * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null. 615 640 */ 616 public static void loadPlugins(Component parent,Collection<PluginInformation> plugins, ProgressMonitor monitor) { 641 public static void loadPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) { 617 642 if (monitor == null) { 618 643 monitor = NullProgressMonitor.INSTANCE; … … 644 669 return; 645 670 646 ClassLoader pluginClassLoader = createClassLoader(toLoad); 647 sources.add(0, pluginClassLoader); 671 extendPluginClassLoader(toLoad); 648 672 monitor.setTicksCount(toLoad.size()); 649 673 for (PluginInformation info : toLoad) { 650 674 monitor.setExtraText(tr("Loading plugin ''{0}''...", info.name)); 651 loadPlugin(parent, info, pluginClassLoader);675 loadPlugin(parent, info, getPluginClassLoader()); 652 676 monitor.worked(1); 653 677 } … … 1045 1069 * If {@code dowarn} is true, this methods emits warning messages on the console if a downloaded 1046 1070 * but not yet installed plugin .jar can't be be installed. If {@code dowarn} is false, the 1047 * installation of the respective plugin is sil lently skipped.1071 * installation of the respective plugin is silently skipped. 1048 1072 * 1049 1073 * @param dowarn if true, warning messages are displayed; false otherwise -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r7655 r8017 78 78 /** The plugin icon. */ 79 79 public ImageIcon icon; 80 /** Plugin can be loaded at any time and not just at start. */ 81 public boolean canloadatruntime = false; 80 82 /** The libraries referenced in Class-Path manifest attribute. */ 81 83 public List<URL> libraries = new LinkedList<>(); … … 169 171 this.icon = other.icon; 170 172 this.iconPath = other.iconPath; 173 this.canloadatruntime = other.canloadatruntime; 171 174 this.libraries = other.libraries; 172 175 this.attr.clear(); … … 189 192 this.early = other.early; 190 193 this.className = other.className; 194 this.canloadatruntime = other.canloadatruntime; 191 195 this.libraries = other.libraries; 192 196 this.stage = other.stage; … … 250 254 } 251 255 } 256 canloadatruntime = Boolean.parseBoolean(attr.getValue("Plugin-Canloadatruntime")); 252 257 if (oldcheck && mainversion > Version.getInstance().getVersion()) { 253 258 int myv = Version.getInstance().getVersion();
Note:
See TracChangeset
for help on using the changeset viewer.