Changeset 12982 in josm for trunk/src


Ignore:
Timestamp:
2017-10-11T14:09:31+02:00 (7 years ago)
Author:
bastiK
Message:

remove old migration code (see #15410)

File:
1 edited

Legend:

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

    r12946 r12982  
    1717import java.lang.reflect.Field;
    1818import java.nio.charset.StandardCharsets;
    19 import java.util.AbstractMap;
    2019import java.util.ArrayList;
    2120import java.util.Collection;
     
    3736import java.util.regex.Matcher;
    3837import java.util.regex.Pattern;
    39 import java.util.stream.Collectors;
    4038import java.util.stream.Stream;
    4139
     
    5654import org.openstreetmap.josm.spi.preferences.Setting;
    5755import org.openstreetmap.josm.spi.preferences.StringSetting;
    58 import org.openstreetmap.josm.data.preferences.sources.ExtendedSourceEntry;
    59 import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
    6056import org.openstreetmap.josm.io.OfflineAccessException;
    6157import org.openstreetmap.josm.io.OnlineResource;
     
    10096
    10197    private static final String[] OBSOLETE_PREF_KEYS = {
    102       "imagery.layers.addedIds", /* remove entry after June 2017 */
    10398      "projection", /* remove entry after Nov. 2017 */
    10499      "projection.sub", /* remove entry after Nov. 2017 */
     
    15611556     */
    15621557    private void removeObsolete(int loadedVersion) {
    1563         // drop in March 2017
    1564         removeUrlFromEntries(loadedVersion, 10063,
    1565                 "validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries",
    1566                 "resource://data/validator/power.mapcss");
    1567         // drop in March 2017
    1568         if (loadedVersion < 11058) {
    1569             migrateOldColorKeys();
    1570         }
    1571         // drop in September 2017
    1572         if (loadedVersion < 11424) {
    1573             addNewerDefaultEntry(
    1574                     "validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries",
    1575                     "resource://data/validator/territories.mapcss");
    1576         }
    1577 
    15781558        for (String key : OBSOLETE_PREF_KEYS) {
    15791559            if (settingsMap.containsKey(key)) {
     
    15841564    }
    15851565
    1586     private void migrateOldColorKeys() {
    1587         settingsMap.keySet().stream()
    1588                 .filter(key -> key.startsWith(COLOR_PREFIX))
    1589                 .flatMap(this::searchOldColorKey)
    1590                 .collect(Collectors.toList()) // to avoid ConcurrentModificationException
    1591                 .forEach(entry -> {
    1592                     final String oldKey = entry.getKey();
    1593                     final String newKey = entry.getValue();
    1594                     Logging.info("Migrating old color key {0} => {1}", oldKey, newKey);
    1595                     put(newKey, get(oldKey));
    1596                     put(oldKey, null);
    1597                 });
    1598     }
    1599 
    1600     private Stream<AbstractMap.SimpleImmutableEntry<String, String>> searchOldColorKey(String key) {
    1601         final String newKey = ColorProperty.getColorKey(key.substring(COLOR_PREFIX.length()));
    1602         return key.equals(newKey) || settingsMap.containsKey(newKey)
    1603                 ? Stream.empty()
    1604                 : Stream.of(new AbstractMap.SimpleImmutableEntry<>(key, newKey));
    1605     }
    1606 
    1607     private void removeUrlFromEntries(int loadedVersion, int versionMax, String key, String urlPart) {
    1608         if (loadedVersion < versionMax) {
    1609             Setting<?> setting = settingsMap.get(key);
    1610             if (setting instanceof MapListSetting) {
    1611                 List<Map<String, String>> l = new LinkedList<>();
    1612                 boolean modified = false;
    1613                 for (Map<String, String> map: ((MapListSetting) setting).getValue()) {
    1614                     String url = map.get("url");
    1615                     if (url != null && url.contains(urlPart)) {
    1616                         modified = true;
    1617                     } else {
    1618                         l.add(map);
    1619                     }
    1620                 }
    1621                 if (modified) {
    1622                     putListOfMaps(key, l);
    1623                 }
    1624             }
    1625         }
    1626     }
    1627 
    1628     private void addNewerDefaultEntry(String key, final String url) {
    1629         Setting<?> setting = settingsMap.get(key);
    1630         if (setting instanceof MapListSetting) {
    1631             List<Map<String, String>> l = new ArrayList<>(((MapListSetting) setting).getValue());
    1632             if (l.stream().noneMatch(x -> x.containsValue(url))) {
    1633                 ValidatorPrefHelper helper = ValidatorPrefHelper.INSTANCE;
    1634                 Optional<ExtendedSourceEntry> val = helper.getDefault().stream().filter(x -> url.equals(x.url)).findFirst();
    1635                 if (val.isPresent()) {
    1636                     l.add(helper.serialize(val.get()));
    1637                 }
    1638                 putListOfMaps(key, l);
    1639             }
    1640         }
    1641     }
    1642 
    16431566    /**
    16441567     * Enables or not the preferences file auto-save mechanism (save each time a setting is changed).
Note: See TracChangeset for help on using the changeset viewer.