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