Changeset 3730 in josm for trunk/src/org/openstreetmap/josm


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

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

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/preferences/BooleanProperty.java

    r3720 r3730  
    44import org.openstreetmap.josm.Main;
    55
    6 public class BooleanProperty {
     6public class BooleanProperty extends AbstractProperty {
    77
    8     private final String key;
    9     private final boolean defaultValue;
     8    protected final boolean defaultValue;
    109
    1110    public BooleanProperty(String key, boolean defaultValue) {
    12         this.key = key;
     11        super(key);
    1312        this.defaultValue = defaultValue;
    1413    }
     
    2221    }
    2322
    24     public String getKey() {
    25         return key;
    26     }
    27 
    2823    public boolean isDefaultValue() {
    2924        return defaultValue;
    3025    }
    31 
    3226}
  • trunk/src/org/openstreetmap/josm/data/preferences/CollectionProperty.java

    r3720 r3730  
    66import org.openstreetmap.josm.Main;
    77
    8 public class CollectionProperty {
    9     private final String key;
    10     private final Collection<String> defaultValue;
     8public class CollectionProperty extends AbstractProperty {
     9    protected final Collection<String> defaultValue;
    1110
    1211    public CollectionProperty(String key, Collection<String> defaultValue) {
    13         this.key = key;
     12        super(key);
    1413        this.defaultValue = defaultValue;
    1514    }
     
    2322    }
    2423
    25     public String getKey() {
    26         return key;
    27     }
    28 
    2924    public Collection<String> getDefaultValue() {
    3025        return defaultValue;
  • trunk/src/org/openstreetmap/josm/data/preferences/IntegerProperty.java

    r3720 r3730  
    44import org.openstreetmap.josm.Main;
    55
    6 public class IntegerProperty {
     6public class IntegerProperty extends AbstractProperty {
    77
    8     private final String key;
    9     private final int defaultValue;
     8    protected final int defaultValue;
    109
    1110    public IntegerProperty(String key, int defaultValue) {
    12         this.key = key;
     11        super(key);
    1312        this.defaultValue = defaultValue;
    1413    }
     
    3837    }
    3938
    40     public String getKey() {
    41         return key;
    42     }
    43 
    4439    public int getDefaultValue() {
    4540        return defaultValue;
  • trunk/src/org/openstreetmap/josm/data/preferences/StringProperty.java

    r3720 r3730  
    44import org.openstreetmap.josm.Main;
    55
    6 public class StringProperty {
     6public class StringProperty extends AbstractProperty {
    77
    8     private final String key;
    9     private final String defaultValue;
     8    protected final String defaultValue;
    109
    1110    public StringProperty(String key, String defaultValue) {
    12         this.key = key;
     11        super(key);
    1312        this.defaultValue = defaultValue;
    1413    }
     
    2221    }
    2322
    24     public String getKey() {
    25         return key;
    26     }
    27 
    2823    public String getDefaultValue() {
    2924        return defaultValue;
  • 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>");
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r3669 r3730  
    201201
    202202    protected void filterOldPlugins() {
    203         for (String p : PluginHandler.DEPRECATED_PLUGINS.keySet()) {
     203        for (PluginHandler.DeprecatedPlugin p : PluginHandler.DEPRECATED_PLUGINS) {
    204204            if (canceled)return;
    205             if (availablePlugins.containsKey(p)) {
    206                 availablePlugins.remove(p);
     205            if (availablePlugins.containsKey(p.name)) {
     206                availablePlugins.remove(p.name);
    207207            }
    208208        }
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r3669 r3730  
    295295    protected List<PluginInformation> filterDeprecatedPlugins(List<PluginInformation> plugins) {
    296296        List<PluginInformation> ret = new ArrayList<PluginInformation>(plugins.size());
    297         HashSet<String> deprecatedPluginNames = new HashSet<String>(PluginHandler.DEPRECATED_PLUGINS.keySet());
     297        HashSet<String> deprecatedPluginNames = new HashSet<String>();
     298        for (PluginHandler.DeprecatedPlugin p : PluginHandler.DEPRECATED_PLUGINS) {
     299            deprecatedPluginNames.add(p.name);
     300        }
    298301        for (PluginInformation plugin: plugins) {
    299302            if (deprecatedPluginNames.contains(plugin.name)) {
Note: See TracChangeset for help on using the changeset viewer.