Ignore:
Timestamp:
2023-08-22T17:40:36+02:00 (18 months ago)
Author:
taylor.smock
Message:

Use jakarta.json instead of java.json

This also fixes various lint issues

Location:
applications/editors/josm/plugins/MicrosoftStreetside
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/MicrosoftStreetside/gradle.properties

    r36034 r36122  
    88# Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible.
    99# You can check if the plugin compiles against this version by executing `./gradlew compileJava_minJosm`.
    10 plugin.main.version=18494
     10plugin.main.version=18723
    1111#plugin.version=
    1212# Version of JOSM against which the plugin is compiled
    1313# Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ .
    1414# If not, choose the next higher number that is available, or the gradle build will break.
    15 plugin.compile.version=18494
     15plugin.compile.version=18724
    1616plugin.requires=apache-commons;apache-http;jackson;javafx;log4j;utilsplugin2
    1717
  • applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/oauth/OAuthUtils.java

    r34317 r36122  
    88import java.net.URL;
    99
    10 import javax.json.Json;
    11 import javax.json.JsonException;
    12 import javax.json.JsonObject;
    13 import javax.json.JsonReader;
     10import jakarta.json.Json;
     11import jakarta.json.JsonException;
     12import jakarta.json.JsonObject;
     13import jakarta.json.JsonReader;
    1414
    1515import org.openstreetmap.josm.plugins.streetside.utils.StreetsideProperties;
  • applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonDecoder.java

    r34428 r36122  
    99import java.util.function.Function;
    1010
    11 import javax.json.JsonArray;
    12 import javax.json.JsonNumber;
    13 import javax.json.JsonObject;
    14 import javax.json.JsonValue;
     11import jakarta.json.JsonArray;
     12import jakarta.json.JsonNumber;
     13import jakarta.json.JsonObject;
     14import jakarta.json.JsonValue;
    1515
    16 import org.apache.log4j.Logger;
    1716import org.openstreetmap.josm.data.coor.LatLon;
    1817import org.openstreetmap.josm.tools.I18n;
     18import org.openstreetmap.josm.tools.Logging;
    1919
    2020public final class JsonDecoder {
    21 
    22   final static Logger logger = Logger.getLogger(JsonDecoder.class);
     21  private static final double[] EMPTY_DOUBLE = new double[0];
    2322
    2423  private JsonDecoder() {
     
    6564  static LatLon decodeLatLon(final JsonArray json) {
    6665    final double[] result = decodeDoublePair(json);
    67     if (result != null) {
     66    if (result.length == 2) {
    6867      return new LatLon(result[1], result[0]);
    6968    }
     
    7776   *         if the parameter was not a {@link JsonArray} of exactly size 2 containing two {@link JsonNumber}s
    7877   */
    79   @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull")
    8078  static double[] decodeDoublePair(final JsonArray json) {
    8179    if (
     
    8785      return new double[]{json.getJsonNumber(0).doubleValue(), json.getJsonNumber(1).doubleValue()};
    8886    }
    89     return null;
     87    return EMPTY_DOUBLE;
    9088  }
    9189
     
    9694   * @return the point in time as a {@link Long} value representing the UNIX epoch time, or <code>null</code> if the
    9795   *   parameter does not match the required format (this also triggers a warning via
    98    *   {@link Logger}, or the parameter is <code>null</code>).
     96   *   {@link Logging}, or the parameter is <code>null</code>).
    9997   */
    10098  static Long decodeTimestamp(final String timestamp) {
     
    104102      } catch (ParseException e) {
    105103        StackTraceElement calledBy = e.getStackTrace()[Math.min(e.getStackTrace().length - 1, 2)];
    106         logger.warn(I18n.tr(String.format(
     104        Logging.warn(I18n.tr(String.format(
    107105          "Could not decode time from the timestamp `%s` (called by %s.%s:%d)",
    108106          timestamp, calledBy.getClassName(), calledBy.getMethodName(), calledBy.getLineNumber()
  • applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonImageDetectionDecoder.java

    r34399 r36122  
    55import java.awt.geom.Path2D;
    66
    7 import javax.json.JsonArray;
    8 import javax.json.JsonNumber;
    9 import javax.json.JsonObject;
    10 import javax.json.JsonValue;
     7import jakarta.json.JsonArray;
     8import jakarta.json.JsonNumber;
     9import jakarta.json.JsonObject;
     10import jakarta.json.JsonValue;
    1111
    12 import org.apache.log4j.Logger;
    1312import org.openstreetmap.josm.plugins.streetside.model.ImageDetection;
    1413import org.openstreetmap.josm.plugins.streetside.utils.StreetsideURL.APIv3;
     14import org.openstreetmap.josm.tools.Logging;
    1515
    1616/**
     
    1919 */
    2020public final class JsonImageDetectionDecoder {
    21 
    22   final static Logger logger = Logger.getLogger(JsonImageDetectionDecoder.class);
    2321
    2422  private JsonImageDetectionDecoder() {
     
    5048    if (json instanceof JsonObject) {
    5149      if (!"Polygon".equals(((JsonObject) json).getString("type", null))) {
    52         logger.warn(
     50        Logging.warn(
    5351          String.format("Image detections using shapes with type=%s are currently not supported!",
    5452          ((JsonObject) json).getString("type", "‹no type set›"))
     
    9391    json.forEach(val -> {
    9492      double[] coord = JsonDecoder.decodeDoublePair(val instanceof JsonArray ? (JsonArray) val : null);
    95       if (shape.getCurrentPoint() == null && coord != null) {
     93      if (shape.getCurrentPoint() == null && coord.length == 2) {
    9694        shape.moveTo(coord[0], coord[1]);
    97       } else if (coord != null) {
     95      } else if (coord != null && coord.length == 2) {
    9896        shape.lineTo(coord[0], coord[1]);
    9997      }
  • applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonSequencesDecoder.java

    r34325 r36122  
    55import java.util.function.Function;
    66
    7 import javax.json.JsonArray;
    8 import javax.json.JsonNumber;
    9 import javax.json.JsonObject;
    10 import javax.json.JsonString;
    11 import javax.json.JsonValue;
     7import jakarta.json.JsonArray;
     8import jakarta.json.JsonNumber;
     9import jakarta.json.JsonObject;
     10import jakarta.json.JsonString;
     11import jakarta.json.JsonValue;
    1212
    1313import org.openstreetmap.josm.data.coor.LatLon;
  • applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonStreetsideDecoder.java

    r34428 r36122  
    22package org.openstreetmap.josm.plugins.streetside.utils.api;
    33
    4 import java.text.ParseException;
    5 import java.text.SimpleDateFormat;
    64import java.util.Collection;
    75import java.util.HashSet;
    8 import java.util.Locale;
    96import java.util.function.Function;
    107
    11 import javax.json.JsonArray;
    12 import javax.json.JsonNumber;
    13 import javax.json.JsonObject;
    14 import javax.json.JsonValue;
     8import org.openstreetmap.josm.data.coor.LatLon;
     9import org.openstreetmap.josm.tools.Logging;
    1510
    16 import org.apache.log4j.Logger;
    17 import org.openstreetmap.josm.data.coor.LatLon;
    18 import org.openstreetmap.josm.tools.I18n;
     11import jakarta.json.JsonArray;
     12import jakarta.json.JsonNumber;
     13import jakarta.json.JsonObject;
    1914
    2015public final class JsonStreetsideDecoder {
    21 
    22   final static Logger logger = Logger.getLogger(JsonStreetsideDecoder.class);
    2316
    2417  private JsonStreetsideDecoder() {
     
    3831   */
    3932  public static <T> Collection<T> decodeFeatureCollection(final JsonObject json, Function<JsonObject, T> featureDecoder) {
    40     final Collection<T> result = new HashSet<>();
    41     if (
    42       json != null && "FeatureCollection".equals(json.getString("type", null)) && json.containsKey("features")
    43     ) {
    44       final JsonValue features = json.get("features");
    45       for (int i = 0; features instanceof JsonArray && i < ((JsonArray) features).size(); i++) {
    46         final JsonValue val = ((JsonArray) features).get(i);
    47         if (val instanceof JsonObject) {
    48           final T feature = featureDecoder.apply((JsonObject) val);
    49           if (feature != null) {
    50             result.add(feature);
    51           }
    52         }
    53       }
    54     }
    55     return result;
     33    return JsonDecoder.decodeFeatureCollection(json, featureDecoder);
    5634  }
    5735
     
    6442   */
    6543  static LatLon decodeLatLon(final JsonArray json) {
    66     final double[] result = decodeDoublePair(json);
    67     if (result != null) {
    68       return new LatLon(result[1], result[0]);
    69     }
    70     return null;
    71   }
    72 
    73   /**
    74    * Decodes a pair of double values, which are stored in a {@link JsonArray} of exactly size 2.
    75    * @param json the {@link JsonArray} containing the two values
    76    * @return a double array which contains the two values in the same order, or <code>null</code>
    77    *         if the parameter was not a {@link JsonArray} of exactly size 2 containing two {@link JsonNumber}s
    78    */
    79   @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull")
    80   static double[] decodeDoublePair(final JsonArray json) {
    81     if (
    82       json != null &&
    83       json.size() == 2 &&
    84       json.get(0) instanceof JsonNumber &&
    85       json.get(1) instanceof JsonNumber
    86     ) {
    87       return new double[]{json.getJsonNumber(0).doubleValue(), json.getJsonNumber(1).doubleValue()};
    88     }
    89     return null;
     44    return JsonDecoder.decodeLatLon(json);
    9045  }
    9146
     
    9651   * @return the point in time as a {@link Long} value representing the UNIX epoch time, or <code>null</code> if the
    9752   *   parameter does not match the required format (this also triggers a warning via
    98    *   {@link Logger}, or the parameter is <code>null</code>).
     53   *   {@link Logging}, or the parameter is <code>null</code>).
    9954   */
    10055  static Long decodeTimestamp(final String timestamp) {
    101     if (timestamp != null) {
    102       try {
    103         return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX", Locale.UK).parse(timestamp).getTime();
    104       } catch (ParseException e) {
    105         StackTraceElement calledBy = e.getStackTrace()[Math.min(e.getStackTrace().length - 1, 2)];
    106         logger.warn(I18n.tr(String.format(
    107           "Could not decode time from the timestamp `%s` (called by %s.%s:%d)",
    108           timestamp, calledBy.getClassName(), calledBy.getMethodName(), calledBy.getLineNumber()
    109         ), e));
    110       }
    111     }
    112     return null;
     56    return JsonDecoder.decodeTimestamp(timestamp);
    11357  }
    11458}
  • applications/editors/josm/plugins/MicrosoftStreetside/src/org/openstreetmap/josm/plugins/streetside/utils/api/JsonStreetsideSequencesDecoder.java

    r34429 r36122  
    55import java.util.function.Function;
    66
    7 import javax.json.JsonArray;
    8 import javax.json.JsonNumber;
    9 import javax.json.JsonObject;
    10 import javax.json.JsonString;
    11 import javax.json.JsonValue;
     7import jakarta.json.JsonArray;
     8import jakarta.json.JsonNumber;
     9import jakarta.json.JsonObject;
     10import jakarta.json.JsonString;
     11import jakarta.json.JsonValue;
    1212
    1313import org.openstreetmap.josm.data.coor.LatLon;
     
    113113
    114114    if (json.getString("id", null) != null && json.getString("la", null) != null && json.getString("lo", null) != null) {
    115         result = new StreetsideSequence(json.getString("id", null), json.getJsonNumber("la").doubleValue(), json.getJsonNumber("lo").doubleValue(), json.getJsonNumber("cd").longValue());
     115        result = new StreetsideSequence(json.getString("id", null),
     116                json.getJsonNumber("la").doubleValue(), json.getJsonNumber("lo").doubleValue(), json.getJsonNumber("cd").longValue());
    116117    }
    117118
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/JsonUtil.java

    r34386 r36122  
    55import java.nio.charset.StandardCharsets;
    66
    7 import javax.json.Json;
    8 import javax.json.JsonObject;
     7import jakarta.json.Json;
     8import jakarta.json.JsonObject;
    99
    1010public final class JsonUtil {
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/api/JsonDecoderTest.java

    r36064 r36122  
    33
    44
     5import static org.junit.jupiter.api.Assertions.assertArrayEquals;
    56import static org.junit.jupiter.api.Assertions.assertNull;
    67
     
    910import java.util.function.Function;
    1011
    11 import javax.json.Json;
    12 import javax.json.JsonObject;
     12import jakarta.json.Json;
     13import jakarta.json.JsonObject;
    1314
    1415import org.junit.jupiter.api.Test;
     
    2425  @Test
    2526  void testDecodeDoublePair() {
    26     assertNull(JsonDecoder.decodeDoublePair(null));
     27    assertArrayEquals(new double[0], JsonDecoder.decodeDoublePair(null));
    2728  }
    2829
  • applications/editors/josm/plugins/MicrosoftStreetside/test/unit/org/openstreetmap/josm/plugins/streetside/utils/api/JsonSequencesDecoderTest.java

    r36064 r36122  
    1313import java.util.function.Function;
    1414
    15 import javax.json.Json;
    16 import javax.json.JsonArray;
    17 import javax.json.JsonObject;
    18 import javax.json.JsonValue;
     15import jakarta.json.Json;
     16import jakarta.json.JsonArray;
     17import jakarta.json.JsonObject;
     18import jakarta.json.JsonValue;
    1919
    2020import org.junit.jupiter.api.Assertions;
Note: See TracChangeset for help on using the changeset viewer.