[3719] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[1326] | 2 | package org.openstreetmap.josm.plugins;
|
---|
| 3 |
|
---|
[2389] | 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
[1326] | 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
[2817] | 6 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
[1326] | 7 |
|
---|
[5121] | 8 | import java.awt.Component;
|
---|
[1326] | 9 | import java.awt.Font;
|
---|
[10093] | 10 | import java.awt.GraphicsEnvironment;
|
---|
[2856] | 11 | import java.awt.GridBagConstraints;
|
---|
[1326] | 12 | import java.awt.GridBagLayout;
|
---|
[2856] | 13 | import java.awt.Insets;
|
---|
[1326] | 14 | import java.awt.event.ActionEvent;
|
---|
[2817] | 15 | import java.io.File;
|
---|
| 16 | import java.io.FilenameFilter;
|
---|
[10212] | 17 | import java.io.IOException;
|
---|
[1326] | 18 | import java.net.URL;
|
---|
| 19 | import java.net.URLClassLoader;
|
---|
[6282] | 20 | import java.security.AccessController;
|
---|
| 21 | import java.security.PrivilegedAction;
|
---|
[1742] | 22 | import java.util.ArrayList;
|
---|
[1326] | 23 | import java.util.Arrays;
|
---|
| 24 | import java.util.Collection;
|
---|
[1837] | 25 | import java.util.Collections;
|
---|
[10647] | 26 | import java.util.Comparator;
|
---|
[2817] | 27 | import java.util.HashMap;
|
---|
| 28 | import java.util.HashSet;
|
---|
| 29 | import java.util.Iterator;
|
---|
[1326] | 30 | import java.util.LinkedList;
|
---|
| 31 | import java.util.List;
|
---|
[8404] | 32 | import java.util.Locale;
|
---|
[2817] | 33 | import java.util.Map;
|
---|
[4043] | 34 | import java.util.Map.Entry;
|
---|
[2817] | 35 | import java.util.Set;
|
---|
[3669] | 36 | import java.util.TreeSet;
|
---|
[2817] | 37 | import java.util.concurrent.ExecutionException;
|
---|
[6797] | 38 | import java.util.concurrent.FutureTask;
|
---|
[11288] | 39 | import java.util.concurrent.TimeUnit;
|
---|
[5723] | 40 | import java.util.jar.JarFile;
|
---|
[10982] | 41 | import java.util.stream.Collectors;
|
---|
[1326] | 42 |
|
---|
| 43 | import javax.swing.AbstractAction;
|
---|
| 44 | import javax.swing.BorderFactory;
|
---|
| 45 | import javax.swing.Box;
|
---|
| 46 | import javax.swing.JButton;
|
---|
[2856] | 47 | import javax.swing.JCheckBox;
|
---|
[1326] | 48 | import javax.swing.JLabel;
|
---|
| 49 | import javax.swing.JOptionPane;
|
---|
| 50 | import javax.swing.JPanel;
|
---|
| 51 | import javax.swing.JScrollPane;
|
---|
| 52 | import javax.swing.UIManager;
|
---|
| 53 |
|
---|
| 54 | import org.openstreetmap.josm.Main;
|
---|
[8471] | 55 | import org.openstreetmap.josm.actions.RestartAction;
|
---|
[2358] | 56 | import org.openstreetmap.josm.data.Version;
|
---|
[2856] | 57 | import org.openstreetmap.josm.gui.HelpAwareOptionPane;
|
---|
[4043] | 58 | import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
|
---|
[12634] | 59 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
[1326] | 60 | import org.openstreetmap.josm.gui.download.DownloadSelection;
|
---|
[1742] | 61 | import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
|
---|
[2817] | 62 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
| 63 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
[6797] | 64 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[6340] | 65 | import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
|
---|
[5886] | 66 | import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
---|
[7434] | 67 | import org.openstreetmap.josm.io.OfflineAccessException;
|
---|
| 68 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
[1326] | 69 | import org.openstreetmap.josm.tools.GBC;
|
---|
[4159] | 70 | import org.openstreetmap.josm.tools.I18n;
|
---|
[1326] | 71 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
[12620] | 72 | import org.openstreetmap.josm.tools.Logging;
|
---|
[10781] | 73 | import org.openstreetmap.josm.tools.SubclassFilteredCollection;
|
---|
[6524] | 74 | import org.openstreetmap.josm.tools.Utils;
|
---|
[1326] | 75 |
|
---|
[2817] | 76 | /**
|
---|
| 77 | * PluginHandler is basically a collection of static utility functions used to bootstrap
|
---|
| 78 | * and manage the loaded plugins.
|
---|
[6248] | 79 | * @since 1326
|
---|
[2817] | 80 | */
|
---|
[6362] | 81 | public final class PluginHandler {
|
---|
[2278] | 82 |
|
---|
[5508] | 83 | /**
|
---|
[6248] | 84 | * Deprecated plugins that are removed on start
|
---|
[5508] | 85 | */
|
---|
[10245] | 86 | static final Collection<DeprecatedPlugin> DEPRECATED_PLUGINS;
|
---|
[3669] | 87 | static {
|
---|
[10001] | 88 | String inCore = tr("integrated into main program");
|
---|
[3730] | 89 |
|
---|
[12279] | 90 | DEPRECATED_PLUGINS = Arrays.asList(
|
---|
[10001] | 91 | new DeprecatedPlugin("mappaint", inCore),
|
---|
| 92 | new DeprecatedPlugin("unglueplugin", inCore),
|
---|
| 93 | new DeprecatedPlugin("lang-de", inCore),
|
---|
| 94 | new DeprecatedPlugin("lang-en_GB", inCore),
|
---|
| 95 | new DeprecatedPlugin("lang-fr", inCore),
|
---|
| 96 | new DeprecatedPlugin("lang-it", inCore),
|
---|
| 97 | new DeprecatedPlugin("lang-pl", inCore),
|
---|
| 98 | new DeprecatedPlugin("lang-ro", inCore),
|
---|
| 99 | new DeprecatedPlugin("lang-ru", inCore),
|
---|
| 100 | new DeprecatedPlugin("ewmsplugin", inCore),
|
---|
| 101 | new DeprecatedPlugin("ywms", inCore),
|
---|
| 102 | new DeprecatedPlugin("tways-0.2", inCore),
|
---|
| 103 | new DeprecatedPlugin("geotagged", inCore),
|
---|
[8510] | 104 | new DeprecatedPlugin("landsat", tr("replaced by new {0} plugin", "lakewalker")),
|
---|
[10001] | 105 | new DeprecatedPlugin("namefinder", inCore),
|
---|
| 106 | new DeprecatedPlugin("waypoints", inCore),
|
---|
| 107 | new DeprecatedPlugin("slippy_map_chooser", inCore),
|
---|
[8510] | 108 | new DeprecatedPlugin("tcx-support", tr("replaced by new {0} plugin", "dataimport")),
|
---|
[10001] | 109 | new DeprecatedPlugin("usertools", inCore),
|
---|
| 110 | new DeprecatedPlugin("AgPifoJ", inCore),
|
---|
| 111 | new DeprecatedPlugin("utilsplugin", inCore),
|
---|
| 112 | new DeprecatedPlugin("ghost", inCore),
|
---|
| 113 | new DeprecatedPlugin("validator", inCore),
|
---|
| 114 | new DeprecatedPlugin("multipoly", inCore),
|
---|
| 115 | new DeprecatedPlugin("multipoly-convert", inCore),
|
---|
| 116 | new DeprecatedPlugin("remotecontrol", inCore),
|
---|
| 117 | new DeprecatedPlugin("imagery", inCore),
|
---|
| 118 | new DeprecatedPlugin("slippymap", inCore),
|
---|
| 119 | new DeprecatedPlugin("wmsplugin", inCore),
|
---|
| 120 | new DeprecatedPlugin("ParallelWay", inCore),
|
---|
[8510] | 121 | new DeprecatedPlugin("dumbutils", tr("replaced by new {0} plugin", "utilsplugin2")),
|
---|
[10001] | 122 | new DeprecatedPlugin("ImproveWayAccuracy", inCore),
|
---|
[8510] | 123 | new DeprecatedPlugin("Curves", tr("replaced by new {0} plugin", "utilsplugin2")),
|
---|
[10963] | 124 | new DeprecatedPlugin("epsg31287", inCore),
|
---|
[5436] | 125 | new DeprecatedPlugin("licensechange", tr("no longer required")),
|
---|
[10001] | 126 | new DeprecatedPlugin("restart", inCore),
|
---|
| 127 | new DeprecatedPlugin("wayselector", inCore),
|
---|
[10963] | 128 | new DeprecatedPlugin("openstreetbugs", inCore),
|
---|
[7424] | 129 | new DeprecatedPlugin("nearclick", tr("no longer required")),
|
---|
[10001] | 130 | new DeprecatedPlugin("notes", inCore),
|
---|
| 131 | new DeprecatedPlugin("mirrored_download", inCore),
|
---|
| 132 | new DeprecatedPlugin("ImageryCache", inCore),
|
---|
[8943] | 133 | new DeprecatedPlugin("commons-imaging", tr("replaced by new {0} plugin", "apache-commons")),
|
---|
[9141] | 134 | new DeprecatedPlugin("missingRoads", tr("replaced by new {0} plugin", "ImproveOsm")),
|
---|
| 135 | new DeprecatedPlugin("trafficFlowDirection", tr("replaced by new {0} plugin", "ImproveOsm")),
|
---|
[9870] | 136 | new DeprecatedPlugin("kendzi3d-jogl", tr("replaced by new {0} plugin", "jogl")),
|
---|
[10493] | 137 | new DeprecatedPlugin("josm-geojson", tr("replaced by new {0} plugin", "geojson")),
|
---|
[10708] | 138 | new DeprecatedPlugin("proj4j", inCore),
|
---|
[11530] | 139 | new DeprecatedPlugin("OpenStreetView", tr("replaced by new {0} plugin", "OpenStreetCam")),
|
---|
[12279] | 140 | new DeprecatedPlugin("imageryadjust", inCore)
|
---|
| 141 | );
|
---|
[3669] | 142 | }
|
---|
[6839] | 143 |
|
---|
[6360] | 144 | private PluginHandler() {
|
---|
| 145 | // Hide default constructor for utils classes
|
---|
| 146 | }
|
---|
[2554] | 147 |
|
---|
[11974] | 148 | static final class PluginInformationAction extends AbstractAction {
|
---|
| 149 | private final PluginInformation info;
|
---|
| 150 |
|
---|
| 151 | PluginInformationAction(PluginInformation info) {
|
---|
| 152 | super(tr("Information"));
|
---|
| 153 | this.info = info;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | /**
|
---|
| 157 | * Returns plugin information text.
|
---|
| 158 | * @return plugin information text
|
---|
| 159 | */
|
---|
| 160 | public String getText() {
|
---|
| 161 | StringBuilder b = new StringBuilder();
|
---|
| 162 | for (Entry<String, String> e : info.attr.entrySet()) {
|
---|
| 163 | b.append(e.getKey());
|
---|
| 164 | b.append(": ");
|
---|
| 165 | b.append(e.getValue());
|
---|
| 166 | b.append('\n');
|
---|
| 167 | }
|
---|
| 168 | return b.toString();
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | @Override
|
---|
| 172 | public void actionPerformed(ActionEvent event) {
|
---|
| 173 | String text = getText();
|
---|
| 174 | JosmTextArea a = new JosmTextArea(10, 40);
|
---|
| 175 | a.setEditable(false);
|
---|
| 176 | a.setText(text);
|
---|
| 177 | a.setCaretPosition(0);
|
---|
| 178 | if (!GraphicsEnvironment.isHeadless()) {
|
---|
| 179 | JOptionPane.showMessageDialog(Main.parent, new JScrollPane(a), tr("Plugin information"),
|
---|
| 180 | JOptionPane.INFORMATION_MESSAGE);
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[6248] | 185 | /**
|
---|
| 186 | * Description of a deprecated plugin
|
---|
| 187 | */
|
---|
[3730] | 188 | public static class DeprecatedPlugin implements Comparable<DeprecatedPlugin> {
|
---|
[6248] | 189 | /** Plugin name */
|
---|
| 190 | public final String name;
|
---|
| 191 | /** Short explanation about deprecation, can be {@code null} */
|
---|
| 192 | public final String reason;
|
---|
[3730] | 193 |
|
---|
[6248] | 194 | /**
|
---|
| 195 | * Constructs a new {@code DeprecatedPlugin} with a given reason.
|
---|
| 196 | * @param name The plugin name
|
---|
| 197 | * @param reason The reason about deprecation
|
---|
| 198 | */
|
---|
[3730] | 199 | public DeprecatedPlugin(String name, String reason) {
|
---|
| 200 | this.name = name;
|
---|
| 201 | this.reason = reason;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[9870] | 204 | @Override
|
---|
| 205 | public int hashCode() {
|
---|
| 206 | final int prime = 31;
|
---|
| 207 | int result = prime + ((name == null) ? 0 : name.hashCode());
|
---|
| 208 | return prime * result + ((reason == null) ? 0 : reason.hashCode());
|
---|
[3730] | 209 | }
|
---|
| 210 |
|
---|
[6084] | 211 | @Override
|
---|
[9870] | 212 | public boolean equals(Object obj) {
|
---|
| 213 | if (this == obj)
|
---|
| 214 | return true;
|
---|
| 215 | if (obj == null)
|
---|
| 216 | return false;
|
---|
| 217 | if (getClass() != obj.getClass())
|
---|
| 218 | return false;
|
---|
| 219 | DeprecatedPlugin other = (DeprecatedPlugin) obj;
|
---|
| 220 | if (name == null) {
|
---|
| 221 | if (other.name != null)
|
---|
| 222 | return false;
|
---|
| 223 | } else if (!name.equals(other.name))
|
---|
| 224 | return false;
|
---|
| 225 | if (reason == null) {
|
---|
| 226 | if (other.reason != null)
|
---|
| 227 | return false;
|
---|
| 228 | } else if (!reason.equals(other.reason))
|
---|
| 229 | return false;
|
---|
| 230 | return true;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | @Override
|
---|
[3730] | 234 | public int compareTo(DeprecatedPlugin o) {
|
---|
[9870] | 235 | int d = name.compareTo(o.name);
|
---|
| 236 | if (d == 0)
|
---|
| 237 | d = reason.compareTo(o.reason);
|
---|
| 238 | return d;
|
---|
[3730] | 239 | }
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[6248] | 242 | /**
|
---|
[8017] | 243 | * ClassLoader that makes the addURL method of URLClassLoader public.
|
---|
| 244 | *
|
---|
| 245 | * Like URLClassLoader, but allows to add more URLs after construction.
|
---|
| 246 | */
|
---|
| 247 | public static class DynamicURLClassLoader extends URLClassLoader {
|
---|
| 248 |
|
---|
[8453] | 249 | /**
|
---|
| 250 | * Constructs a new {@code DynamicURLClassLoader}.
|
---|
| 251 | * @param urls the URLs from which to load classes and resources
|
---|
| 252 | * @param parent the parent class loader for delegation
|
---|
| 253 | */
|
---|
[8017] | 254 | public DynamicURLClassLoader(URL[] urls, ClassLoader parent) {
|
---|
| 255 | super(urls, parent);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | @Override
|
---|
| 259 | public void addURL(URL url) {
|
---|
| 260 | super.addURL(url);
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | /**
|
---|
[8070] | 265 | * List of unmaintained plugins. Not really up-to-date as the vast majority of plugins are not maintained after a few months, sadly...
|
---|
[6248] | 266 | */
|
---|
[10238] | 267 | static final List<String> UNMAINTAINED_PLUGINS = Collections.unmodifiableList(Arrays.asList(
|
---|
[11345] | 268 | "NanoLog", // See https://trac.openstreetmap.org/changeset/29404/subversion
|
---|
| 269 | "irsrectify", // See https://trac.openstreetmap.org/changeset/29404/subversion
|
---|
| 270 | "surveyor2", // See https://trac.openstreetmap.org/changeset/29404/subversion
|
---|
[8453] | 271 | "gpsbabelgui",
|
---|
| 272 | "Intersect_way",
|
---|
| 273 | "ContourOverlappingMerge", // See #11202, #11518, https://github.com/bularcasergiu/ContourOverlappingMerge/issues/1
|
---|
[8944] | 274 | "LaneConnector", // See #11468, #11518, https://github.com/TrifanAdrian/LanecConnectorPlugin/issues/1
|
---|
| 275 | "Remove.redundant.points" // See #11468, #11518, https://github.com/bularcasergiu/RemoveRedundantPoints (not even created an issue...)
|
---|
[10238] | 276 | ));
|
---|
[6070] | 277 |
|
---|
[5145] | 278 | /**
|
---|
| 279 | * Default time-based update interval, in days (pluginmanager.time-based-update.interval)
|
---|
| 280 | */
|
---|
| 281 | public static final int DEFAULT_TIME_BASED_UPDATE_INTERVAL = 30;
|
---|
[2817] | 282 |
|
---|
[1326] | 283 | /**
|
---|
| 284 | * All installed and loaded plugins (resp. their main classes)
|
---|
| 285 | */
|
---|
[10987] | 286 | static final Collection<PluginProxy> pluginList = new LinkedList<>();
|
---|
[2817] | 287 |
|
---|
[1326] | 288 | /**
|
---|
[8938] | 289 | * All exceptions that occured during plugin loading
|
---|
| 290 | */
|
---|
[12599] | 291 | static final Map<String, Throwable> pluginLoadingExceptions = new HashMap<>();
|
---|
[8938] | 292 |
|
---|
| 293 | /**
|
---|
[12322] | 294 | * Class loader to locate resources from plugins.
|
---|
| 295 | * @see #getJoinedPluginResourceCL()
|
---|
[8017] | 296 | */
|
---|
[12322] | 297 | private static DynamicURLClassLoader joinedPluginResourceCL;
|
---|
[8017] | 298 |
|
---|
| 299 | /**
|
---|
[3874] | 300 | * Add here all ClassLoader whose resource should be searched.
|
---|
| 301 | */
|
---|
[7005] | 302 | private static final List<ClassLoader> sources = new LinkedList<>();
|
---|
[3874] | 303 | static {
|
---|
| 304 | try {
|
---|
| 305 | sources.add(ClassLoader.getSystemClassLoader());
|
---|
| 306 | sources.add(org.openstreetmap.josm.gui.MainApplication.class.getClassLoader());
|
---|
| 307 | } catch (SecurityException ex) {
|
---|
[12620] | 308 | Logging.debug(ex);
|
---|
[3874] | 309 | sources.add(ImageProvider.class.getClassLoader());
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
[6839] | 312 |
|
---|
[8840] | 313 | private static PluginDownloadTask pluginDownloadTask;
|
---|
[3874] | 314 |
|
---|
[10982] | 315 | /**
|
---|
| 316 | * Returns the list of currently installed and loaded plugins.
|
---|
| 317 | * @return the list of currently installed and loaded plugins
|
---|
| 318 | * @since 10982
|
---|
| 319 | */
|
---|
| 320 | public static List<PluginInformation> getPlugins() {
|
---|
| 321 | return pluginList.stream().map(PluginProxy::getPluginInformation).collect(Collectors.toList());
|
---|
| 322 | }
|
---|
| 323 |
|
---|
[11904] | 324 | /**
|
---|
| 325 | * Returns all ClassLoaders whose resource should be searched.
|
---|
| 326 | * @return all ClassLoaders whose resource should be searched
|
---|
| 327 | */
|
---|
[3874] | 328 | public static Collection<ClassLoader> getResourceClassLoaders() {
|
---|
| 329 | return Collections.unmodifiableCollection(sources);
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | /**
|
---|
[2817] | 333 | * Removes deprecated plugins from a collection of plugins. Modifies the
|
---|
| 334 | * collection <code>plugins</code>.
|
---|
[3232] | 335 | *
|
---|
[2817] | 336 | * Also notifies the user about removed deprecated plugins
|
---|
[3232] | 337 | *
|
---|
[5121] | 338 | * @param parent The parent Component used to display warning popup
|
---|
[2817] | 339 | * @param plugins the collection of plugins
|
---|
[1326] | 340 | */
|
---|
[10093] | 341 | static void filterDeprecatedPlugins(Component parent, Collection<String> plugins) {
|
---|
[7005] | 342 | Set<DeprecatedPlugin> removedPlugins = new TreeSet<>();
|
---|
[3730] | 343 | for (DeprecatedPlugin depr : DEPRECATED_PLUGINS) {
|
---|
| 344 | if (plugins.contains(depr.name)) {
|
---|
| 345 | plugins.remove(depr.name);
|
---|
| 346 | Main.pref.removeFromCollection("plugins", depr.name);
|
---|
| 347 | removedPlugins.add(depr);
|
---|
[1326] | 348 | }
|
---|
| 349 | }
|
---|
[2817] | 350 | if (removedPlugins.isEmpty())
|
---|
| 351 | return;
|
---|
| 352 |
|
---|
| 353 | // notify user about removed deprecated plugins
|
---|
| 354 | //
|
---|
[8938] | 355 | StringBuilder sb = new StringBuilder(32);
|
---|
[8379] | 356 | sb.append("<html>")
|
---|
| 357 | .append(trn(
|
---|
[2817] | 358 | "The following plugin is no longer necessary and has been deactivated:",
|
---|
| 359 | "The following plugins are no longer necessary and have been deactivated:",
|
---|
[8379] | 360 | removedPlugins.size()))
|
---|
| 361 | .append("<ul>");
|
---|
[3730] | 362 | for (DeprecatedPlugin depr: removedPlugins) {
|
---|
| 363 | sb.append("<li>").append(depr.name);
|
---|
| 364 | if (depr.reason != null) {
|
---|
[8390] | 365 | sb.append(" (").append(depr.reason).append(')');
|
---|
[3669] | 366 | }
|
---|
| 367 | sb.append("</li>");
|
---|
[2259] | 368 | }
|
---|
[8390] | 369 | sb.append("</ul></html>");
|
---|
[10093] | 370 | if (!GraphicsEnvironment.isHeadless()) {
|
---|
| 371 | JOptionPane.showMessageDialog(
|
---|
| 372 | parent,
|
---|
| 373 | sb.toString(),
|
---|
| 374 | tr("Warning"),
|
---|
| 375 | JOptionPane.WARNING_MESSAGE
|
---|
| 376 | );
|
---|
| 377 | }
|
---|
[2817] | 378 | }
|
---|
[1326] | 379 |
|
---|
[2817] | 380 | /**
|
---|
| 381 | * Removes unmaintained plugins from a collection of plugins. Modifies the
|
---|
| 382 | * collection <code>plugins</code>. Also removes the plugin from the list
|
---|
| 383 | * of plugins in the preferences, if necessary.
|
---|
[3232] | 384 | *
|
---|
[2817] | 385 | * Asks the user for every unmaintained plugin whether it should be removed.
|
---|
[8938] | 386 | * @param parent The parent Component used to display warning popup
|
---|
[3232] | 387 | *
|
---|
[2817] | 388 | * @param plugins the collection of plugins
|
---|
| 389 | */
|
---|
[10093] | 390 | static void filterUnmaintainedPlugins(Component parent, Collection<String> plugins) {
|
---|
[2817] | 391 | for (String unmaintained : UNMAINTAINED_PLUGINS) {
|
---|
| 392 | if (!plugins.contains(unmaintained)) {
|
---|
| 393 | continue;
|
---|
[2372] | 394 | }
|
---|
[8938] | 395 | String msg = tr("<html>Loading of the plugin \"{0}\" was requested."
|
---|
[2817] | 396 | + "<br>This plugin is no longer developed and very likely will produce errors."
|
---|
[11848] | 397 | +"<br>It should be disabled.<br>Delete from preferences?</html>",
|
---|
| 398 | Utils.escapeReservedCharactersHTML(unmaintained));
|
---|
[8510] | 399 | if (confirmDisablePlugin(parent, msg, unmaintained)) {
|
---|
[2817] | 400 | Main.pref.removeFromCollection("plugins", unmaintained);
|
---|
| 401 | plugins.remove(unmaintained);
|
---|
[2372] | 402 | }
|
---|
[2817] | 403 | }
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | /**
|
---|
| 407 | * Checks whether the locally available plugins should be updated and
|
---|
| 408 | * asks the user if running an update is OK. An update is advised if
|
---|
| 409 | * JOSM was updated to a new version since the last plugin updates or
|
---|
| 410 | * if the plugins were last updated a long time ago.
|
---|
[3232] | 411 | *
|
---|
[5121] | 412 | * @param parent the parent component relative to which the confirmation dialog
|
---|
[2856] | 413 | * is to be displayed
|
---|
[2817] | 414 | * @return true if a plugin update should be run; false, otherwise
|
---|
| 415 | */
|
---|
[5121] | 416 | public static boolean checkAndConfirmPluginUpdate(Component parent) {
|
---|
[7434] | 417 | if (!checkOfflineAccess()) {
|
---|
[12620] | 418 | Logging.info(tr("{0} not available (offline mode)", tr("Plugin update")));
|
---|
[7434] | 419 | return false;
|
---|
| 420 | }
|
---|
[2817] | 421 | String message = null;
|
---|
| 422 | String togglePreferenceKey = null;
|
---|
| 423 | int v = Version.getInstance().getVersion();
|
---|
[12841] | 424 | if (Main.pref.getInt("pluginmanager.version", 0) < v) {
|
---|
[2856] | 425 | message =
|
---|
| 426 | "<html>"
|
---|
| 427 | + tr("You updated your JOSM software.<br>"
|
---|
| 428 | + "To prevent problems the plugins should be updated as well.<br><br>"
|
---|
| 429 | + "Update plugins now?"
|
---|
| 430 | )
|
---|
| 431 | + "</html>";
|
---|
[2924] | 432 | togglePreferenceKey = "pluginmanager.version-based-update.policy";
|
---|
[10378] | 433 | } else {
|
---|
[2817] | 434 | long tim = System.currentTimeMillis();
|
---|
| 435 | long last = Main.pref.getLong("pluginmanager.lastupdate", 0);
|
---|
[12841] | 436 | Integer maxTime = Main.pref.getInt("pluginmanager.time-based-update.interval", DEFAULT_TIME_BASED_UPDATE_INTERVAL);
|
---|
[11288] | 437 | long d = TimeUnit.MILLISECONDS.toDays(tim - last);
|
---|
[2817] | 438 | if ((last <= 0) || (maxTime <= 0)) {
|
---|
| 439 | Main.pref.put("pluginmanager.lastupdate", Long.toString(tim));
|
---|
| 440 | } else if (d > maxTime) {
|
---|
[2856] | 441 | message =
|
---|
| 442 | "<html>"
|
---|
| 443 | + tr("Last plugin update more than {0} days ago.", d)
|
---|
| 444 | + "</html>";
|
---|
[2924] | 445 | togglePreferenceKey = "pluginmanager.time-based-update.policy";
|
---|
[2372] | 446 | }
|
---|
| 447 | }
|
---|
[2817] | 448 | if (message == null) return false;
|
---|
[2372] | 449 |
|
---|
[2856] | 450 | UpdatePluginsMessagePanel pnlMessage = new UpdatePluginsMessagePanel();
|
---|
| 451 | pnlMessage.setMessage(message);
|
---|
| 452 | pnlMessage.initDontShowAgain(togglePreferenceKey);
|
---|
| 453 |
|
---|
[2866] | 454 | // check whether automatic update at startup was disabled
|
---|
| 455 | //
|
---|
[8404] | 456 | String policy = Main.pref.get(togglePreferenceKey, "ask").trim().toLowerCase(Locale.ENGLISH);
|
---|
[7012] | 457 | switch(policy) {
|
---|
| 458 | case "never":
|
---|
[2990] | 459 | if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
|
---|
[12620] | 460 | Logging.info(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
|
---|
[2990] | 461 | } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
|
---|
[12620] | 462 | Logging.info(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
|
---|
[2924] | 463 | }
|
---|
| 464 | return false;
|
---|
[2866] | 465 |
|
---|
[7012] | 466 | case "always":
|
---|
[5029] | 467 | if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
|
---|
[12620] | 468 | Logging.info(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
|
---|
[2990] | 469 | } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
|
---|
[12620] | 470 | Logging.info(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
|
---|
[2924] | 471 | }
|
---|
| 472 | return true;
|
---|
[7348] | 473 |
|
---|
[7012] | 474 | case "ask":
|
---|
| 475 | break;
|
---|
[2924] | 476 |
|
---|
[7012] | 477 | default:
|
---|
[12620] | 478 | Logging.warn(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey));
|
---|
[2924] | 479 | }
|
---|
[7012] | 480 |
|
---|
[9062] | 481 | ButtonSpec[] options = new ButtonSpec[] {
|
---|
| 482 | new ButtonSpec(
|
---|
| 483 | tr("Update plugins"),
|
---|
| 484 | ImageProvider.get("dialogs", "refresh"),
|
---|
| 485 | tr("Click to update the activated plugins"),
|
---|
| 486 | null /* no specific help context */
|
---|
| 487 | ),
|
---|
| 488 | new ButtonSpec(
|
---|
| 489 | tr("Skip update"),
|
---|
| 490 | ImageProvider.get("cancel"),
|
---|
| 491 | tr("Click to skip updating the activated plugins"),
|
---|
| 492 | null /* no specific help context */
|
---|
| 493 | )
|
---|
| 494 | };
|
---|
| 495 |
|
---|
[2856] | 496 | int ret = HelpAwareOptionPane.showOptionDialog(
|
---|
| 497 | parent,
|
---|
| 498 | pnlMessage,
|
---|
[2817] | 499 | tr("Update plugins"),
|
---|
[2856] | 500 | JOptionPane.WARNING_MESSAGE,
|
---|
| 501 | null,
|
---|
| 502 | options,
|
---|
| 503 | options[0],
|
---|
[2924] | 504 | ht("/Preferences/Plugins#AutomaticUpdate")
|
---|
[2817] | 505 | );
|
---|
[2856] | 506 |
|
---|
[2924] | 507 | if (pnlMessage.isRememberDecision()) {
|
---|
| 508 | switch(ret) {
|
---|
| 509 | case 0:
|
---|
| 510 | Main.pref.put(togglePreferenceKey, "always");
|
---|
| 511 | break;
|
---|
| 512 | case JOptionPane.CLOSED_OPTION:
|
---|
| 513 | case 1:
|
---|
| 514 | Main.pref.put(togglePreferenceKey, "never");
|
---|
| 515 | break;
|
---|
[10216] | 516 | default: // Do nothing
|
---|
[2924] | 517 | }
|
---|
| 518 | } else {
|
---|
| 519 | Main.pref.put(togglePreferenceKey, "ask");
|
---|
| 520 | }
|
---|
[2856] | 521 | return ret == 0;
|
---|
[2817] | 522 | }
|
---|
[2278] | 523 |
|
---|
[7434] | 524 | private static boolean checkOfflineAccess() {
|
---|
| 525 | if (Main.isOffline(OnlineResource.ALL)) {
|
---|
| 526 | return false;
|
---|
| 527 | }
|
---|
| 528 | if (Main.isOffline(OnlineResource.JOSM_WEBSITE)) {
|
---|
| 529 | for (String updateSite : Main.pref.getPluginSites()) {
|
---|
| 530 | try {
|
---|
| 531 | OnlineResource.JOSM_WEBSITE.checkOfflineAccess(updateSite, Main.getJOSMWebsite());
|
---|
| 532 | } catch (OfflineAccessException e) {
|
---|
[12620] | 533 | Logging.trace(e);
|
---|
[7434] | 534 | return false;
|
---|
| 535 | }
|
---|
| 536 | }
|
---|
| 537 | }
|
---|
| 538 | return true;
|
---|
| 539 | }
|
---|
| 540 |
|
---|
[2817] | 541 | /**
|
---|
[8795] | 542 | * Alerts the user if a plugin required by another plugin is missing, and offer to download them & restart JOSM
|
---|
[3232] | 543 | *
|
---|
[5121] | 544 | * @param parent The parent Component used to display error popup
|
---|
[4310] | 545 | * @param plugin the plugin
|
---|
[2817] | 546 | * @param missingRequiredPlugin the missing required plugin
|
---|
| 547 | */
|
---|
[5121] | 548 | private static void alertMissingRequiredPlugin(Component parent, String plugin, Set<String> missingRequiredPlugin) {
|
---|
[8471] | 549 | StringBuilder sb = new StringBuilder(48);
|
---|
[8379] | 550 | sb.append("<html>")
|
---|
| 551 | .append(trn("Plugin {0} requires a plugin which was not found. The missing plugin is:",
|
---|
[2858] | 552 | "Plugin {0} requires {1} plugins which were not found. The missing plugins are:",
|
---|
[2817] | 553 | missingRequiredPlugin.size(),
|
---|
[11848] | 554 | Utils.escapeReservedCharactersHTML(plugin),
|
---|
[8379] | 555 | missingRequiredPlugin.size()))
|
---|
| 556 | .append(Utils.joinAsHtmlUnorderedList(missingRequiredPlugin))
|
---|
| 557 | .append("</html>");
|
---|
[8471] | 558 | ButtonSpec[] specs = new ButtonSpec[] {
|
---|
| 559 | new ButtonSpec(
|
---|
| 560 | tr("Download and restart"),
|
---|
| 561 | ImageProvider.get("restart"),
|
---|
| 562 | trn("Click to download missing plugin and restart JOSM",
|
---|
| 563 | "Click to download missing plugins and restart JOSM",
|
---|
| 564 | missingRequiredPlugin.size()),
|
---|
| 565 | null /* no specific help text */
|
---|
| 566 | ),
|
---|
| 567 | new ButtonSpec(
|
---|
| 568 | tr("Continue"),
|
---|
| 569 | ImageProvider.get("ok"),
|
---|
| 570 | trn("Click to continue without this plugin",
|
---|
| 571 | "Click to continue without these plugins",
|
---|
| 572 | missingRequiredPlugin.size()),
|
---|
| 573 | null /* no specific help text */
|
---|
| 574 | )
|
---|
| 575 | };
|
---|
| 576 | if (0 == HelpAwareOptionPane.showOptionDialog(
|
---|
[2856] | 577 | parent,
|
---|
[2817] | 578 | sb.toString(),
|
---|
| 579 | tr("Error"),
|
---|
[8471] | 580 | JOptionPane.ERROR_MESSAGE,
|
---|
| 581 | null, /* no special icon */
|
---|
| 582 | specs,
|
---|
| 583 | specs[0],
|
---|
[9972] | 584 | ht("/Plugin/Loading#MissingRequiredPlugin"))) {
|
---|
[8471] | 585 | downloadRequiredPluginsAndRestart(parent, missingRequiredPlugin);
|
---|
| 586 | }
|
---|
[2817] | 587 | }
|
---|
| 588 |
|
---|
[8471] | 589 | private static void downloadRequiredPluginsAndRestart(final Component parent, final Set<String> missingRequiredPlugin) {
|
---|
| 590 | // Update plugin list
|
---|
| 591 | final ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask(
|
---|
| 592 | Main.pref.getOnlinePluginSites());
|
---|
[12634] | 593 | MainApplication.worker.submit(pluginInfoDownloadTask);
|
---|
[8471] | 594 |
|
---|
| 595 | // Continuation
|
---|
[12634] | 596 | MainApplication.worker.submit(() -> {
|
---|
[10616] | 597 | // Build list of plugins to download
|
---|
| 598 | Set<PluginInformation> toDownload = new HashSet<>(pluginInfoDownloadTask.getAvailablePlugins());
|
---|
[11339] | 599 | toDownload.removeIf(info -> !missingRequiredPlugin.contains(info.getName()));
|
---|
[10616] | 600 | // Check if something has still to be downloaded
|
---|
| 601 | if (!toDownload.isEmpty()) {
|
---|
| 602 | // download plugins
|
---|
| 603 | final PluginDownloadTask task = new PluginDownloadTask(parent, toDownload, tr("Download plugins"));
|
---|
[12634] | 604 | MainApplication.worker.submit(task);
|
---|
| 605 | MainApplication.worker.submit(() -> {
|
---|
[10616] | 606 | // restart if some plugins have been downloaded
|
---|
| 607 | if (!task.getDownloadedPlugins().isEmpty()) {
|
---|
| 608 | // update plugin list in preferences
|
---|
[12841] | 609 | Set<String> plugins = new HashSet<>(Main.pref.getList("plugins"));
|
---|
[10616] | 610 | for (PluginInformation plugin : task.getDownloadedPlugins()) {
|
---|
| 611 | plugins.add(plugin.name);
|
---|
[8471] | 612 | }
|
---|
[12841] | 613 | Main.pref.putList("plugins", new ArrayList<>(plugins));
|
---|
[10616] | 614 | // restart
|
---|
[12273] | 615 | try {
|
---|
| 616 | RestartAction.restartJOSM();
|
---|
| 617 | } catch (IOException e) {
|
---|
[12620] | 618 | Logging.error(e);
|
---|
[12273] | 619 | }
|
---|
[10616] | 620 | } else {
|
---|
[12620] | 621 | Logging.warn("No plugin downloaded, restart canceled");
|
---|
[10616] | 622 | }
|
---|
| 623 | });
|
---|
| 624 | } else {
|
---|
[12620] | 625 | Logging.warn("No plugin to download, operation canceled");
|
---|
[8471] | 626 | }
|
---|
| 627 | });
|
---|
| 628 | }
|
---|
| 629 |
|
---|
[5121] | 630 | private static void alertJOSMUpdateRequired(Component parent, String plugin, int requiredVersion) {
|
---|
[2856] | 631 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 632 | parent,
|
---|
[2858] | 633 | tr("<html>Plugin {0} requires JOSM version {1}. The current JOSM version is {2}.<br>"
|
---|
[2856] | 634 | +"You have to update JOSM in order to use this plugin.</html>",
|
---|
[4470] | 635 | plugin, Integer.toString(requiredVersion), Version.getInstance().getVersionString()
|
---|
[2856] | 636 | ),
|
---|
| 637 | tr("Warning"),
|
---|
| 638 | JOptionPane.WARNING_MESSAGE,
|
---|
[9972] | 639 | ht("/Plugin/Loading#JOSMUpdateRequired")
|
---|
[2856] | 640 | );
|
---|
| 641 | }
|
---|
| 642 |
|
---|
[2817] | 643 | /**
|
---|
| 644 | * Checks whether all preconditions for loading the plugin <code>plugin</code> are met. The
|
---|
| 645 | * current JOSM version must be compatible with the plugin and no other plugins this plugin
|
---|
| 646 | * depends on should be missing.
|
---|
[3232] | 647 | *
|
---|
[5121] | 648 | * @param parent The parent Component used to display error popup
|
---|
[2817] | 649 | * @param plugins the collection of all loaded plugins
|
---|
| 650 | * @param plugin the plugin for which preconditions are checked
|
---|
| 651 | * @return true, if the preconditions are met; false otherwise
|
---|
| 652 | */
|
---|
[5121] | 653 | public static boolean checkLoadPreconditions(Component parent, Collection<PluginInformation> plugins, PluginInformation plugin) {
|
---|
[2817] | 654 |
|
---|
| 655 | // make sure the plugin is compatible with the current JOSM version
|
---|
| 656 | //
|
---|
| 657 | int josmVersion = Version.getInstance().getVersion();
|
---|
[4737] | 658 | if (plugin.localmainversion > josmVersion && josmVersion != Version.JOSM_UNKNOWN_VERSION) {
|
---|
| 659 | alertJOSMUpdateRequired(parent, plugin.name, plugin.localmainversion);
|
---|
[2817] | 660 | return false;
|
---|
| 661 | }
|
---|
[6070] | 662 |
|
---|
[5987] | 663 | // Add all plugins already loaded (to include early plugins when checking late ones)
|
---|
[7005] | 664 | Collection<PluginInformation> allPlugins = new HashSet<>(plugins);
|
---|
[5987] | 665 | for (PluginProxy proxy : pluginList) {
|
---|
| 666 | allPlugins.add(proxy.getPluginInformation());
|
---|
| 667 | }
|
---|
[2817] | 668 |
|
---|
[5987] | 669 | return checkRequiredPluginsPreconditions(parent, allPlugins, plugin, true);
|
---|
[5121] | 670 | }
|
---|
| 671 |
|
---|
| 672 | /**
|
---|
| 673 | * Checks if required plugins preconditions for loading the plugin <code>plugin</code> are met.
|
---|
| 674 | * No other plugins this plugin depends on should be missing.
|
---|
| 675 | *
|
---|
[8074] | 676 | * @param parent The parent Component used to display error popup. If parent is
|
---|
| 677 | * null, the error popup is suppressed
|
---|
[5121] | 678 | * @param plugins the collection of all loaded plugins
|
---|
| 679 | * @param plugin the plugin for which preconditions are checked
|
---|
[5601] | 680 | * @param local Determines if the local or up-to-date plugin dependencies are to be checked.
|
---|
[5121] | 681 | * @return true, if the preconditions are met; false otherwise
|
---|
[5601] | 682 | * @since 5601
|
---|
[5121] | 683 | */
|
---|
[8509] | 684 | public static boolean checkRequiredPluginsPreconditions(Component parent, Collection<PluginInformation> plugins,
|
---|
| 685 | PluginInformation plugin, boolean local) {
|
---|
[5121] | 686 |
|
---|
[5601] | 687 | String requires = local ? plugin.localrequires : plugin.requires;
|
---|
[6070] | 688 |
|
---|
[2817] | 689 | // make sure the dependencies to other plugins are not broken
|
---|
| 690 | //
|
---|
[5601] | 691 | if (requires != null) {
|
---|
[7005] | 692 | Set<String> pluginNames = new HashSet<>();
|
---|
[2817] | 693 | for (PluginInformation pi: plugins) {
|
---|
| 694 | pluginNames.add(pi.name);
|
---|
| 695 | }
|
---|
[7005] | 696 | Set<String> missingPlugins = new HashSet<>();
|
---|
[5601] | 697 | List<String> requiredPlugins = local ? plugin.getLocalRequiredPlugins() : plugin.getRequiredPlugins();
|
---|
| 698 | for (String requiredPlugin : requiredPlugins) {
|
---|
[2817] | 699 | if (!pluginNames.contains(requiredPlugin)) {
|
---|
| 700 | missingPlugins.add(requiredPlugin);
|
---|
[1326] | 701 | }
|
---|
| 702 | }
|
---|
[2817] | 703 | if (!missingPlugins.isEmpty()) {
|
---|
[8074] | 704 | if (parent != null) {
|
---|
| 705 | alertMissingRequiredPlugin(parent, plugin.name, missingPlugins);
|
---|
| 706 | }
|
---|
[2817] | 707 | return false;
|
---|
| 708 | }
|
---|
[1326] | 709 | }
|
---|
[2817] | 710 | return true;
|
---|
| 711 | }
|
---|
[1326] | 712 |
|
---|
[2817] | 713 | /**
|
---|
[12322] | 714 | * Method to get the (now obsolete) class loader for loading plugin code.
|
---|
[3232] | 715 | *
|
---|
[2817] | 716 | * @return the class loader
|
---|
[12322] | 717 | * @deprecated There is no longer a unified plugin class loader. Use {@link PluginProxy#classLoader}
|
---|
| 718 | * to get the class loader for each plugin. Or <code>PluginClass.class.getClassLoader()</code>
|
---|
| 719 | * to access the class loader from within the plugin.
|
---|
[2817] | 720 | */
|
---|
[12322] | 721 | @Deprecated
|
---|
[8126] | 722 | public static synchronized DynamicURLClassLoader getPluginClassLoader() {
|
---|
[12322] | 723 | return getJoinedPluginResourceCL();
|
---|
| 724 | }
|
---|
| 725 |
|
---|
| 726 | /**
|
---|
| 727 | * Get class loader to locate resources from plugins.
|
---|
| 728 | *
|
---|
| 729 | * It joins URLs of all plugins, to find images, etc.
|
---|
| 730 | * (Not for loading Java classes - each plugin has a separate {@link PluginClassLoader}
|
---|
| 731 | * for that purpose.)
|
---|
| 732 | * @return class loader to locate resources from plugins
|
---|
| 733 | */
|
---|
| 734 | private static synchronized DynamicURLClassLoader getJoinedPluginResourceCL() {
|
---|
| 735 | if (joinedPluginResourceCL == null) {
|
---|
| 736 | joinedPluginResourceCL = AccessController.doPrivileged((PrivilegedAction<DynamicURLClassLoader>)
|
---|
[12627] | 737 | () -> new DynamicURLClassLoader(new URL[0], PluginHandler.class.getClassLoader()));
|
---|
[12322] | 738 | sources.add(0, joinedPluginResourceCL);
|
---|
[8017] | 739 | }
|
---|
[12322] | 740 | return joinedPluginResourceCL;
|
---|
[8017] | 741 | }
|
---|
| 742 |
|
---|
| 743 | /**
|
---|
[12322] | 744 | * Add more plugins to the joined plugin resource class loader.
|
---|
[8017] | 745 | *
|
---|
[12322] | 746 | * @param plugins the plugins to add
|
---|
[8017] | 747 | */
|
---|
[12322] | 748 | private static void extendJoinedPluginResourceCL(Collection<PluginInformation> plugins) {
|
---|
[1326] | 749 | // iterate all plugins and collect all libraries of all plugins:
|
---|
[2817] | 750 | File pluginDir = Main.pref.getPluginsDirectory();
|
---|
[12322] | 751 | DynamicURLClassLoader cl = getJoinedPluginResourceCL();
|
---|
[6070] | 752 |
|
---|
[8017] | 753 | for (PluginInformation info : plugins) {
|
---|
[2817] | 754 | if (info.libraries == null) {
|
---|
| 755 | continue;
|
---|
[1860] | 756 | }
|
---|
[8017] | 757 | for (URL libUrl : info.libraries) {
|
---|
| 758 | cl.addURL(libUrl);
|
---|
| 759 | }
|
---|
[2817] | 760 | File pluginJar = new File(pluginDir, info.name + ".jar");
|
---|
[4159] | 761 | I18n.addTexts(pluginJar);
|
---|
[6615] | 762 | URL pluginJarUrl = Utils.fileToURL(pluginJar);
|
---|
[8017] | 763 | cl.addURL(pluginJarUrl);
|
---|
[1860] | 764 | }
|
---|
[2817] | 765 | }
|
---|
[1326] | 766 |
|
---|
[2817] | 767 | /**
|
---|
| 768 | * Loads and instantiates the plugin described by <code>plugin</code> using
|
---|
| 769 | * the class loader <code>pluginClassLoader</code>.
|
---|
[3232] | 770 | *
|
---|
[6248] | 771 | * @param parent The parent component to be used for the displayed dialog
|
---|
[2817] | 772 | * @param plugin the plugin
|
---|
| 773 | * @param pluginClassLoader the plugin class loader
|
---|
| 774 | */
|
---|
[12322] | 775 | private static void loadPlugin(Component parent, PluginInformation plugin, PluginClassLoader pluginClassLoader) {
|
---|
[3297] | 776 | String msg = tr("Could not load plugin {0}. Delete from preferences?", plugin.name);
|
---|
[2817] | 777 | try {
|
---|
| 778 | Class<?> klass = plugin.loadClass(pluginClassLoader);
|
---|
| 779 | if (klass != null) {
|
---|
[12620] | 780 | Logging.info(tr("loading plugin ''{0}'' (version {1})", plugin.name, plugin.localversion));
|
---|
[12322] | 781 | PluginProxy pluginProxy = plugin.load(klass, pluginClassLoader);
|
---|
[5957] | 782 | pluginList.add(pluginProxy);
|
---|
[12639] | 783 | MainApplication.addAndFireMapFrameListener(pluginProxy);
|
---|
[2817] | 784 | }
|
---|
[3297] | 785 | msg = null;
|
---|
[5723] | 786 | } catch (PluginException e) {
|
---|
[8938] | 787 | pluginLoadingExceptions.put(plugin.name, e);
|
---|
[12620] | 788 | Logging.error(e);
|
---|
[3090] | 789 | if (e.getCause() instanceof ClassNotFoundException) {
|
---|
[3297] | 790 | msg = tr("<html>Could not load plugin {0} because the plugin<br>main class ''{1}'' was not found.<br>"
|
---|
[11848] | 791 | + "Delete from preferences?</html>", Utils.escapeReservedCharactersHTML(plugin.name), plugin.className);
|
---|
[3090] | 792 | }
|
---|
[11746] | 793 | } catch (RuntimeException e) { // NOPMD
|
---|
[8938] | 794 | pluginLoadingExceptions.put(plugin.name, e);
|
---|
[12620] | 795 | Logging.error(e);
|
---|
[2817] | 796 | }
|
---|
[6248] | 797 | if (msg != null && confirmDisablePlugin(parent, msg, plugin.name)) {
|
---|
[3297] | 798 | Main.pref.removeFromCollection("plugins", plugin.name);
|
---|
[4043] | 799 | }
|
---|
[2817] | 800 | }
|
---|
| 801 |
|
---|
| 802 | /**
|
---|
[8471] | 803 | * Loads the plugin in <code>plugins</code> from locally available jar files into memory.
|
---|
[3232] | 804 | *
|
---|
[6248] | 805 | * @param parent The parent component to be used for the displayed dialog
|
---|
[2817] | 806 | * @param plugins the list of plugins
|
---|
[5266] | 807 | * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
|
---|
[2817] | 808 | */
|
---|
[8017] | 809 | public static void loadPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) {
|
---|
[2817] | 810 | if (monitor == null) {
|
---|
| 811 | monitor = NullProgressMonitor.INSTANCE;
|
---|
| 812 | }
|
---|
| 813 | try {
|
---|
| 814 | monitor.beginTask(tr("Loading plugins ..."));
|
---|
[2864] | 815 | monitor.subTask(tr("Checking plugin preconditions..."));
|
---|
[7005] | 816 | List<PluginInformation> toLoad = new LinkedList<>();
|
---|
[2864] | 817 | for (PluginInformation pi: plugins) {
|
---|
| 818 | if (checkLoadPreconditions(parent, plugins, pi)) {
|
---|
| 819 | toLoad.add(pi);
|
---|
| 820 | }
|
---|
| 821 | }
|
---|
[2817] | 822 | // sort the plugins according to their "staging" equivalence class. The
|
---|
| 823 | // lower the value of "stage" the earlier the plugin should be loaded.
|
---|
| 824 | //
|
---|
[10647] | 825 | toLoad.sort(Comparator.comparingInt(o -> o.stage));
|
---|
[2817] | 826 | if (toLoad.isEmpty())
|
---|
| 827 | return;
|
---|
| 828 |
|
---|
[12322] | 829 | Map<PluginInformation, PluginClassLoader> classLoaders = new HashMap<>();
|
---|
| 830 | for (PluginInformation info : toLoad) {
|
---|
[12323] | 831 | PluginClassLoader cl = AccessController.doPrivileged((PrivilegedAction<PluginClassLoader>)
|
---|
| 832 | () -> new PluginClassLoader(
|
---|
[12322] | 833 | info.libraries.toArray(new URL[0]),
|
---|
[12627] | 834 | PluginHandler.class.getClassLoader(),
|
---|
[12322] | 835 | null));
|
---|
[12323] | 836 | classLoaders.put(info, cl);
|
---|
[12322] | 837 | }
|
---|
| 838 |
|
---|
| 839 | // resolve dependencies
|
---|
| 840 | for (PluginInformation info : toLoad) {
|
---|
| 841 | PluginClassLoader cl = classLoaders.get(info);
|
---|
| 842 | DEPENDENCIES:
|
---|
| 843 | for (String depName : info.getRequiredPlugins()) {
|
---|
| 844 | for (PluginInformation depInfo : toLoad) {
|
---|
| 845 | if (depInfo.getName().equals(depName)) {
|
---|
| 846 | cl.addDependency(classLoaders.get(depInfo));
|
---|
| 847 | continue DEPENDENCIES;
|
---|
| 848 | }
|
---|
| 849 | }
|
---|
| 850 | for (PluginProxy proxy : pluginList) {
|
---|
| 851 | if (proxy.getPluginInformation().getName().equals(depName)) {
|
---|
| 852 | cl.addDependency(proxy.getClassLoader());
|
---|
| 853 | continue DEPENDENCIES;
|
---|
| 854 | }
|
---|
| 855 | }
|
---|
| 856 | throw new AssertionError("unable to find dependency " + depName + " for plugin " + info.getName());
|
---|
| 857 | }
|
---|
| 858 | }
|
---|
| 859 |
|
---|
| 860 | extendJoinedPluginResourceCL(toLoad);
|
---|
[2817] | 861 | monitor.setTicksCount(toLoad.size());
|
---|
| 862 | for (PluginInformation info : toLoad) {
|
---|
| 863 | monitor.setExtraText(tr("Loading plugin ''{0}''...", info.name));
|
---|
[12322] | 864 | loadPlugin(parent, info, classLoaders.get(info));
|
---|
[2817] | 865 | monitor.worked(1);
|
---|
| 866 | }
|
---|
| 867 | } finally {
|
---|
| 868 | monitor.finishTask();
|
---|
[1326] | 869 | }
|
---|
| 870 | }
|
---|
[2817] | 871 |
|
---|
| 872 | /**
|
---|
[8453] | 873 | * Loads plugins from <code>plugins</code> which have the flag {@link PluginInformation#early} set to true.
|
---|
[3232] | 874 | *
|
---|
[8453] | 875 | * @param parent The parent component to be used for the displayed dialog
|
---|
[2817] | 876 | * @param plugins the collection of plugins
|
---|
[5266] | 877 | * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
|
---|
[2817] | 878 | */
|
---|
[5121] | 879 | public static void loadEarlyPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) {
|
---|
[7005] | 880 | List<PluginInformation> earlyPlugins = new ArrayList<>(plugins.size());
|
---|
[2817] | 881 | for (PluginInformation pi: plugins) {
|
---|
| 882 | if (pi.early) {
|
---|
| 883 | earlyPlugins.add(pi);
|
---|
| 884 | }
|
---|
| 885 | }
|
---|
[2856] | 886 | loadPlugins(parent, earlyPlugins, monitor);
|
---|
[2817] | 887 | }
|
---|
| 888 |
|
---|
| 889 | /**
|
---|
[8453] | 890 | * Loads plugins from <code>plugins</code> which have the flag {@link PluginInformation#early} set to false.
|
---|
[3232] | 891 | *
|
---|
[6248] | 892 | * @param parent The parent component to be used for the displayed dialog
|
---|
[2817] | 893 | * @param plugins the collection of plugins
|
---|
[5266] | 894 | * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
|
---|
[2817] | 895 | */
|
---|
[5121] | 896 | public static void loadLatePlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) {
|
---|
[7005] | 897 | List<PluginInformation> latePlugins = new ArrayList<>(plugins.size());
|
---|
[2817] | 898 | for (PluginInformation pi: plugins) {
|
---|
| 899 | if (!pi.early) {
|
---|
| 900 | latePlugins.add(pi);
|
---|
| 901 | }
|
---|
| 902 | }
|
---|
[2856] | 903 | loadPlugins(parent, latePlugins, monitor);
|
---|
[2817] | 904 | }
|
---|
| 905 |
|
---|
| 906 | /**
|
---|
| 907 | * Loads locally available plugin information from local plugin jars and from cached
|
---|
| 908 | * plugin lists.
|
---|
| 909 | *
|
---|
[5266] | 910 | * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
|
---|
[2817] | 911 | * @return the list of locally available plugin information
|
---|
[3232] | 912 | *
|
---|
[2817] | 913 | */
|
---|
| 914 | private static Map<String, PluginInformation> loadLocallyAvailablePluginInformation(ProgressMonitor monitor) {
|
---|
| 915 | if (monitor == null) {
|
---|
| 916 | monitor = NullProgressMonitor.INSTANCE;
|
---|
| 917 | }
|
---|
| 918 | try {
|
---|
| 919 | ReadLocalPluginInformationTask task = new ReadLocalPluginInformationTask(monitor);
|
---|
| 920 | try {
|
---|
[8776] | 921 | task.run();
|
---|
[11746] | 922 | } catch (RuntimeException e) { // NOPMD
|
---|
[12620] | 923 | Logging.error(e);
|
---|
[2817] | 924 | return null;
|
---|
| 925 | }
|
---|
[8338] | 926 | Map<String, PluginInformation> ret = new HashMap<>();
|
---|
[2817] | 927 | for (PluginInformation pi: task.getAvailablePlugins()) {
|
---|
| 928 | ret.put(pi.name, pi);
|
---|
| 929 | }
|
---|
| 930 | return ret;
|
---|
| 931 | } finally {
|
---|
| 932 | monitor.finishTask();
|
---|
| 933 | }
|
---|
| 934 | }
|
---|
| 935 |
|
---|
[5121] | 936 | private static void alertMissingPluginInformation(Component parent, Collection<String> plugins) {
|
---|
[2817] | 937 | StringBuilder sb = new StringBuilder();
|
---|
[8379] | 938 | sb.append("<html>")
|
---|
| 939 | .append(trn("JOSM could not find information about the following plugin:",
|
---|
[2817] | 940 | "JOSM could not find information about the following plugins:",
|
---|
[8379] | 941 | plugins.size()))
|
---|
| 942 | .append(Utils.joinAsHtmlUnorderedList(plugins))
|
---|
| 943 | .append(trn("The plugin is not going to be loaded.",
|
---|
[2817] | 944 | "The plugins are not going to be loaded.",
|
---|
[8379] | 945 | plugins.size()))
|
---|
| 946 | .append("</html>");
|
---|
[9917] | 947 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 948 | parent,
|
---|
| 949 | sb.toString(),
|
---|
| 950 | tr("Warning"),
|
---|
| 951 | JOptionPane.WARNING_MESSAGE,
|
---|
[9972] | 952 | ht("/Plugin/Loading#MissingPluginInfos")
|
---|
[9917] | 953 | );
|
---|
[2817] | 954 | }
|
---|
| 955 |
|
---|
| 956 | /**
|
---|
| 957 | * Builds the set of plugins to load. Deprecated and unmaintained plugins are filtered
|
---|
| 958 | * out. This involves user interaction. This method displays alert and confirmation
|
---|
| 959 | * messages.
|
---|
| 960 | *
|
---|
[6248] | 961 | * @param parent The parent component to be used for the displayed dialog
|
---|
[5266] | 962 | * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
|
---|
[2817] | 963 | * @return the set of plugins to load (as set of plugin names)
|
---|
| 964 | */
|
---|
[5121] | 965 | public static List<PluginInformation> buildListOfPluginsToLoad(Component parent, ProgressMonitor monitor) {
|
---|
[2817] | 966 | if (monitor == null) {
|
---|
| 967 | monitor = NullProgressMonitor.INSTANCE;
|
---|
| 968 | }
|
---|
| 969 | try {
|
---|
[10800] | 970 | monitor.beginTask(tr("Determining plugins to load..."));
|
---|
[12841] | 971 | Set<String> plugins = new HashSet<>(Main.pref.getList("plugins", new LinkedList<String>()));
|
---|
[12620] | 972 | Logging.debug("Plugins list initialized to {0}", plugins);
|
---|
[10121] | 973 | String systemProp = System.getProperty("josm.plugins");
|
---|
| 974 | if (systemProp != null) {
|
---|
| 975 | plugins.addAll(Arrays.asList(systemProp.split(",")));
|
---|
[12620] | 976 | Logging.debug("josm.plugins system property set to '{0}'. Plugins list is now {1}", systemProp, plugins);
|
---|
[10121] | 977 | }
|
---|
[2817] | 978 | monitor.subTask(tr("Removing deprecated plugins..."));
|
---|
[2856] | 979 | filterDeprecatedPlugins(parent, plugins);
|
---|
[2955] | 980 | monitor.subTask(tr("Removing unmaintained plugins..."));
|
---|
[2856] | 981 | filterUnmaintainedPlugins(parent, plugins);
|
---|
[12620] | 982 | Logging.debug("Plugins list is finally set to {0}", plugins);
|
---|
[8510] | 983 | Map<String, PluginInformation> infos = loadLocallyAvailablePluginInformation(monitor.createSubTaskMonitor(1, false));
|
---|
[7005] | 984 | List<PluginInformation> ret = new LinkedList<>();
|
---|
[11397] | 985 | if (infos != null) {
|
---|
| 986 | for (Iterator<String> it = plugins.iterator(); it.hasNext();) {
|
---|
| 987 | String plugin = it.next();
|
---|
| 988 | if (infos.containsKey(plugin)) {
|
---|
| 989 | ret.add(infos.get(plugin));
|
---|
| 990 | it.remove();
|
---|
| 991 | }
|
---|
[2817] | 992 | }
|
---|
| 993 | }
|
---|
| 994 | if (!plugins.isEmpty()) {
|
---|
[2856] | 995 | alertMissingPluginInformation(parent, plugins);
|
---|
[2817] | 996 | }
|
---|
| 997 | return ret;
|
---|
| 998 | } finally {
|
---|
| 999 | monitor.finishTask();
|
---|
| 1000 | }
|
---|
| 1001 | }
|
---|
| 1002 |
|
---|
[5121] | 1003 | private static void alertFailedPluginUpdate(Component parent, Collection<PluginInformation> plugins) {
|
---|
[10242] | 1004 | StringBuilder sb = new StringBuilder(128);
|
---|
[8379] | 1005 | sb.append("<html>")
|
---|
| 1006 | .append(trn(
|
---|
[2817] | 1007 | "Updating the following plugin has failed:",
|
---|
| 1008 | "Updating the following plugins has failed:",
|
---|
[8379] | 1009 | plugins.size()))
|
---|
| 1010 | .append("<ul>");
|
---|
[2817] | 1011 | for (PluginInformation pi: plugins) {
|
---|
[11848] | 1012 | sb.append("<li>").append(Utils.escapeReservedCharactersHTML(pi.name)).append("</li>");
|
---|
[2817] | 1013 | }
|
---|
[8379] | 1014 | sb.append("</ul>")
|
---|
| 1015 | .append(trn(
|
---|
[2856] | 1016 | "Please open the Preference Dialog after JOSM has started and try to update it manually.",
|
---|
| 1017 | "Please open the Preference Dialog after JOSM has started and try to update them manually.",
|
---|
[8379] | 1018 | plugins.size()))
|
---|
| 1019 | .append("</html>");
|
---|
[2856] | 1020 | HelpAwareOptionPane.showOptionDialog(
|
---|
| 1021 | parent,
|
---|
[2817] | 1022 | sb.toString(),
|
---|
| 1023 | tr("Plugin update failed"),
|
---|
[2856] | 1024 | JOptionPane.ERROR_MESSAGE,
|
---|
[9972] | 1025 | ht("/Plugin/Loading#FailedPluginUpdated")
|
---|
[2817] | 1026 | );
|
---|
| 1027 | }
|
---|
[6070] | 1028 |
|
---|
[5601] | 1029 | private static Set<PluginInformation> findRequiredPluginsToDownload(
|
---|
| 1030 | Collection<PluginInformation> pluginsToUpdate, List<PluginInformation> allPlugins, Set<PluginInformation> pluginsToDownload) {
|
---|
[7005] | 1031 | Set<PluginInformation> result = new HashSet<>();
|
---|
[5601] | 1032 | for (PluginInformation pi : pluginsToUpdate) {
|
---|
| 1033 | for (String name : pi.getRequiredPlugins()) {
|
---|
| 1034 | try {
|
---|
| 1035 | PluginInformation installedPlugin = PluginInformation.findPlugin(name);
|
---|
| 1036 | if (installedPlugin == null) {
|
---|
| 1037 | // New required plugin is not installed, find its PluginInformation
|
---|
| 1038 | PluginInformation reqPlugin = null;
|
---|
| 1039 | for (PluginInformation pi2 : allPlugins) {
|
---|
| 1040 | if (pi2.getName().equals(name)) {
|
---|
| 1041 | reqPlugin = pi2;
|
---|
| 1042 | break;
|
---|
| 1043 | }
|
---|
| 1044 | }
|
---|
| 1045 | // Required plugin is known but not already on download list
|
---|
| 1046 | if (reqPlugin != null && !pluginsToDownload.contains(reqPlugin)) {
|
---|
| 1047 | result.add(reqPlugin);
|
---|
| 1048 | }
|
---|
| 1049 | }
|
---|
| 1050 | } catch (PluginException e) {
|
---|
[12620] | 1051 | Logging.warn(tr("Failed to find plugin {0}", name));
|
---|
| 1052 | Logging.error(e);
|
---|
[5601] | 1053 | }
|
---|
| 1054 | }
|
---|
| 1055 | }
|
---|
| 1056 | return result;
|
---|
| 1057 | }
|
---|
[2817] | 1058 |
|
---|
| 1059 | /**
|
---|
| 1060 | * Updates the plugins in <code>plugins</code>.
|
---|
[3232] | 1061 | *
|
---|
[5121] | 1062 | * @param parent the parent component for message boxes
|
---|
[6797] | 1063 | * @param pluginsWanted the collection of plugins to update. Updates all plugins if {@code null}
|
---|
[5266] | 1064 | * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
|
---|
[6839] | 1065 | * @param displayErrMsg if {@code true}, a blocking error message is displayed in case of I/O exception.
|
---|
[8928] | 1066 | * @return the list of plugins to load
|
---|
[8291] | 1067 | * @throws IllegalArgumentException if plugins is null
|
---|
[2817] | 1068 | */
|
---|
[6797] | 1069 | public static Collection<PluginInformation> updatePlugins(Component parent,
|
---|
[8291] | 1070 | Collection<PluginInformation> pluginsWanted, ProgressMonitor monitor, boolean displayErrMsg) {
|
---|
[6797] | 1071 | Collection<PluginInformation> plugins = null;
|
---|
| 1072 | pluginDownloadTask = null;
|
---|
[2817] | 1073 | if (monitor == null) {
|
---|
| 1074 | monitor = NullProgressMonitor.INSTANCE;
|
---|
| 1075 | }
|
---|
| 1076 | try {
|
---|
[3086] | 1077 | monitor.beginTask("");
|
---|
| 1078 |
|
---|
| 1079 | // try to download the plugin lists
|
---|
| 1080 | ReadRemotePluginInformationTask task1 = new ReadRemotePluginInformationTask(
|
---|
[8030] | 1081 | monitor.createSubTaskMonitor(1, false),
|
---|
[8471] | 1082 | Main.pref.getOnlinePluginSites(), displayErrMsg
|
---|
[3086] | 1083 | );
|
---|
[8776] | 1084 | task1.run();
|
---|
[10768] | 1085 | List<PluginInformation> allPlugins = task1.getAvailablePlugins();
|
---|
[6070] | 1086 |
|
---|
[3086] | 1087 | try {
|
---|
[8030] | 1088 | plugins = buildListOfPluginsToLoad(parent, monitor.createSubTaskMonitor(1, false));
|
---|
[6839] | 1089 | // If only some plugins have to be updated, filter the list
|
---|
[6797] | 1090 | if (pluginsWanted != null && !pluginsWanted.isEmpty()) {
|
---|
[10781] | 1091 | final Collection<String> pluginsWantedName = Utils.transform(pluginsWanted, piw -> piw.name);
|
---|
| 1092 | plugins = SubclassFilteredCollection.filter(plugins, pi -> pluginsWantedName.contains(pi.name));
|
---|
[6797] | 1093 | }
|
---|
[11746] | 1094 | } catch (RuntimeException e) { // NOPMD
|
---|
[12620] | 1095 | Logging.warn(tr("Failed to download plugin information list"));
|
---|
| 1096 | Logging.error(e);
|
---|
[3086] | 1097 | // don't abort in case of error, continue with downloading plugins below
|
---|
| 1098 | }
|
---|
| 1099 |
|
---|
[3090] | 1100 | // filter plugins which actually have to be updated
|
---|
[7005] | 1101 | Collection<PluginInformation> pluginsToUpdate = new ArrayList<>();
|
---|
[10768] | 1102 | if (plugins != null) {
|
---|
| 1103 | for (PluginInformation pi: plugins) {
|
---|
| 1104 | if (pi.isUpdateRequired()) {
|
---|
| 1105 | pluginsToUpdate.add(pi);
|
---|
| 1106 | }
|
---|
[3090] | 1107 | }
|
---|
| 1108 | }
|
---|
[6070] | 1109 |
|
---|
[5601] | 1110 | if (!pluginsToUpdate.isEmpty()) {
|
---|
[6070] | 1111 |
|
---|
[7005] | 1112 | Set<PluginInformation> pluginsToDownload = new HashSet<>(pluginsToUpdate);
|
---|
[6070] | 1113 |
|
---|
[5601] | 1114 | if (allPlugins != null) {
|
---|
| 1115 | // Updated plugins may need additional plugin dependencies currently not installed
|
---|
| 1116 | //
|
---|
| 1117 | Set<PluginInformation> additionalPlugins = findRequiredPluginsToDownload(pluginsToUpdate, allPlugins, pluginsToDownload);
|
---|
| 1118 | pluginsToDownload.addAll(additionalPlugins);
|
---|
[6070] | 1119 |
|
---|
[5601] | 1120 | // Iterate on required plugins, if they need themselves another plugins (i.e A needs B, but B needs C)
|
---|
| 1121 | while (!additionalPlugins.isEmpty()) {
|
---|
| 1122 | // Install the additional plugins to load them later
|
---|
[10768] | 1123 | if (plugins != null)
|
---|
| 1124 | plugins.addAll(additionalPlugins);
|
---|
[5601] | 1125 | additionalPlugins = findRequiredPluginsToDownload(additionalPlugins, allPlugins, pluginsToDownload);
|
---|
| 1126 | pluginsToDownload.addAll(additionalPlugins);
|
---|
| 1127 | }
|
---|
| 1128 | }
|
---|
[3086] | 1129 |
|
---|
[3090] | 1130 | // try to update the locally installed plugins
|
---|
[6797] | 1131 | pluginDownloadTask = new PluginDownloadTask(
|
---|
[8510] | 1132 | monitor.createSubTaskMonitor(1, false),
|
---|
[5601] | 1133 | pluginsToDownload,
|
---|
[3090] | 1134 | tr("Update plugins")
|
---|
| 1135 | );
|
---|
| 1136 |
|
---|
| 1137 | try {
|
---|
[8776] | 1138 | pluginDownloadTask.run();
|
---|
[11746] | 1139 | } catch (RuntimeException e) { // NOPMD
|
---|
[12620] | 1140 | Logging.error(e);
|
---|
[3106] | 1141 | alertFailedPluginUpdate(parent, pluginsToUpdate);
|
---|
[3287] | 1142 | return plugins;
|
---|
[3090] | 1143 | }
|
---|
[6070] | 1144 |
|
---|
[5601] | 1145 | // Update Plugin info for downloaded plugins
|
---|
[6797] | 1146 | refreshLocalUpdatedPluginInfo(pluginDownloadTask.getDownloadedPlugins());
|
---|
[6070] | 1147 |
|
---|
[3090] | 1148 | // notify user if downloading a locally installed plugin failed
|
---|
[8443] | 1149 | if (!pluginDownloadTask.getFailedPlugins().isEmpty()) {
|
---|
[6797] | 1150 | alertFailedPluginUpdate(parent, pluginDownloadTask.getFailedPlugins());
|
---|
[3287] | 1151 | return plugins;
|
---|
[3090] | 1152 | }
|
---|
[2817] | 1153 | }
|
---|
| 1154 | } finally {
|
---|
| 1155 | monitor.finishTask();
|
---|
| 1156 | }
|
---|
[6797] | 1157 | if (pluginsWanted == null) {
|
---|
| 1158 | // if all plugins updated, remember the update because it was successful
|
---|
[12841] | 1159 | Main.pref.putInt("pluginmanager.version", Version.getInstance().getVersion());
|
---|
[6797] | 1160 | Main.pref.put("pluginmanager.lastupdate", Long.toString(System.currentTimeMillis()));
|
---|
| 1161 | }
|
---|
[3287] | 1162 | return plugins;
|
---|
[2817] | 1163 | }
|
---|
| 1164 |
|
---|
| 1165 | /**
|
---|
| 1166 | * Ask the user for confirmation that a plugin shall be disabled.
|
---|
[6839] | 1167 | *
|
---|
[6248] | 1168 | * @param parent The parent component to be used for the displayed dialog
|
---|
[2817] | 1169 | * @param reason the reason for disabling the plugin
|
---|
| 1170 | * @param name the plugin name
|
---|
| 1171 | * @return true, if the plugin shall be disabled; false, otherwise
|
---|
| 1172 | */
|
---|
[5121] | 1173 | public static boolean confirmDisablePlugin(Component parent, String reason, String name) {
|
---|
[8443] | 1174 | ButtonSpec[] options = new ButtonSpec[] {
|
---|
[2856] | 1175 | new ButtonSpec(
|
---|
| 1176 | tr("Disable plugin"),
|
---|
| 1177 | ImageProvider.get("dialogs", "delete"),
|
---|
| 1178 | tr("Click to delete the plugin ''{0}''", name),
|
---|
| 1179 | null /* no specific help context */
|
---|
| 1180 | ),
|
---|
| 1181 | new ButtonSpec(
|
---|
| 1182 | tr("Keep plugin"),
|
---|
| 1183 | ImageProvider.get("cancel"),
|
---|
| 1184 | tr("Click to keep the plugin ''{0}''", name),
|
---|
| 1185 | null /* no specific help context */
|
---|
| 1186 | )
|
---|
| 1187 | };
|
---|
[9917] | 1188 | return 0 == HelpAwareOptionPane.showOptionDialog(
|
---|
[8939] | 1189 | parent,
|
---|
| 1190 | reason,
|
---|
| 1191 | tr("Disable plugin"),
|
---|
| 1192 | JOptionPane.WARNING_MESSAGE,
|
---|
| 1193 | null,
|
---|
| 1194 | options,
|
---|
| 1195 | options[0],
|
---|
| 1196 | null // FIXME: add help topic
|
---|
| 1197 | );
|
---|
[2259] | 1198 | }
|
---|
| 1199 |
|
---|
[6248] | 1200 | /**
|
---|
| 1201 | * Returns the plugin of the specified name.
|
---|
| 1202 | * @param name The plugin name
|
---|
| 1203 | * @return The plugin of the specified name, if installed and loaded, or {@code null} otherwise.
|
---|
| 1204 | */
|
---|
[1326] | 1205 | public static Object getPlugin(String name) {
|
---|
[8513] | 1206 | for (PluginProxy plugin : pluginList) {
|
---|
[6248] | 1207 | if (plugin.getPluginInformation().name.equals(name))
|
---|
[12322] | 1208 | return plugin.getPlugin();
|
---|
[8513] | 1209 | }
|
---|
[1326] | 1210 | return null;
|
---|
| 1211 | }
|
---|
| 1212 |
|
---|
[12323] | 1213 | /**
|
---|
| 1214 | * Returns the plugin class loader for the plugin of the specified name.
|
---|
| 1215 | * @param name The plugin name
|
---|
| 1216 | * @return The plugin class loader for the plugin of the specified name, if
|
---|
| 1217 | * installed and loaded, or {@code null} otherwise.
|
---|
| 1218 | * @since 12323
|
---|
| 1219 | */
|
---|
| 1220 | public static PluginClassLoader getPluginClassLoader(String name) {
|
---|
| 1221 | for (PluginProxy plugin : pluginList) {
|
---|
| 1222 | if (plugin.getPluginInformation().name.equals(name))
|
---|
| 1223 | return plugin.getClassLoader();
|
---|
| 1224 | }
|
---|
| 1225 | return null;
|
---|
| 1226 | }
|
---|
| 1227 |
|
---|
[2817] | 1228 | public static void addDownloadSelection(List<DownloadSelection> downloadSelections) {
|
---|
[1860] | 1229 | for (PluginProxy p : pluginList) {
|
---|
[1326] | 1230 | p.addDownloadSelection(downloadSelections);
|
---|
[1860] | 1231 | }
|
---|
[1326] | 1232 | }
|
---|
[2817] | 1233 |
|
---|
[8024] | 1234 | public static Collection<PreferenceSettingFactory> getPreferenceSetting() {
|
---|
| 1235 | Collection<PreferenceSettingFactory> settings = new ArrayList<>();
|
---|
[1326] | 1236 | for (PluginProxy plugin : pluginList) {
|
---|
[1742] | 1237 | settings.add(new PluginPreferenceFactory(plugin));
|
---|
[1326] | 1238 | }
|
---|
[8024] | 1239 | return settings;
|
---|
[1326] | 1240 | }
|
---|
| 1241 |
|
---|
[2817] | 1242 | /**
|
---|
| 1243 | * Installs downloaded plugins. Moves files with the suffix ".jar.new" to the corresponding
|
---|
| 1244 | * ".jar" files.
|
---|
[3232] | 1245 | *
|
---|
[3090] | 1246 | * If {@code dowarn} is true, this methods emits warning messages on the console if a downloaded
|
---|
| 1247 | * but not yet installed plugin .jar can't be be installed. If {@code dowarn} is false, the
|
---|
[8017] | 1248 | * installation of the respective plugin is silently skipped.
|
---|
[3232] | 1249 | *
|
---|
[3090] | 1250 | * @param dowarn if true, warning messages are displayed; false otherwise
|
---|
[2817] | 1251 | */
|
---|
[3054] | 1252 | public static void installDownloadedPlugins(boolean dowarn) {
|
---|
[2817] | 1253 | File pluginDir = Main.pref.getPluginsDirectory();
|
---|
[8443] | 1254 | if (!pluginDir.exists() || !pluginDir.isDirectory() || !pluginDir.canWrite())
|
---|
[2817] | 1255 | return;
|
---|
| 1256 |
|
---|
[10616] | 1257 | final File[] files = pluginDir.listFiles((FilenameFilter) (dir, name) -> name.endsWith(".jar.new"));
|
---|
[8308] | 1258 | if (files == null)
|
---|
| 1259 | return;
|
---|
[2817] | 1260 |
|
---|
| 1261 | for (File updatedPlugin : files) {
|
---|
| 1262 | final String filePath = updatedPlugin.getPath();
|
---|
| 1263 | File plugin = new File(filePath.substring(0, filePath.length() - 4));
|
---|
| 1264 | String pluginName = updatedPlugin.getName().substring(0, updatedPlugin.getName().length() - 8);
|
---|
[6883] | 1265 | if (plugin.exists() && !plugin.delete() && dowarn) {
|
---|
[12620] | 1266 | Logging.warn(tr("Failed to delete outdated plugin ''{0}''.", plugin.toString()));
|
---|
| 1267 | Logging.warn(tr("Failed to install already downloaded plugin ''{0}''. " +
|
---|
[8510] | 1268 | "Skipping installation. JOSM is still going to load the old plugin version.",
|
---|
[8509] | 1269 | pluginName));
|
---|
[6883] | 1270 | continue;
|
---|
[2817] | 1271 | }
|
---|
[5723] | 1272 | try {
|
---|
| 1273 | // Check the plugin is a valid and accessible JAR file before installing it (fix #7754)
|
---|
| 1274 | new JarFile(updatedPlugin).close();
|
---|
[10212] | 1275 | } catch (IOException e) {
|
---|
[5723] | 1276 | if (dowarn) {
|
---|
[12620] | 1277 | Logging.log(Logging.LEVEL_WARN, tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}",
|
---|
| 1278 | plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage()), e);
|
---|
[5723] | 1279 | }
|
---|
| 1280 | continue;
|
---|
| 1281 | }
|
---|
| 1282 | // Install plugin
|
---|
[3090] | 1283 | if (!updatedPlugin.renameTo(plugin) && dowarn) {
|
---|
[12620] | 1284 | Logging.warn(tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.",
|
---|
[8509] | 1285 | plugin.toString(), updatedPlugin.toString()));
|
---|
[12620] | 1286 | Logging.warn(tr("Failed to install already downloaded plugin ''{0}''. " +
|
---|
[8510] | 1287 | "Skipping installation. JOSM is still going to load the old plugin version.",
|
---|
[8509] | 1288 | pluginName));
|
---|
[2817] | 1289 | }
|
---|
[1326] | 1290 | }
|
---|
| 1291 | }
|
---|
[6070] | 1292 |
|
---|
[5601] | 1293 | /**
|
---|
[5723] | 1294 | * Determines if the specified file is a valid and accessible JAR file.
|
---|
[9616] | 1295 | * @param jar The file to check
|
---|
[5723] | 1296 | * @return true if file can be opened as a JAR file.
|
---|
| 1297 | * @since 5723
|
---|
| 1298 | */
|
---|
| 1299 | public static boolean isValidJar(File jar) {
|
---|
| 1300 | if (jar != null && jar.exists() && jar.canRead()) {
|
---|
| 1301 | try {
|
---|
| 1302 | new JarFile(jar).close();
|
---|
[10212] | 1303 | } catch (IOException e) {
|
---|
[12620] | 1304 | Logging.warn(e);
|
---|
[5723] | 1305 | return false;
|
---|
| 1306 | }
|
---|
| 1307 | return true;
|
---|
[9616] | 1308 | } else if (jar != null) {
|
---|
[12620] | 1309 | Logging.warn("Invalid jar file ''"+jar+"'' (exists: "+jar.exists()+", canRead: "+jar.canRead()+')');
|
---|
[5723] | 1310 | }
|
---|
| 1311 | return false;
|
---|
| 1312 | }
|
---|
[6070] | 1313 |
|
---|
[5723] | 1314 | /**
|
---|
[5601] | 1315 | * Replies the updated jar file for the given plugin name.
|
---|
| 1316 | * @param name The plugin name to find.
|
---|
| 1317 | * @return the updated jar file for the given plugin name. null if not found or not readable.
|
---|
| 1318 | * @since 5601
|
---|
| 1319 | */
|
---|
| 1320 | public static File findUpdatedJar(String name) {
|
---|
| 1321 | File pluginDir = Main.pref.getPluginsDirectory();
|
---|
| 1322 | // Find the downloaded file. We have tried to install the downloaded plugins
|
---|
[5723] | 1323 | // (PluginHandler.installDownloadedPlugins). This succeeds depending on the platform.
|
---|
[5601] | 1324 | File downloadedPluginFile = new File(pluginDir, name + ".jar.new");
|
---|
[5723] | 1325 | if (!isValidJar(downloadedPluginFile)) {
|
---|
[5601] | 1326 | downloadedPluginFile = new File(pluginDir, name + ".jar");
|
---|
[5723] | 1327 | if (!isValidJar(downloadedPluginFile)) {
|
---|
[5601] | 1328 | return null;
|
---|
| 1329 | }
|
---|
| 1330 | }
|
---|
| 1331 | return downloadedPluginFile;
|
---|
| 1332 | }
|
---|
[6070] | 1333 |
|
---|
[5601] | 1334 | /**
|
---|
| 1335 | * Refreshes the given PluginInformation objects with new contents read from their corresponding jar file.
|
---|
| 1336 | * @param updatedPlugins The PluginInformation objects to update.
|
---|
| 1337 | * @since 5601
|
---|
| 1338 | */
|
---|
| 1339 | public static void refreshLocalUpdatedPluginInfo(Collection<PluginInformation> updatedPlugins) {
|
---|
| 1340 | if (updatedPlugins == null) return;
|
---|
| 1341 | for (PluginInformation pi : updatedPlugins) {
|
---|
| 1342 | File downloadedPluginFile = findUpdatedJar(pi.name);
|
---|
| 1343 | if (downloadedPluginFile == null) {
|
---|
| 1344 | continue;
|
---|
| 1345 | }
|
---|
| 1346 | try {
|
---|
| 1347 | pi.updateFromJar(new PluginInformation(downloadedPluginFile, pi.name));
|
---|
[8510] | 1348 | } catch (PluginException e) {
|
---|
[12620] | 1349 | Logging.error(e);
|
---|
[5601] | 1350 | }
|
---|
| 1351 | }
|
---|
| 1352 | }
|
---|
[2817] | 1353 |
|
---|
[6797] | 1354 | private static int askUpdateDisableKeepPluginAfterException(PluginProxy plugin) {
|
---|
| 1355 | final ButtonSpec[] options = new ButtonSpec[] {
|
---|
[2856] | 1356 | new ButtonSpec(
|
---|
[6797] | 1357 | tr("Update plugin"),
|
---|
| 1358 | ImageProvider.get("dialogs", "refresh"),
|
---|
| 1359 | tr("Click to update the plugin ''{0}''", plugin.getPluginInformation().name),
|
---|
| 1360 | null /* no specific help context */
|
---|
| 1361 | ),
|
---|
| 1362 | new ButtonSpec(
|
---|
[2856] | 1363 | tr("Disable plugin"),
|
---|
| 1364 | ImageProvider.get("dialogs", "delete"),
|
---|
| 1365 | tr("Click to disable the plugin ''{0}''", plugin.getPluginInformation().name),
|
---|
| 1366 | null /* no specific help context */
|
---|
| 1367 | ),
|
---|
| 1368 | new ButtonSpec(
|
---|
| 1369 | tr("Keep plugin"),
|
---|
| 1370 | ImageProvider.get("cancel"),
|
---|
[8510] | 1371 | tr("Click to keep the plugin ''{0}''", plugin.getPluginInformation().name),
|
---|
[2856] | 1372 | null /* no specific help context */
|
---|
| 1373 | )
|
---|
| 1374 | };
|
---|
| 1375 |
|
---|
[10242] | 1376 | final StringBuilder msg = new StringBuilder(256);
|
---|
[8379] | 1377 | msg.append("<html>")
|
---|
[11848] | 1378 | .append(tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.",
|
---|
| 1379 | Utils.escapeReservedCharactersHTML(plugin.getPluginInformation().name)))
|
---|
[8379] | 1380 | .append("<br>");
|
---|
[6797] | 1381 | if (plugin.getPluginInformation().author != null) {
|
---|
[11848] | 1382 | msg.append(tr("According to the information within the plugin, the author is {0}.",
|
---|
| 1383 | Utils.escapeReservedCharactersHTML(plugin.getPluginInformation().author)))
|
---|
[8379] | 1384 | .append("<br>");
|
---|
[2856] | 1385 | }
|
---|
[8379] | 1386 | msg.append(tr("Try updating to the newest version of this plugin before reporting a bug."))
|
---|
| 1387 | .append("</html>");
|
---|
[2856] | 1388 |
|
---|
[6797] | 1389 | try {
|
---|
[10616] | 1390 | FutureTask<Integer> task = new FutureTask<>(() -> HelpAwareOptionPane.showOptionDialog(
|
---|
| 1391 | Main.parent,
|
---|
| 1392 | msg.toString(),
|
---|
| 1393 | tr("Update plugins"),
|
---|
| 1394 | JOptionPane.QUESTION_MESSAGE,
|
---|
| 1395 | null,
|
---|
| 1396 | options,
|
---|
| 1397 | options[0],
|
---|
| 1398 | ht("/ErrorMessages#ErrorInPlugin")
|
---|
| 1399 | ));
|
---|
[6797] | 1400 | GuiHelper.runInEDT(task);
|
---|
| 1401 | return task.get();
|
---|
[7004] | 1402 | } catch (InterruptedException | ExecutionException e) {
|
---|
[12620] | 1403 | Logging.warn(e);
|
---|
[6797] | 1404 | }
|
---|
| 1405 | return -1;
|
---|
[2856] | 1406 | }
|
---|
| 1407 |
|
---|
[2859] | 1408 | /**
|
---|
| 1409 | * Replies the plugin which most likely threw the exception <code>ex</code>.
|
---|
[3232] | 1410 | *
|
---|
[2859] | 1411 | * @param ex the exception
|
---|
[4167] | 1412 | * @return the plugin; null, if the exception probably wasn't thrown from a plugin
|
---|
[2859] | 1413 | */
|
---|
[2856] | 1414 | private static PluginProxy getPluginCausingException(Throwable ex) {
|
---|
[4167] | 1415 | PluginProxy err = null;
|
---|
| 1416 | StackTraceElement[] stack = ex.getStackTrace();
|
---|
[8471] | 1417 | // remember the error position, as multiple plugins may be involved, we search the topmost one
|
---|
[4167] | 1418 | int pos = stack.length;
|
---|
[2856] | 1419 | for (PluginProxy p : pluginList) {
|
---|
| 1420 | String baseClass = p.getPluginInformation().className;
|
---|
[6083] | 1421 | baseClass = baseClass.substring(0, baseClass.lastIndexOf('.'));
|
---|
[4167] | 1422 | for (int elpos = 0; elpos < pos; ++elpos) {
|
---|
| 1423 | if (stack[elpos].getClassName().startsWith(baseClass)) {
|
---|
| 1424 | pos = elpos;
|
---|
| 1425 | err = p;
|
---|
| 1426 | }
|
---|
[2856] | 1427 | }
|
---|
| 1428 | }
|
---|
[4167] | 1429 | return err;
|
---|
[2856] | 1430 | }
|
---|
| 1431 |
|
---|
[2859] | 1432 | /**
|
---|
| 1433 | * Checks whether the exception <code>e</code> was thrown by a plugin. If so,
|
---|
[6797] | 1434 | * conditionally updates or deactivates the plugin, but asks the user first.
|
---|
[3232] | 1435 | *
|
---|
[2859] | 1436 | * @param e the exception
|
---|
[6797] | 1437 | * @return plugin download task if the plugin has been updated to a newer version, {@code null} if it has been disabled or kept as it
|
---|
[2859] | 1438 | */
|
---|
[6797] | 1439 | public static PluginDownloadTask updateOrdisablePluginAfterException(Throwable e) {
|
---|
[1326] | 1440 | PluginProxy plugin = null;
|
---|
| 1441 | // Check for an explicit problem when calling a plugin function
|
---|
[1860] | 1442 | if (e instanceof PluginException) {
|
---|
[2856] | 1443 | plugin = ((PluginException) e).plugin;
|
---|
[1860] | 1444 | }
|
---|
[2855] | 1445 | if (plugin == null) {
|
---|
[2856] | 1446 | plugin = getPluginCausingException(e);
|
---|
[1326] | 1447 | }
|
---|
[2859] | 1448 | if (plugin == null)
|
---|
| 1449 | // don't know what plugin threw the exception
|
---|
[6797] | 1450 | return null;
|
---|
[1326] | 1451 |
|
---|
[12841] | 1452 | Set<String> plugins = new HashSet<>(Main.pref.getList("plugins"));
|
---|
[6797] | 1453 | final PluginInformation pluginInfo = plugin.getPluginInformation();
|
---|
[8443] | 1454 | if (!plugins.contains(pluginInfo.name))
|
---|
[2859] | 1455 | // plugin not activated ? strange in this context but anyway, don't bother
|
---|
[2866] | 1456 | // the user with dialogs, skip conditional deactivation
|
---|
[6797] | 1457 | return null;
|
---|
[2859] | 1458 |
|
---|
[6797] | 1459 | switch (askUpdateDisableKeepPluginAfterException(plugin)) {
|
---|
| 1460 | case 0:
|
---|
| 1461 | // update the plugin
|
---|
[6839] | 1462 | updatePlugins(Main.parent, Collections.singleton(pluginInfo), null, true);
|
---|
[6797] | 1463 | return pluginDownloadTask;
|
---|
| 1464 | case 1:
|
---|
| 1465 | // deactivate the plugin
|
---|
| 1466 | plugins.remove(plugin.getPluginInformation().name);
|
---|
[12841] | 1467 | Main.pref.putList("plugins", new ArrayList<>(plugins));
|
---|
[10616] | 1468 | GuiHelper.runInEDTAndWait(() -> JOptionPane.showMessageDialog(
|
---|
| 1469 | Main.parent,
|
---|
| 1470 | tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin."),
|
---|
| 1471 | tr("Information"),
|
---|
| 1472 | JOptionPane.INFORMATION_MESSAGE
|
---|
| 1473 | ));
|
---|
[6797] | 1474 | return null;
|
---|
| 1475 | default:
|
---|
[2859] | 1476 | // user doesn't want to deactivate the plugin
|
---|
[6797] | 1477 | return null;
|
---|
| 1478 | }
|
---|
[1326] | 1479 | }
|
---|
[2817] | 1480 |
|
---|
[6248] | 1481 | /**
|
---|
| 1482 | * Returns the list of loaded plugins as a {@code String} to be displayed in status report. Useful for bug reports.
|
---|
[10696] | 1483 | * @return The list of loaded plugins
|
---|
[6248] | 1484 | */
|
---|
[10696] | 1485 | public static Collection<String> getBugReportInformation() {
|
---|
[12841] | 1486 | final Collection<String> pl = new TreeSet<>(Main.pref.getList("plugins", new LinkedList<>()));
|
---|
[1326] | 1487 | for (final PluginProxy pp : pluginList) {
|
---|
[3297] | 1488 | PluginInformation pi = pp.getPluginInformation();
|
---|
| 1489 | pl.remove(pi.name);
|
---|
[6087] | 1490 | pl.add(pi.name + " (" + (pi.localversion != null && !pi.localversion.isEmpty()
|
---|
[8846] | 1491 | ? pi.localversion : "unknown") + ')');
|
---|
[1326] | 1492 | }
|
---|
[10696] | 1493 | return pl;
|
---|
[1326] | 1494 | }
|
---|
[2817] | 1495 |
|
---|
[6248] | 1496 | /**
|
---|
| 1497 | * Returns the list of loaded plugins as a {@code JPanel} to be displayed in About dialog.
|
---|
| 1498 | * @return The list of loaded plugins (one "line" of Swing components per plugin)
|
---|
| 1499 | */
|
---|
[2817] | 1500 | public static JPanel getInfoPanel() {
|
---|
[1326] | 1501 | JPanel pluginTab = new JPanel(new GridBagLayout());
|
---|
| 1502 | for (final PluginProxy p : pluginList) {
|
---|
[2830] | 1503 | final PluginInformation info = p.getPluginInformation();
|
---|
| 1504 | String name = info.name
|
---|
[6087] | 1505 | + (info.version != null && !info.version.isEmpty() ? " Version: " + info.version : "");
|
---|
[1326] | 1506 | pluginTab.add(new JLabel(name), GBC.std());
|
---|
| 1507 | pluginTab.add(Box.createHorizontalGlue(), GBC.std().fill(GBC.HORIZONTAL));
|
---|
[11974] | 1508 | pluginTab.add(new JButton(new PluginInformationAction(info)), GBC.eol());
|
---|
[1326] | 1509 |
|
---|
[8345] | 1510 | JosmTextArea description = new JosmTextArea(info.description == null ? tr("no description available")
|
---|
| 1511 | : info.description);
|
---|
[1326] | 1512 | description.setEditable(false);
|
---|
| 1513 | description.setFont(new JLabel().getFont().deriveFont(Font.ITALIC));
|
---|
| 1514 | description.setLineWrap(true);
|
---|
| 1515 | description.setWrapStyleWord(true);
|
---|
[2817] | 1516 | description.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
|
---|
[1326] | 1517 | description.setBackground(UIManager.getColor("Panel.background"));
|
---|
[5194] | 1518 | description.setCaretPosition(0);
|
---|
[1326] | 1519 |
|
---|
| 1520 | pluginTab.add(description, GBC.eop().fill(GBC.HORIZONTAL));
|
---|
| 1521 | }
|
---|
| 1522 | return pluginTab;
|
---|
| 1523 | }
|
---|
[2856] | 1524 |
|
---|
[8938] | 1525 | /**
|
---|
| 1526 | * Returns the set of deprecated and unmaintained plugins.
|
---|
| 1527 | * @return set of deprecated and unmaintained plugins names.
|
---|
| 1528 | * @since 8938
|
---|
| 1529 | */
|
---|
| 1530 | public static Set<String> getDeprecatedAndUnmaintainedPlugins() {
|
---|
[10238] | 1531 | Set<String> result = new HashSet<>(DEPRECATED_PLUGINS.size() + UNMAINTAINED_PLUGINS.size());
|
---|
[8938] | 1532 | for (DeprecatedPlugin dp : DEPRECATED_PLUGINS) {
|
---|
| 1533 | result.add(dp.name);
|
---|
| 1534 | }
|
---|
[10238] | 1535 | result.addAll(UNMAINTAINED_PLUGINS);
|
---|
[8938] | 1536 | return result;
|
---|
| 1537 | }
|
---|
| 1538 |
|
---|
[6883] | 1539 | private static class UpdatePluginsMessagePanel extends JPanel {
|
---|
[10179] | 1540 | private final JMultilineLabel lblMessage = new JMultilineLabel("");
|
---|
| 1541 | private final JCheckBox cbDontShowAgain = new JCheckBox(
|
---|
| 1542 | tr("Do not ask again and remember my decision (go to Preferences->Plugins to change it later)"));
|
---|
[2856] | 1543 |
|
---|
[10179] | 1544 | UpdatePluginsMessagePanel() {
|
---|
| 1545 | build();
|
---|
| 1546 | }
|
---|
| 1547 |
|
---|
[6890] | 1548 | protected final void build() {
|
---|
[2856] | 1549 | setLayout(new GridBagLayout());
|
---|
| 1550 | GridBagConstraints gc = new GridBagConstraints();
|
---|
| 1551 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
| 1552 | gc.fill = GridBagConstraints.BOTH;
|
---|
| 1553 | gc.weightx = 1.0;
|
---|
| 1554 | gc.weighty = 1.0;
|
---|
[8510] | 1555 | gc.insets = new Insets(5, 5, 5, 5);
|
---|
[10179] | 1556 | add(lblMessage, gc);
|
---|
[2856] | 1557 | lblMessage.setFont(lblMessage.getFont().deriveFont(Font.PLAIN));
|
---|
| 1558 |
|
---|
| 1559 | gc.gridy = 1;
|
---|
| 1560 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
| 1561 | gc.weighty = 0.0;
|
---|
[10179] | 1562 | add(cbDontShowAgain, gc);
|
---|
[2856] | 1563 | cbDontShowAgain.setFont(cbDontShowAgain.getFont().deriveFont(Font.PLAIN));
|
---|
| 1564 | }
|
---|
| 1565 |
|
---|
| 1566 | public void setMessage(String message) {
|
---|
| 1567 | lblMessage.setText(message);
|
---|
| 1568 | }
|
---|
| 1569 |
|
---|
| 1570 | public void initDontShowAgain(String preferencesKey) {
|
---|
[2924] | 1571 | String policy = Main.pref.get(preferencesKey, "ask");
|
---|
[8404] | 1572 | policy = policy.trim().toLowerCase(Locale.ENGLISH);
|
---|
[6990] | 1573 | cbDontShowAgain.setSelected(!"ask".equals(policy));
|
---|
[2856] | 1574 | }
|
---|
| 1575 |
|
---|
[2924] | 1576 | public boolean isRememberDecision() {
|
---|
| 1577 | return cbDontShowAgain.isSelected();
|
---|
[2856] | 1578 | }
|
---|
| 1579 | }
|
---|
[1326] | 1580 | }
|
---|