Changeset 10616 in josm for trunk/src/org/openstreetmap/josm/plugins
- Timestamp:
- 2016-07-23T21:38:02+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/Plugin.java
r9645 r10616 146 146 File pluginJar = new File(pluginDir, info.name + ".jar"); 147 147 final URL pluginJarUrl = Utils.fileToURL(pluginJar); 148 return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 149 @Override 150 public ClassLoader run() { 151 return new URLClassLoader(new URL[] {pluginJarUrl}, Main.class.getClassLoader()); 152 } 153 }); 148 return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) 149 () -> new URLClassLoader(new URL[] {pluginJarUrl}, Main.class.getClassLoader())); 154 150 } 155 151 } -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r10493 r10616 24 24 import java.util.Collection; 25 25 import java.util.Collections; 26 import java.util.Comparator;27 26 import java.util.HashMap; 28 27 import java.util.HashSet; … … 35 34 import java.util.Set; 36 35 import java.util.TreeSet; 37 import java.util.concurrent.Callable;38 36 import java.util.concurrent.ExecutionException; 39 37 import java.util.concurrent.FutureTask; … … 534 532 535 533 // Continuation 536 Main.worker.submit(new Runnable() { 537 @Override 538 public void run() { 539 // Build list of plugins to download 540 Set<PluginInformation> toDownload = new HashSet<>(pluginInfoDownloadTask.getAvailablePlugins()); 541 for (Iterator<PluginInformation> it = toDownload.iterator(); it.hasNext();) { 542 PluginInformation info = it.next(); 543 if (!missingRequiredPlugin.contains(info.getName())) { 544 it.remove(); 534 Main.worker.submit(() -> { 535 // Build list of plugins to download 536 Set<PluginInformation> toDownload = new HashSet<>(pluginInfoDownloadTask.getAvailablePlugins()); 537 for (Iterator<PluginInformation> it = toDownload.iterator(); it.hasNext();) { 538 PluginInformation info = it.next(); 539 if (!missingRequiredPlugin.contains(info.getName())) { 540 it.remove(); 541 } 542 } 543 // Check if something has still to be downloaded 544 if (!toDownload.isEmpty()) { 545 // download plugins 546 final PluginDownloadTask task = new PluginDownloadTask(parent, toDownload, tr("Download plugins")); 547 Main.worker.submit(task); 548 Main.worker.submit(() -> { 549 // restart if some plugins have been downloaded 550 if (!task.getDownloadedPlugins().isEmpty()) { 551 // update plugin list in preferences 552 Set<String> plugins = new HashSet<>(Main.pref.getCollection("plugins")); 553 for (PluginInformation plugin : task.getDownloadedPlugins()) { 554 plugins.add(plugin.name); 555 } 556 Main.pref.putCollection("plugins", plugins); 557 // restart 558 new RestartAction().actionPerformed(null); 559 } else { 560 Main.warn("No plugin downloaded, restart canceled"); 545 561 } 546 } 547 // Check if something has still to be downloaded 548 if (!toDownload.isEmpty()) { 549 // download plugins 550 final PluginDownloadTask task = new PluginDownloadTask(parent, toDownload, tr("Download plugins")); 551 Main.worker.submit(task); 552 Main.worker.submit(new Runnable() { 553 @Override 554 public void run() { 555 // restart if some plugins have been downloaded 556 if (!task.getDownloadedPlugins().isEmpty()) { 557 // update plugin list in preferences 558 Set<String> plugins = new HashSet<>(Main.pref.getCollection("plugins")); 559 for (PluginInformation plugin : task.getDownloadedPlugins()) { 560 plugins.add(plugin.name); 561 } 562 Main.pref.putCollection("plugins", plugins); 563 // restart 564 new RestartAction().actionPerformed(null); 565 } else { 566 Main.warn("No plugin downloaded, restart canceled"); 567 } 568 } 569 }); 570 } else { 571 Main.warn("No plugin to download, operation canceled"); 572 } 562 }); 563 } else { 564 Main.warn("No plugin to download, operation canceled"); 573 565 } 574 566 }); … … 665 657 public static synchronized DynamicURLClassLoader getPluginClassLoader() { 666 658 if (pluginClassLoader == null) { 667 pluginClassLoader = AccessController.doPrivileged(new PrivilegedAction<DynamicURLClassLoader>() { 668 @Override 669 public DynamicURLClassLoader run() { 670 return new DynamicURLClassLoader(new URL[0], Main.class.getClassLoader()); 671 } 672 }); 659 pluginClassLoader = AccessController.doPrivileged((PrivilegedAction<DynamicURLClassLoader>) 660 () -> new DynamicURLClassLoader(new URL[0], Main.class.getClassLoader())); 673 661 sources.add(0, pluginClassLoader); 674 662 } … … 760 748 Collections.sort( 761 749 toLoad, 762 new Comparator<PluginInformation>() { 763 @Override 764 public int compare(PluginInformation o1, PluginInformation o2) { 765 if (o1.stage < o2.stage) return -1; 766 if (o1.stage == o2.stage) return 0; 767 return 1; 768 } 750 (o1, o2) -> { 751 if (o1.stage < o2.stage) return -1; 752 if (o1.stage == o2.stage) return 0; 753 return 1; 769 754 } 770 755 ); … … 1173 1158 return; 1174 1159 1175 final File[] files = pluginDir.listFiles(new FilenameFilter() { 1176 @Override 1177 public boolean accept(File dir, String name) { 1178 return name.endsWith(".jar.new"); 1179 } 1180 }); 1160 final File[] files = pluginDir.listFiles((FilenameFilter) (dir, name) -> name.endsWith(".jar.new")); 1181 1161 if (files == null) 1182 1162 return; … … 1198 1178 } catch (IOException e) { 1199 1179 if (dowarn) { 1200 Main.warn( tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}",1180 Main.warn(e, tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}", 1201 1181 plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage())); 1202 1182 } … … 1309 1289 1310 1290 try { 1311 FutureTask<Integer> task = new FutureTask<>(new Callable<Integer>() { 1312 @Override 1313 public Integer call() { 1314 return HelpAwareOptionPane.showOptionDialog( 1315 Main.parent, 1316 msg.toString(), 1317 tr("Update plugins"), 1318 JOptionPane.QUESTION_MESSAGE, 1319 null, 1320 options, 1321 options[0], 1322 ht("/ErrorMessages#ErrorInPlugin") 1323 ); 1324 } 1325 }); 1291 FutureTask<Integer> task = new FutureTask<>(() -> HelpAwareOptionPane.showOptionDialog( 1292 Main.parent, 1293 msg.toString(), 1294 tr("Update plugins"), 1295 JOptionPane.QUESTION_MESSAGE, 1296 null, 1297 options, 1298 options[0], 1299 ht("/ErrorMessages#ErrorInPlugin") 1300 )); 1326 1301 GuiHelper.runInEDT(task); 1327 1302 return task.get(); … … 1394 1369 plugins.remove(plugin.getPluginInformation().name); 1395 1370 Main.pref.putCollection("plugins", plugins); 1396 GuiHelper.runInEDTAndWait(new Runnable() { 1397 @Override 1398 public void run() { 1399 JOptionPane.showMessageDialog( 1400 Main.parent, 1401 tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."), 1402 tr("Information"), 1403 JOptionPane.INFORMATION_MESSAGE 1404 ); 1405 } 1406 }); 1371 GuiHelper.runInEDTAndWait(() -> JOptionPane.showMessageDialog( 1372 Main.parent, 1373 tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."), 1374 tr("Information"), 1375 JOptionPane.INFORMATION_MESSAGE 1376 )); 1407 1377 return null; 1408 1378 default: -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r10173 r10616 47 47 } 48 48 49 /** 50 * Constructs a new {@code ReadLocalPluginInformationTask}. 51 * @param monitor progress monitor 52 */ 49 53 public ReadLocalPluginInformationTask(ProgressMonitor monitor) { 50 54 super(tr("Reading local plugin information.."), monitor, false); … … 77 81 78 82 private static File[] listFiles(File pluginsDirectory, final String regex) { 79 return pluginsDirectory.listFiles( 80 new FilenameFilter() { 81 @Override 82 public boolean accept(File dir, String name) { 83 return name.matches(regex); 84 } 85 } 86 ); 83 return pluginsDirectory.listFiles((FilenameFilter) (dir, name) -> name.matches(regex)); 87 84 } 88 85 … … 108 105 protected void scanPluginFiles(ProgressMonitor monitor, File pluginsDirectory) { 109 106 File[] pluginFiles = pluginsDirectory.listFiles( 110 new FilenameFilter() { 111 @Override 112 public boolean accept(File dir, String name) { 113 return name.endsWith(".jar") || name.endsWith(".jar.new"); 114 } 115 } 107 (FilenameFilter) (dir, name) -> name.endsWith(".jar") || name.endsWith(".jar.new") 116 108 ); 117 109 if (pluginFiles == null || pluginFiles.length == 0) … … 131 123 } 132 124 } catch (PluginException e) { 133 Main.warn( "PluginException: "+e.getMessage());125 Main.warn(e, "PluginException: "); 134 126 Main.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname)); 135 127 } -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r10173 r10616 200 200 private static void displayErrorMessage(final ProgressMonitor monitor, final String msg, final String details, final String title, 201 201 final String firstMessage) { 202 GuiHelper.runInEDTAndWait(new Runnable() { 203 @Override public void run() { 204 JPanel panel = new JPanel(new GridBagLayout()); 205 panel.add(new JLabel(firstMessage), GBC.eol().insets(0, 0, 0, 10)); 206 StringBuilder b = new StringBuilder(); 207 for (String part : msg.split("(?<=\\G.{200})")) { 208 b.append(part).append('\n'); 209 } 210 panel.add(new JLabel("<html><body width=\"500\"><b>"+b.toString().trim()+"</b></body></html>"), GBC.eol().insets(0, 0, 0, 10)); 211 if (details != null && !details.isEmpty()) { 212 panel.add(new JLabel(tr("Details:")), GBC.eol().insets(0, 0, 0, 10)); 213 JosmTextArea area = new JosmTextArea(details); 214 area.setEditable(false); 215 area.setLineWrap(true); 216 area.setWrapStyleWord(true); 217 JScrollPane scrollPane = new JScrollPane(area); 218 scrollPane.setPreferredSize(new Dimension(500, 300)); 219 panel.add(scrollPane, GBC.eol().fill()); 220 } 221 JOptionPane.showMessageDialog(monitor.getWindowParent(), panel, title, JOptionPane.ERROR_MESSAGE); 222 } 202 GuiHelper.runInEDTAndWait(() -> { 203 JPanel panel = new JPanel(new GridBagLayout()); 204 panel.add(new JLabel(firstMessage), GBC.eol().insets(0, 0, 0, 10)); 205 StringBuilder b = new StringBuilder(); 206 for (String part : msg.split("(?<=\\G.{200})")) { 207 b.append(part).append('\n'); 208 } 209 panel.add(new JLabel("<html><body width=\"500\"><b>"+b.toString().trim()+"</b></body></html>"), GBC.eol().insets(0, 0, 0, 10)); 210 if (details != null && !details.isEmpty()) { 211 panel.add(new JLabel(tr("Details:")), GBC.eol().insets(0, 0, 0, 10)); 212 JosmTextArea area = new JosmTextArea(details); 213 area.setEditable(false); 214 area.setLineWrap(true); 215 area.setWrapStyleWord(true); 216 JScrollPane scrollPane = new JScrollPane(area); 217 scrollPane.setPreferredSize(new Dimension(500, 300)); 218 panel.add(scrollPane, GBC.eol().fill()); 219 } 220 JOptionPane.showMessageDialog(monitor.getWindowParent(), panel, title, JOptionPane.ERROR_MESSAGE); 223 221 }); 224 222 } … … 296 294 for (String location : PluginInformation.getPluginLocations()) { 297 295 File[] f = new File(location).listFiles( 298 new FilenameFilter() { 299 @Override 300 public boolean accept(File dir, String name) { 301 return name.matches("^([0-9]+-)?site.*\\.txt$") || 302 name.matches("^([0-9]+-)?site.*-icons\\.zip$"); 303 } 304 } 296 (FilenameFilter) (dir, name) -> name.matches("^([0-9]+-)?site.*\\.txt$") || 297 name.matches("^([0-9]+-)?site.*-icons\\.zip$") 305 298 ); 306 299 if (f != null && f.length > 0) {
Note:
See TracChangeset
for help on using the changeset viewer.