Ignore:
Timestamp:
2010-12-16T18:20:22+01:00 (14 years ago)
Author:
bastiK
Message:

improve migration when remotecontrol plugin is removed (set remotecontol.enabled=yes) (see also #5748)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r3723 r3730  
    2929import java.util.Set;
    3030import java.util.Map.Entry;
    31 import java.util.TreeMap;
    3231import java.util.TreeSet;
    3332import java.util.concurrent.ExecutionException;
     
    5958import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    6059import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     60import org.openstreetmap.josm.io.remotecontrol.RemoteControl;
    6161import org.openstreetmap.josm.tools.CheckParameterUtil;
    6262import org.openstreetmap.josm.tools.GBC;
     
    7070public class PluginHandler {
    7171
    72     /* deprecated plugins that are removed on start
    73        key - plugin name; value - explanation for deprecation (optional, can be null) */
    74     public final static Map<String, String> DEPRECATED_PLUGINS = new TreeMap<String, String>();
     72    /* deprecated plugins that are removed on start */
     73    public final static Collection<DeprecatedPlugin> DEPRECATED_PLUGINS;
    7574    static {
    7675        String IN_CORE = tr("integrated into main program");
    77         for (String[] depr : new String[][] {
    78             {"mappaint", IN_CORE}, {"unglueplugin", IN_CORE},
    79             {"lang-de", IN_CORE}, {"lang-en_GB", IN_CORE}, {"lang-fr", IN_CORE},
    80             {"lang-it", IN_CORE}, {"lang-pl", IN_CORE}, {"lang-ro", IN_CORE},
    81             {"lang-ru", IN_CORE}, {"ewmsplugin", IN_CORE}, {"ywms", IN_CORE},
    82             {"tways-0.2", IN_CORE},
    83             {"geotagged", IN_CORE},
    84             {"landsat", tr("replaced by {0} plugin","lakewalker")},
    85             {"namefinder", IN_CORE},
    86             {"waypoints", IN_CORE}, {"slippy_map_chooser", IN_CORE},
    87             {"tcx-support", tr("replaced by {0} plugin","dataimport")},
    88             {"usertools", IN_CORE},
    89             {"AgPifoJ", IN_CORE}, {"utilsplugin", IN_CORE}, {"ghost", IN_CORE},
    90             {"validator", IN_CORE}, {"multipoly", IN_CORE},
    91             {"remotecontrol", IN_CORE},
    92             {"imagery", IN_CORE}, {"slippymap", IN_CORE}, {"wmsplugin", IN_CORE}}) {
    93             DEPRECATED_PLUGINS.put(depr[0], depr.length >= 2 ? depr[1] : null);
     76
     77        class RemotecontrolMigration implements Runnable {
     78            public void run() {
     79                System.out.println("Migrating remotecontrol plugin...");
     80                if (!RemoteControl.PROP_REMOTECONTROL_ENABLED.isSet()) {
     81                    System.out.println("  Setting "+RemoteControl.PROP_REMOTECONTROL_ENABLED.getKey()+"=true");
     82                    RemoteControl.PROP_REMOTECONTROL_ENABLED.put(true);
     83                }
     84                System.out.println("...Done.");
     85            }
     86        }
     87
     88        DEPRECATED_PLUGINS = Arrays.asList(new DeprecatedPlugin[] {
     89            new DeprecatedPlugin("mappaint", IN_CORE),
     90            new DeprecatedPlugin("unglueplugin", IN_CORE),
     91            new DeprecatedPlugin("lang-de", IN_CORE),
     92            new DeprecatedPlugin("lang-en_GB", IN_CORE),
     93            new DeprecatedPlugin("lang-fr", IN_CORE),
     94            new DeprecatedPlugin("lang-it", IN_CORE),
     95            new DeprecatedPlugin("lang-pl", IN_CORE),
     96            new DeprecatedPlugin("lang-ro", IN_CORE),
     97            new DeprecatedPlugin("lang-ru", IN_CORE),
     98            new DeprecatedPlugin("ewmsplugin", IN_CORE),
     99            new DeprecatedPlugin("ywms", IN_CORE),
     100            new DeprecatedPlugin("tways-0.2", IN_CORE),
     101            new DeprecatedPlugin("geotagged", IN_CORE),
     102            new DeprecatedPlugin("landsat", tr("replaced by new {0} plugin","lakewalker")),
     103            new DeprecatedPlugin("namefinder", IN_CORE),
     104            new DeprecatedPlugin("waypoints", IN_CORE),
     105            new DeprecatedPlugin("slippy_map_chooser", IN_CORE),
     106            new DeprecatedPlugin("tcx-support", tr("replaced by new {0} plugin","dataimport")),
     107            new DeprecatedPlugin("usertools", IN_CORE),
     108            new DeprecatedPlugin("AgPifoJ", IN_CORE),
     109            new DeprecatedPlugin("utilsplugin", IN_CORE),
     110            new DeprecatedPlugin("ghost", IN_CORE),
     111            new DeprecatedPlugin("validator", IN_CORE),
     112            new DeprecatedPlugin("multipoly", IN_CORE),
     113            new DeprecatedPlugin("remotecontrol", IN_CORE, new RemotecontrolMigration()),
     114            new DeprecatedPlugin("imagery", IN_CORE),
     115            new DeprecatedPlugin("slippymap", IN_CORE),
     116            new DeprecatedPlugin("wmsplugin", IN_CORE),
     117        });
     118    }
     119
     120    public static class DeprecatedPlugin implements Comparable<DeprecatedPlugin> {
     121        public String name;
     122        // short explanation, can be null
     123        public String reason;
     124        // migration, can be null
     125        private Runnable migration;
     126
     127        public DeprecatedPlugin(String name) {
     128            this.name = name;
     129        }
     130
     131        public DeprecatedPlugin(String name, String reason) {
     132            this.name = name;
     133            this.reason = reason;
     134        }
     135
     136        public DeprecatedPlugin(String name, String reason, Runnable migration) {
     137            this.name = name;
     138            this.reason = reason;
     139            this.migration = migration;
     140        }
     141
     142        public void migrate() {
     143            if (migration != null) {
     144                migration.run();
     145            }
     146        }
     147
     148        public int compareTo(DeprecatedPlugin o) {
     149            return name.compareTo(o.name);
    94150        }
    95151    }
     
    111167     */
    112168    private static void filterDeprecatedPlugins(Window parent, Collection<String> plugins) {
    113         Set<String> removedPlugins = new TreeSet<String>();
    114         for (String p : DEPRECATED_PLUGINS.keySet()) {
    115             if (plugins.contains(p)) {
    116                 plugins.remove(p);
    117                 Main.pref.removeFromCollection("plugins", p);
    118                 removedPlugins.add(p);
     169        Set<DeprecatedPlugin> removedPlugins = new TreeSet<DeprecatedPlugin>();
     170        for (DeprecatedPlugin depr : DEPRECATED_PLUGINS) {
     171            if (plugins.contains(depr.name)) {
     172                plugins.remove(depr.name);
     173                Main.pref.removeFromCollection("plugins", depr.name);
     174                removedPlugins.add(depr);
     175                depr.migrate();
    119176            }
    120177        }
     
    132189        ));
    133190        sb.append("<ul>");
    134         for (String name: removedPlugins) {
    135             sb.append("<li>").append(name);
    136             String explanation = DEPRECATED_PLUGINS.get(name);
    137             if (explanation != null) {
    138                 sb.append(" ("+explanation+")");
     191        for (DeprecatedPlugin depr: removedPlugins) {
     192            sb.append("<li>").append(depr.name);
     193            if (depr.reason != null) {
     194                sb.append(" (").append(depr.reason).append(")");
    139195            }
    140196            sb.append("</li>");
Note: See TracChangeset for help on using the changeset viewer.