Changeset 18011 in josm for trunk


Ignore:
Timestamp:
2021-07-13T22:49:09+02:00 (3 years ago)
Author:
Don-vip
Message:

see #17177 - add debug log on saving, wait for saving in testMapillaryStyle, code style

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/style/MapboxVectorStyle.java

    r17990 r18011  
    1717import java.util.List;
    1818import java.util.Map;
     19import java.util.Map.Entry;
    1920import java.util.Objects;
    2021import java.util.Optional;
     
    2425import javax.imageio.ImageIO;
    2526import javax.json.Json;
    26 import javax.json.JsonArray;
    2727import javax.json.JsonObject;
    2828import javax.json.JsonReader;
    29 import javax.json.JsonStructure;
    3029import javax.json.JsonValue;
    3130
     
    6059                    BufferedReader reader = style.getContentReader();
    6160                    JsonReader jsonReader = Json.createReader(reader)) {
    62                 JsonStructure structure = jsonReader.read();
    63                 return new MapboxVectorStyle(structure.asJsonObject());
     61                return new MapboxVectorStyle(jsonReader.read().asJsonObject());
    6462            } catch (IOException e) {
    6563                Logging.error(e);
     
    10098            final List<Source> sourceList;
    10199            if (jsonObject.containsKey("sources") && jsonObject.get("sources").getValueType() == JsonValue.ValueType.OBJECT) {
    102                 final JsonObject sourceObj = jsonObject.getJsonObject("sources");
    103                 sourceList = sourceObj.entrySet().stream().filter(entry -> entry.getValue().getValueType() == JsonValue.ValueType.OBJECT)
     100                sourceList = jsonObject.getJsonObject("sources").entrySet().stream()
     101                  .filter(entry -> entry.getValue().getValueType() == JsonValue.ValueType.OBJECT)
    104102                  .map(entry -> {
    105103                      try {
     
    119117            final List<Layers> layers;
    120118            if (jsonObject.containsKey("layers") && jsonObject.get("layers").getValueType() == JsonValue.ValueType.ARRAY) {
    121                 JsonArray lArray = jsonObject.getJsonArray("layers");
    122                 layers = lArray.stream().filter(JsonObject.class::isInstance).map(JsonObject.class::cast).map(obj -> new Layers(id, obj))
     119                layers = jsonObject.getJsonArray("layers").stream()
     120                  .filter(JsonObject.class::isInstance).map(JsonObject.class::cast).map(obj -> new Layers(id, obj))
    123121                  .collect(Collectors.toList());
    124122            } else {
     
    130128            // Abuse HashMap null (null == default)
    131129            this.sources = new LinkedHashMap<>();
    132             for (Map.Entry<Optional<Source>, List<Layers>> entry : sourceLayer.entrySet()) {
     130            for (Entry<Optional<Source>, List<Layers>> entry : sourceLayer.entrySet()) {
    133131                final Source source = entry.getKey().orElse(null);
    134132                final String data = entry.getValue().stream().map(Layers::toString).collect(Collectors.joining());
     
    159157        // HiDPI images first -- if this succeeds, don't bother with the lower resolution (JOSM has no method to switch)
    160158        try (CachedFile spriteJson = new CachedFile(this.spriteUrl + "@2x.json");
    161           CachedFile spritePng = new CachedFile(this.spriteUrl + "@2x.png")) {
     159             CachedFile spritePng = new CachedFile(this.spriteUrl + "@2x.png")) {
    162160            if (parseSprites(spriteJson, spritePng)) {
    163161                return;
     
    165163        }
    166164        try (CachedFile spriteJson = new CachedFile(this.spriteUrl + ".json");
    167         CachedFile spritePng = new CachedFile(this.spriteUrl + ".png")) {
     165             CachedFile spritePng = new CachedFile(this.spriteUrl + ".png")) {
    168166            parseSprites(spriteJson, spritePng);
    169167        }
     
    193191            return false;
    194192        }
    195         for (Map.Entry<String, JsonValue> entry : spriteObject.entrySet()) {
     193        for (Entry<String, JsonValue> entry : spriteObject.entrySet()) {
    196194            final JsonObject info = entry.getValue().asJsonObject();
    197195            int width = info.getInt("width");
     
    218216        }
    219217        final File toSave = new File(location, name);
     218        Logging.debug("Saving {0} to {1}...", object.getClass().getSimpleName(), toSave);
    220219        try {
    221220            if (object instanceof BufferedImage) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r17994 r18011  
    9595    static final Set<String> SUPPORTED_KEYS = new HashSet<>();
    9696    static {
    97         Field[] declaredFields = StyleKeys.class.getDeclaredFields();
    98         for (Field f : declaredFields) {
     97        for (Field f : StyleKeys.class.getDeclaredFields()) {
    9998            try {
    10099                SUPPORTED_KEYS.add((String) f.get(null));
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/style/MapboxVectorStyleTest.java

    r17990 r18011  
    2121import java.util.ArrayList;
    2222import java.util.Collection;
     23import java.util.List;
    2324import java.util.Map;
    2425import java.util.Objects;
     
    127128        MapCSSStyleSource styleSource2 = (MapCSSStyleSource) sources.get(source2).getStyleSources().get(0);
    128129
     130        awaitSaveFinished();
     131
     132        assertTrue(styleSource1.url.endsWith("source1.mapcss"));
     133        assertTrue(styleSource2.url.endsWith("source2.mapcss"));
     134
     135        MapCSSStyleSource mapCSSStyleSource1 = new MapCSSStyleSource(styleSource1.url, styleSource1.name, styleSource1.title);
     136        MapCSSStyleSource mapCSSStyleSource2 = new MapCSSStyleSource(styleSource2.url, styleSource2.name, styleSource2.title);
     137
     138        assertEquals(styleSource1, mapCSSStyleSource1);
     139        assertEquals(styleSource2, mapCSSStyleSource2);
     140    }
     141
     142    private static void awaitSaveFinished() {
    129143        AtomicBoolean saveFinished = new AtomicBoolean();
    130144        MainApplication.worker.execute(() -> saveFinished.set(true));
    131145        Awaitility.await().atMost(Durations.ONE_SECOND).until(saveFinished::get);
    132 
    133         assertTrue(styleSource1.url.endsWith("source1.mapcss"));
    134         assertTrue(styleSource2.url.endsWith("source2.mapcss"));
    135 
    136         MapCSSStyleSource mapCSSStyleSource1 = new MapCSSStyleSource(styleSource1.url, styleSource1.name, styleSource1.title);
    137         MapCSSStyleSource mapCSSStyleSource2 = new MapCSSStyleSource(styleSource2.url, styleSource2.name, styleSource2.title);
    138 
    139         assertEquals(styleSource1, mapCSSStyleSource1);
    140         assertEquals(styleSource2, mapCSSStyleSource2);
    141146    }
    142147
     
    165170        assertEquals(spritePath, style.getSpriteUrl());
    166171
    167         AtomicBoolean saveFinished = new AtomicBoolean();
    168         MainApplication.worker.execute(() -> saveFinished.set(true));
    169         Awaitility.await().atMost(Durations.ONE_SECOND).until(saveFinished::get);
     172        awaitSaveFinished();
    170173
    171174        int scalar = 28; // 255 / 9 (could be 4, but this was a nicer number)
     
    246249        assertNotNull(mapillarySource, style.toString());
    247250        mapillarySource.getStyleSources().forEach(StyleSource::loadStyleSource);
    248         assertEquals(1, mapillarySource.getStyleSources().size());
    249         final MapCSSStyleSource mapillaryCssSource = (MapCSSStyleSource) mapillarySource.getStyleSources().get(0);
     251        List<StyleSource> styleSources = mapillarySource.getStyleSources();
     252        assertEquals(1, styleSources.size());
     253        final MapCSSStyleSource mapillaryCssSource = (MapCSSStyleSource) styleSources.get(0);
     254
     255        awaitSaveFinished();
     256
    250257        assertTrue(mapillaryCssSource.getErrors().isEmpty(), mapillaryCssSource.getErrors().toString());
    251258        final MapCSSRule mapillaryOverview = getRule(mapillaryCssSource, "node", "mapillary-overview");
Note: See TracChangeset for help on using the changeset viewer.