diff --git a/.github/workflows/ant-release.yml b/.github/workflows/ant-release.yml index 82a84aa93..55ee9ae48 100644 --- a/.github/workflows/ant-release.yml +++ b/.github/workflows/ant-release.yml @@ -8,6 +8,6 @@ jobs: call-workflow: uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1 with: - josm-revision: "r18613" + josm-revision: "r18723" diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index 880c5e31d..59a83c6a6 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -18,7 +18,7 @@ jobs: call-workflow: strategy: matrix: - josm-revision: ["", "r18613"] + josm-revision: ["", "r18723"] uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1 with: josm-revision: ${{ matrix.josm-revision }} diff --git a/build.gradle.kts b/build.gradle.kts index 3cd6a9217..7c2db2961 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -178,6 +178,7 @@ josm { debugPort = 7051 manifest { // See https://floscher.gitlab.io/gradle-josm-plugin/kdoc/latest/gradle-josm-plugin/org.openstreetmap.josm.gradle.plugin.config/-josm-manifest/old-version-download-link.html + oldVersionDownloadLink(18613, "2.1.5", URL("https://github.com/JOSM/Mapillary/releases/download/v2.1.5/Mapillary.jar")); oldVersionDownloadLink(18531, "v2.0.2", URL("https://github.com/JOSM/Mapillary/releases/download/v2.0.2/Mapillary.jar")); oldVersionDownloadLink(17903, "v2.0.0-alpha.36", URL("https://github.com/JOSM/Mapillary/releases/download/v2.0.0-alpha.36/Mapillary.jar")) } diff --git a/gradle.properties b/gradle.properties index 6315a676b..b81d24d1d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,11 @@ plugin.icon=images/mapillary-logo.svg plugin.link=https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Mapillary # Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible. # You can check if the plugin compiles against this version by executing `./gradlew compileJava_minJosm`. -plugin.main.version=18613 +plugin.main.version=18723 # Version of JOSM against which the plugin is compiled # Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ . # If not, choose the next higher number that is available, or the gradle build will break. -plugin.compile.version=18613 +plugin.compile.version=18724 # The datepicker plugin is currently in the source tree. TODO fix plugin.requires=apache-commons diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/actions/SmartEditRemoveAction.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/actions/SmartEditRemoveAction.java index dcd1d9d0a..e2f9da7d2 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/actions/SmartEditRemoveAction.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/actions/SmartEditRemoveAction.java @@ -9,11 +9,11 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonObjectBuilder; import javax.swing.JOptionPane; import javax.swing.text.AbstractDocument; +import jakarta.json.Json; +import jakarta.json.JsonObjectBuilder; import org.openstreetmap.josm.actions.JosmAction; import org.openstreetmap.josm.data.vector.VectorPrimitive; import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/cache/Caches.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/cache/Caches.java index 582c0bc55..d6f9aa576 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/cache/Caches.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/cache/Caches.java @@ -23,12 +23,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonReader; -import javax.json.JsonValue; -import javax.json.stream.JsonParser; import javax.swing.JOptionPane; +import jakarta.json.Json; +import jakarta.json.JsonReader; +import jakarta.json.JsonValue; +import jakarta.json.stream.JsonParser; import org.apache.commons.jcs3.access.CacheAccess; import org.apache.commons.jcs3.access.behavior.ICacheAccess; import org.apache.commons.jcs3.engine.behavior.ICompositeCacheAttributes; @@ -54,7 +54,7 @@ public final class Caches { /** The cache for metadata objects */ public static final MapillaryCacheAccess META_DATA_CACHE = new MapillaryCacheAccess<>( - JCSCacheManager.getCache("mapillary:metadata", 100, 100000, getCacheDirectory().getPath()), string -> { + JCSCacheManager.getCache("mapillary:metadata", 100, 100_000, getCacheDirectory().getPath()), string -> { try (JsonParser reader = Json .createParser(new ByteArrayInputStream(string.getBytes(StandardCharsets.UTF_8)))) { while (reader.hasNext()) { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/MapillaryDownloader.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/MapillaryDownloader.java index a3cde3cbb..5ab0589c3 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/MapillaryDownloader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/MapillaryDownloader.java @@ -3,8 +3,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; @@ -18,13 +17,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonNumber; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonString; -import javax.json.JsonValue; +import jakarta.json.Json; +import jakarta.json.JsonNumber; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; +import jakarta.json.JsonString; +import jakarta.json.JsonValue; import org.openstreetmap.josm.data.osm.IWay; import org.openstreetmap.josm.plugins.mapillary.cache.Caches; import org.openstreetmap.josm.plugins.mapillary.gui.layer.MapillaryLayer; @@ -156,7 +155,7 @@ private static void separatelyCacheDownloadedImages(final JsonObject jsonObject) } @Nullable - static JsonObject getUrlResponse(@Nonnull URL url) { + static JsonObject getUrlResponse(@Nonnull URI url) { try { return OAuthUtils.getWithHeader(url); } catch (IOException e) { @@ -168,8 +167,8 @@ static JsonObject getUrlResponse(@Nonnull URL url) { @Nullable static JsonObject getUrlResponse(@Nonnull String url) { try { - return getUrlResponse(new URL(url)); - } catch (MalformedURLException e) { + return getUrlResponse(URI.create(url)); + } catch (IllegalArgumentException e) { Logging.error(e); } return null; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/ObjectDetections.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/ObjectDetections.java index a38594a5e..63195c933 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/ObjectDetections.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/ObjectDetections.java @@ -16,13 +16,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonString; -import javax.json.stream.JsonParser; import javax.swing.ImageIcon; +import jakarta.json.Json; +import jakarta.json.JsonArray; +import jakarta.json.JsonObject; +import jakarta.json.JsonString; +import jakarta.json.stream.JsonParser; import org.openstreetmap.josm.data.osm.Tag; import org.openstreetmap.josm.data.osm.TagMap; import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/OrganizationRecord.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/OrganizationRecord.java index df4c151cb..5f268c7ad 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/OrganizationRecord.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/OrganizationRecord.java @@ -4,7 +4,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; import java.io.Serializable; -import java.net.URL; +import java.net.URI; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -15,9 +15,9 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; import javax.imageio.ImageIO; -import javax.json.JsonObject; import javax.swing.ImageIcon; +import jakarta.json.JsonObject; import org.openstreetmap.josm.data.imagery.vectortile.mapbox.MVTTile; import org.openstreetmap.josm.data.osm.INode; import org.openstreetmap.josm.gui.MainApplication; @@ -85,7 +85,7 @@ private static ImageIcon createAvatarIcon(@Nullable String avatar) { */ private static BufferedImage fetchAvatarIcon(String url) { try { - HttpClient client = HttpClient.create(new URL(url)); + HttpClient client = HttpClient.create(URI.create(url).toURL()); OAuthUtils.addAuthenticationHeader(client); HttpClient.Response response = client.connect(); if (response.getResponseCode() >= 200 && response.getResponseCode() < 400) { @@ -127,7 +127,7 @@ private static OrganizationRecord getNewOrganization(long id) { // TODO check for API in v4 (preferably one that doesn't need user auth) final String url = MapillaryConfig.getUrls().getOrganizationInformation(id); try { - final JsonObject data = OAuthUtils.getWithHeader(new URL(url)); + final JsonObject data = OAuthUtils.getWithHeader(URI.create(url)); final OrganizationRecord organizationRecord = decodeNewOrganization(data); // Ensure that we aren't blocking the main EDT thread MainApplication.worker.execute(() -> LISTENERS.fireEvent(l -> l.organizationAdded(organizationRecord))); @@ -213,15 +213,33 @@ public String getNiceName() { return niceName; } + /** + * Add listener for organizations + * + * @param listener The listener to notify when a new organization is added + */ public static void addOrganizationListener(OrganizationRecordListener listener) { LISTENERS.addListener(listener); } + /** + * Remove a listener for organizations + * + * @param listener The listener to remove from the notification list + */ public static void removeOrganizationListener(OrganizationRecordListener listener) { LISTENERS.removeListener(listener); } + /** + * The interface for listening for new organizations + */ public interface OrganizationRecordListener extends Serializable { + /** + * Called when a new organization is added + * + * @param organization The new organization + */ void organizationAdded(OrganizationRecord organization); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/smartedit/IgnoredObjects.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/smartedit/IgnoredObjects.java index 623a4e22f..f38559914 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/smartedit/IgnoredObjects.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/data/mapillary/smartedit/IgnoredObjects.java @@ -13,11 +13,10 @@ import java.util.Set; import java.util.stream.Collectors; -import javax.json.Json; -import javax.json.JsonNumber; -import javax.json.JsonObject; -import javax.json.stream.JsonParser; - +import jakarta.json.Json; +import jakarta.json.JsonNumber; +import jakarta.json.JsonObject; +import jakarta.json.stream.JsonParser; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; import org.openstreetmap.josm.gui.MainApplication; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/dialog/OldVersionDialog.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/dialog/OldVersionDialog.java index 92c92820b..8864a49e6 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/dialog/OldVersionDialog.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/dialog/OldVersionDialog.java @@ -9,13 +9,13 @@ import java.util.Optional; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonValue; import javax.swing.JOptionPane; +import jakarta.json.Json; +import jakarta.json.JsonException; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; +import jakarta.json.JsonValue; import org.openstreetmap.josm.data.Version; import org.openstreetmap.josm.data.preferences.IntegerProperty; import org.openstreetmap.josm.data.preferences.StringProperty; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java index 8ecf4bfce..8d16d952f 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java @@ -5,7 +5,7 @@ import java.awt.Shape; import java.io.ByteArrayInputStream; import java.io.IOException; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; @@ -23,10 +23,10 @@ import java.util.function.Supplier; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; import org.apache.commons.jcs3.access.CacheAccess; import org.openstreetmap.josm.data.cache.JCSCacheManager; import org.openstreetmap.josm.data.osm.IPrimitive; @@ -333,7 +333,7 @@ private static List> getDetections(long key) { final String urlString = MapillaryConfig.getUrls().getDetectionInformation(key); final String jsonString = Caches.META_DATA_CACHE.get(urlString, () -> { try { - final JsonObject jsonObject = OAuthUtils.getWithHeader(new URL(urlString)); + final JsonObject jsonObject = OAuthUtils.getWithHeader(URI.create(urlString)); return jsonObject != null ? jsonObject.toString() : null; } catch (IOException e) { Logging.error(e); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java index b4adf3329..3363aabb9 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java @@ -8,9 +8,8 @@ import java.util.Map; import java.util.stream.Collectors; -import javax.json.JsonString; -import javax.json.JsonValue; - +import jakarta.json.JsonString; +import jakarta.json.JsonValue; import org.openstreetmap.josm.data.preferences.AbstractProperty; import org.openstreetmap.josm.plugins.mapillary.spi.preferences.MapillaryConfig; import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryProperties; @@ -65,7 +64,7 @@ public static synchronized Map getUserInformation() { if (userInformation == null) { try { userInformation = OAuthUtils.getWithHeader(MapillaryConfig.getUrls().getUserInformation()).entrySet() - .parallelStream().filter(e -> JsonValue.ValueType.STRING.equals(e.getValue().getValueType())) + .parallelStream().filter(e -> JsonValue.ValueType.STRING == e.getValue().getValueType()) .collect(Collectors.toMap(Map.Entry::getKey, e -> ((JsonString) e.getValue()).getString())); } catch (IOException e) { Logging.log(Logging.LEVEL_WARN, "Invalid Mapillary token, resetting field", e); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java index 8ed4d7f30..4070ddba2 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java @@ -8,17 +8,16 @@ import java.net.BindException; import java.net.ServerSocket; import java.net.Socket; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.stream.JsonParsingException; - +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; +import jakarta.json.stream.JsonParsingException; import org.openstreetmap.josm.plugins.mapillary.spi.preferences.MapillaryConfig; import org.openstreetmap.josm.tools.HttpClient; import org.openstreetmap.josm.tools.I18n; @@ -38,6 +37,11 @@ public class OAuthPortListener extends Thread { I18n.tr("Mapillary login"), I18n.tr("Login successful, return to JOSM.")); private final MapillaryLoginListener callback; + /** + * Create a new OAuth callback listener + * + * @param loginCallback The callback to call once we have authenticated + */ public OAuthPortListener(MapillaryLoginListener loginCallback) { this.callback = loginCallback; } @@ -76,7 +80,8 @@ public void run() { MapillaryUser.reset(); - final HttpClient client = HttpClient.create(new URL("https://graph.mapillary.com/token"), "POST"); + final HttpClient client = HttpClient.create(URI.create("https://graph.mapillary.com/token").toURL(), + "POST"); client.setHeader("Authorization", "OAuth " + MapillaryConfig.getUrls().getClientSecret()); client.setRequestBody(("grant_type=authorization_code&client_id=" + MapillaryConfig.getUrls().getClientId() + "&code=" + authorizationCode).getBytes(StandardCharsets.UTF_8)); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java index 5f8a8106c..b158a266f 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java @@ -18,13 +18,13 @@ import java.util.Collections; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonException; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonStructure; import javax.swing.JOptionPane; +import jakarta.json.Json; +import jakarta.json.JsonException; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; +import jakarta.json.JsonStructure; import org.openstreetmap.josm.gui.Notification; import org.openstreetmap.josm.gui.util.GuiHelper; import org.openstreetmap.josm.io.CachedFile; @@ -212,7 +212,7 @@ private static void refreshAuthorization(final String authorizationCode) throws String content = null; IMapillaryUrls urls = MapillaryConfig.getUrls(); try { - final HttpClient client = HttpClient.create(new URL(urls.getTokenUrl()), "POST"); + final HttpClient client = HttpClient.create(URI.create(urls.getTokenUrl()).toURL(), "POST"); client.setHeader(AUTHORIZATION, BEARER + urls.getClientSecret()); client.setRequestBody( ("grant_type=refresh_token&client_id=" + urls.getClientId() + "&refresh_token=" + authorizationCode) diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/ApiKeyReader.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/ApiKeyReader.java index 6c7e6af30..4c576b79e 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/ApiKeyReader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/spi/preferences/ApiKeyReader.java @@ -4,10 +4,9 @@ import java.io.IOException; import java.io.InputStream; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; - +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; import org.openstreetmap.josm.spi.preferences.Config; import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.ResourceProvider; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryMapFeatureUtils.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryMapFeatureUtils.java index 7ccdf63ad..133e8c7a9 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryMapFeatureUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryMapFeatureUtils.java @@ -3,7 +3,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.Locale; @@ -13,9 +13,9 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonReader; +import jakarta.json.Json; +import jakarta.json.JsonReader; import org.openstreetmap.josm.data.osm.IPrimitive; import org.openstreetmap.josm.data.vector.VectorPrimitive; import org.openstreetmap.josm.plugins.mapillary.cache.Caches; @@ -40,7 +40,8 @@ public enum MapFeatureProperties { /** string, name of the class which this object represent */ VALUE, /* - * Start queryable info (seen_at in tiles as timestamp in ms but is in query as timestamp in YYYY-mm-DDTHH:MM:SS + * Start queryable info (seen_at in tiles as timestamp in ms but is in query as a timestamp in + * YYYY-mm-DDTHH:MM:SS * format) */ /** @@ -50,13 +51,13 @@ public enum MapFeatureProperties { /** * int, timestamp in ms since epoch, capture time of the earliest image on which the detection contribute to * this - * map feature, can also be timestamp (YYYY-MM-DDTHH:MM:SS) + * map feature, can also be a timestamp (YYYY-MM-DDTHH:MM:SS) */ FIRST_SEEN_AT, /** * int, timestamp in ms since epoch, capture time of the latest image on which the detection contribute to this * map - * feature, can also be timestamp (YYYY-MM-DDTHH:MM:SS) + * feature, can also be a timestamp (YYYY-MM-DDTHH:MM:SS) */ LAST_SEEN_AT, /* End info in vector layer */ @@ -197,7 +198,7 @@ private static void updateMapFeature(@Nonnull final IPrimitive primitive) { MapFeatureProperties.GEOMETRY, MapFeatureProperties.IMAGES, MapFeatureProperties.ALIGNED_DIRECTION); final String json = Caches.META_DATA_CACHE.get(url, () -> { try { - return OAuthUtils.getWithHeader(new URL(url)).toString(); + return OAuthUtils.getWithHeader(URI.create(url)).toString(); } catch (IOException e) { Logging.error(e); return null; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java index 2f5b81f1e..bdd92de78 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java @@ -10,14 +10,13 @@ import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonString; -import javax.json.JsonStructure; -import javax.json.JsonValue; - +import jakarta.json.Json; +import jakarta.json.JsonArray; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; +import jakarta.json.JsonString; +import jakarta.json.JsonStructure; +import jakarta.json.JsonValue; import org.openstreetmap.josm.data.osm.IPrimitive; import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.plugins.mapillary.gui.layer.MapillaryLayer; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonDecoder.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonDecoder.java index f22c58590..97b7123fb 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonDecoder.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonDecoder.java @@ -9,17 +9,20 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.JsonArray; -import javax.json.JsonNumber; -import javax.json.JsonObject; -import javax.json.JsonValue; +import jakarta.json.JsonArray; +import jakarta.json.JsonNumber; +import jakarta.json.JsonObject; +import jakarta.json.JsonValue; import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.gui.util.GuiHelper; import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.bugreport.BugReport; import org.openstreetmap.josm.tools.bugreport.ReportedException; +/** + * Decode json objects + */ public final class JsonDecoder { private static final double[] EMPTY_DOUBLE = new double[0]; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetailsDecoder.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetailsDecoder.java index 31b33fa2d..34baabaaf 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetailsDecoder.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetailsDecoder.java @@ -11,11 +11,12 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonString; -import javax.json.JsonValue; +import jakarta.json.JsonArray; +import jakarta.json.JsonObject; +import jakarta.json.JsonString; +import jakarta.json.JsonValue; +import org.openstreetmap.josm.data.coor.ILatLon; import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.osm.BBox; import org.openstreetmap.josm.data.osm.Tag; @@ -131,7 +132,7 @@ private static LatLon getCoordinates(JsonObject json, boolean useComputedData) { .decodeLatLon(json.getJsonObject(MapillaryImageUtils.ImageProperties.COMPUTED_GEOMETRY.toString()) .getJsonArray("coordinates")); if (computedCoordinates != null && originalCoordinates != null && computedCoordinates - .greatCircleDistance(originalCoordinates) < MapillaryProperties.ASSUMED_HDOP.get()) { + .greatCircleDistance((ILatLon) originalCoordinates) < MapillaryProperties.ASSUMED_HDOP.get()) { return computedCoordinates; } return Utils.firstNonNull(originalCoordinates, computedCoordinates); diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoder.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoder.java index bde67892f..340991943 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoder.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoder.java @@ -15,10 +15,10 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.JsonObject; -import javax.json.JsonString; -import javax.json.JsonValue; +import jakarta.json.JsonObject; +import jakarta.json.JsonString; +import jakarta.json.JsonValue; import org.openstreetmap.josm.data.imagery.vectortile.mapbox.Feature; import org.openstreetmap.josm.data.imagery.vectortile.mapbox.Layer; import org.openstreetmap.josm.data.protobuf.ProtobufParser; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonMapObjectDecoder.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonMapObjectDecoder.java index 2f5f4a8ae..59ad3cd16 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonMapObjectDecoder.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonMapObjectDecoder.java @@ -8,14 +8,15 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.JsonArray; -import javax.json.JsonNumber; -import javax.json.JsonObject; -import javax.json.JsonValue; +import jakarta.json.JsonArray; +import jakarta.json.JsonNumber; +import jakarta.json.JsonObject; +import jakarta.json.JsonValue; import org.openstreetmap.gui.jmapviewer.interfaces.MapObject; import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.osm.INode; @@ -37,6 +38,14 @@ private JsonMapObjectDecoder() { // Private constructor to avoid instantiation } + /** + * Decode a feature object + * + * @param json The object json + * @param primitive The primitive + * @return The primitive with added values as a singleton collection + * @param The primitive type + */ @Nonnull public static Collection decodeMapFeatureObject(@Nullable final JsonValue json, @Nullable final T primitive) { @@ -139,7 +148,7 @@ private static Collection parseImages(final JsonValue value) { final List parsedImages = new ArrayList<>(value.asJsonArray().size()); for (final JsonValue tValue : value.asJsonArray()) { final Collection tParsedImages = parseImages(tValue); - tParsedImages.stream().filter(Objects::nonNull).forEach(parsedImages::add); + parsedImages.addAll(tParsedImages.stream().filter(Objects::nonNull).collect(Collectors.toList())); } return Collections.unmodifiableList(parsedImages); } else if (value.getValueType() == JsonValue.ValueType.OBJECT diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonSequencesDecoder.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonSequencesDecoder.java index b0cfbf616..464ac5ac3 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonSequencesDecoder.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonSequencesDecoder.java @@ -6,12 +6,11 @@ import java.util.Objects; import java.util.stream.Collectors; -import javax.json.JsonArray; -import javax.json.JsonNumber; -import javax.json.JsonObject; -import javax.json.JsonString; -import javax.json.JsonValue; - +import jakarta.json.JsonArray; +import jakarta.json.JsonNumber; +import jakarta.json.JsonObject; +import jakarta.json.JsonString; +import jakarta.json.JsonValue; import org.openstreetmap.josm.data.osm.IWay; import org.openstreetmap.josm.plugins.mapillary.spi.preferences.IMapillaryUrls; import org.openstreetmap.josm.tools.Logging; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonTagMapDecoder.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonTagMapDecoder.java index 9ddae540a..01f3c2b95 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonTagMapDecoder.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonTagMapDecoder.java @@ -3,16 +3,15 @@ import java.util.Map; -import javax.json.JsonObject; -import javax.json.JsonString; -import javax.json.JsonValue; - +import jakarta.json.JsonObject; +import jakarta.json.JsonString; +import jakarta.json.JsonValue; import org.openstreetmap.josm.data.osm.TagMap; /** * Convert a properties object into a TagMap */ -public class JsonTagMapDecoder { +public final class JsonTagMapDecoder { private JsonTagMapDecoder() { // Utility class, shouldn't be instantiated } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonUserProfileDecoder.java b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonUserProfileDecoder.java index c79e6a12f..318efaf05 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonUserProfileDecoder.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonUserProfileDecoder.java @@ -3,12 +3,12 @@ import java.awt.image.BufferedImage; import java.io.IOException; -import java.net.URL; +import java.net.URI; import javax.imageio.ImageIO; -import javax.json.JsonObject; import javax.swing.ImageIcon; +import jakarta.json.JsonObject; import org.openstreetmap.josm.plugins.mapillary.model.UserProfile; import org.openstreetmap.josm.plugins.mapillary.spi.preferences.IMapillaryUrls; import org.openstreetmap.josm.tools.ImageProvider; @@ -45,7 +45,7 @@ public static UserProfile decodeUserProfile(JsonObject json) { ImageIcon icon = null; if (avatar != null) { try { - BufferedImage img = ImageIO.read(new URL(avatar)); + BufferedImage img = ImageIO.read(URI.create(avatar).toURL()); if (img != null) { icon = new ImageIcon(img); } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtilsTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtilsTest.java index c76fb0c3c..419851158 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtilsTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtilsTest.java @@ -8,12 +8,11 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.awt.GraphicsEnvironment; import java.io.IOException; import java.net.HttpURLConnection; -import java.net.URL; +import java.net.URI; import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; @@ -27,10 +26,10 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonObjectBuilder; import mockit.Invocation; import mockit.Mock; import mockit.MockUp; @@ -249,8 +248,8 @@ void testUpdateAuthorizationBadResponse(Duration duration, String accessToken, S @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.APPLICATION_REQUEST_LIMIT_REACHED) - void testApplicationRequestLimitReached() throws IOException { - final URL url = new URL(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); + void testApplicationRequestLimitReached() { + final URI url = URI.create(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); assertDoesNotThrow(() -> OAuthUtils.getWithHeader(url), "Responses may be parsed, which may fail."); assertAll("Application request limit should not log out the user", LOGGED_IN_CHECKS); this.testAuthenticationRefresh(url); @@ -259,7 +258,7 @@ void testApplicationRequestLimitReached() throws IOException { @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.BAD_REQUEST) void testBadRequest() throws IOException { - final URL url = new URL(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); + final URI url = URI.create(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); verifyCorrectResponseCode(url, HttpURLConnection.HTTP_BAD_REQUEST); assertThrows(IOException.class, () -> OAuthUtils.getWithHeader(url), "Responses may be parsed, which will likely fail."); @@ -269,7 +268,7 @@ void testBadRequest() throws IOException { @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.FORBIDDEN) void testForbiddenRequest() throws IOException { - final URL url = new URL(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); + final URI url = URI.create(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); verifyCorrectResponseCode(url, HttpURLConnection.HTTP_FORBIDDEN); assertThrows(IOException.class, () -> OAuthUtils.getWithHeader(url), "Responses may be parsed, which will likely fail."); @@ -279,7 +278,7 @@ void testForbiddenRequest() throws IOException { @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.NOT_FOUND) void testNotFoundResponse() throws IOException { - final URL url = new URL(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); + final URI url = URI.create(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); verifyCorrectResponseCode(url, HttpURLConnection.HTTP_NOT_FOUND); assertThrows(IOException.class, () -> OAuthUtils.getWithHeader(url), "Responses may be parsed, which will likely fail."); @@ -289,7 +288,7 @@ void testNotFoundResponse() throws IOException { @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.NO_CONTENT) void testNoContentResponse() throws IOException { - final URL url = new URL(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); + final URI url = URI.create(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); verifyCorrectResponseCode(url, HttpURLConnection.HTTP_NO_CONTENT); assertThrows(IOException.class, () -> OAuthUtils.getWithHeader(url), "Responses may be parsed, which will likely fail."); @@ -299,7 +298,7 @@ void testNoContentResponse() throws IOException { @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.SERVER_ERROR) void testServerErrorResponse() throws IOException { - final URL url = new URL(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); + final URI url = URI.create(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); verifyCorrectResponseCode(url, HttpURLConnection.HTTP_INTERNAL_ERROR); assertDoesNotThrow(() -> OAuthUtils.getWithHeader(url), "Responses may be parsed, which may fail."); assertAll("Server errors should not log out the user", LOGGED_IN_CHECKS); @@ -309,7 +308,7 @@ void testServerErrorResponse() throws IOException { @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.UNAUTHORIZED) void testUnauthorizedResponse() throws IOException { - final URL url = new URL(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); + final URI url = URI.create(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); verifyCorrectResponseCode(url, HttpURLConnection.HTTP_UNAUTHORIZED); assertThrows(IOException.class, () -> OAuthUtils.getWithHeader(url), "Responses may be parsed, which will likely fail."); @@ -319,27 +318,25 @@ void testUnauthorizedResponse() throws IOException { @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.UNAUTHORIZED_APPLICATION) void testUnauthorizedApplicationResponse() throws IOException { - final URL url = new URL(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); + final URI url = URI.create(MapillaryConfig.getUrls().getImageInformation(IMAGE_ID)); verifyCorrectResponseCode(url, HttpURLConnection.HTTP_UNAUTHORIZED); assertDoesNotThrow(() -> OAuthUtils.getWithHeader(url), "Responses may be parsed, which may fail."); assertAll("An unauthorized application response should log out the user", NOT_LOGGED_IN_CHECKS); this.testAuthenticationRefresh(url); } - void testAuthenticationRefresh(final URL url) { + void testAuthenticationRefresh(final URI url) { OAuthUtils.updateAuthorization( getUpdateAuthorizationJsonObjectBuilder(Duration.ofSeconds(10), "test", "bearer").build()); assertDoesNotThrow(() -> OAuthUtils.getWithHeader(url)); } - private static void verifyCorrectResponseCode(final URL url, final int responseCode) { - final HttpClient client = HttpClient.create(url); + private static void verifyCorrectResponseCode(final URI url, final int responseCode) throws IOException { + final HttpClient client = HttpClient.create(url.toURL()); OAuthUtils.addAuthenticationHeader(client); try { final HttpClient.Response response = client.connect(); assertEquals(responseCode, response.getResponseCode(), response.fetchContent()); - } catch (IOException ioException) { - fail(ioException); } finally { client.disconnect(); } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/testutils/annotations/MapillaryURLWireMock.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/testutils/annotations/MapillaryURLWireMock.java index 9f748c365..4d43c6362 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/testutils/annotations/MapillaryURLWireMock.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/testutils/annotations/MapillaryURLWireMock.java @@ -9,6 +9,8 @@ import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.UncheckedIOException; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -27,14 +29,6 @@ import java.util.stream.Stream; import javax.imageio.ImageIO; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonReader; -import javax.json.JsonString; -import javax.json.JsonValue; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.client.WireMock; @@ -50,6 +44,14 @@ import com.github.tomakehurst.wiremock.matching.StringValuePattern; import com.github.tomakehurst.wiremock.stubbing.StubMapping; import com.github.tomakehurst.wiremock.verification.LoggedRequest; +import jakarta.json.Json; +import jakarta.json.JsonArray; +import jakarta.json.JsonArrayBuilder; +import jakarta.json.JsonObject; +import jakarta.json.JsonObjectBuilder; +import jakarta.json.JsonReader; +import jakarta.json.JsonString; +import jakarta.json.JsonValue; import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeAllCallback; @@ -71,7 +73,7 @@ @Target(ElementType.TYPE) @ExtendWith(MapillaryURLWireMock.MapillaryURLMockExtension.class) public @interface MapillaryURLWireMock { - /** Use to indicate whether or not the API calls should be mocked */ + /** Use to indicate whether the API calls should be mocked */ enum Type { /** Mock the API calls */ STANDARD, @@ -174,7 +176,7 @@ public void beforeAll(final ExtensionContext context) throws Exception { final Map imageIdsParameters = new HashMap<>(potentialParameters); imageIdsParameters.put("image_ids", new AnythingPattern()); - // This stub *MUST* be accounted for in the an extension (for example, the CollectionEndpoint extension) + // This stub *MUST* be accounted for in the extension (for example, the CollectionEndpoint extension) server.stubFor(WireMock.get(WireMock.urlPathMatching("/api/v4/graph/images.*")) .withQueryParams(imageIdsParameters).willReturn(WireMock.aResponse()).atPriority(0)); // This stub is needed, since the creation of new layers often makes a call to the "stub" URL @@ -192,8 +194,8 @@ public void beforeAll(final ExtensionContext context) throws Exception { ImageIO.write(bufferedImage, "png", imageOut); server.stubFor(WireMock.get(WireMock.urlPathMatching("/thumb_([0-9]+)_([0-9]+)")) .willReturn(WireMock.aResponse().withBody(imageOut.toByteArray())).atPriority(100)); - } catch (Exception exception) { - fail(exception); + } catch (IOException exception) { + throw new UncheckedIOException(exception); } // Store the stub mappings for future use. @@ -269,7 +271,7 @@ public Response transform(Request request, Response response, FileSource files, if (Utils.isBlank(origBody)) { return response; } - String newBody = origBody.replaceAll("https?:\\/\\/.*?\\/", server.baseUrl() + "/"); + String newBody = origBody.replaceAll("https?://.*?/", server.baseUrl() + "/"); // Replace with ids try (JsonReader reader = Json .createReader(new ByteArrayInputStream(newBody.getBytes(StandardCharsets.UTF_8)))) { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/JsonUtil.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/JsonUtil.java index e66e819c0..5ed981cc0 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/JsonUtil.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/JsonUtil.java @@ -2,23 +2,23 @@ package org.openstreetmap.josm.plugins.mapillary.utils; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonValue; -import javax.json.JsonWriter; -import javax.json.JsonWriterFactory; -import javax.json.stream.JsonGenerator; +import jakarta.json.Json; +import jakarta.json.JsonArray; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; +import jakarta.json.JsonValue; +import jakarta.json.JsonWriter; +import jakarta.json.JsonWriterFactory; +import jakarta.json.stream.JsonGenerator; public final class JsonUtil { @@ -87,8 +87,7 @@ public static JsonObject string2jsonObject(String s) { JsonReader reader = Json.createReader(stream)) { return reader.readObject(); } catch (IOException e) { - fail(e); + throw new UncheckedIOException(e); } - return null; } } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonDecoderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonDecoderTest.java index 6d90f6eb5..c9768cd08 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonDecoderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonDecoderTest.java @@ -2,17 +2,16 @@ package org.openstreetmap.josm.plugins.mapillary.utils.api; import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.util.function.Function; -import javax.json.Json; -import javax.json.JsonReader; -import javax.json.JsonValue; - +import jakarta.json.Json; +import jakarta.json.JsonReader; +import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; import org.openstreetmap.josm.plugins.mapillary.utils.TestUtil; @@ -53,8 +52,7 @@ static T stringToJsonValue(final Function f JsonReader reader = Json.createReader(stream)) { return function.apply(reader); } catch (IOException e) { - fail(e); - return null; + throw new UncheckedIOException(e); } } diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetailsDecoderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetailsDecoderTest.java index 56c1c8f53..3d7a0d39b 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetailsDecoderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetailsDecoderTest.java @@ -10,7 +10,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; @@ -19,10 +19,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.LongStream; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; - +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; import org.awaitility.Awaitility; import org.awaitility.Durations; import org.junit.jupiter.api.RepeatedTest; @@ -64,7 +63,7 @@ void testDecodeImageInfos(boolean computedLocations) throws IOException { List downloadedImages = new ArrayList<>(); for (long image : images) { - final URL url = new URL( + final URI url = URI.create( MapillaryConfig.getUrls().getImageInformation(image, MapillaryImageUtils.ImageProperties.values())); downloadedImages.addAll( JsonDecoder.decodeData(OAuthUtils.getWithHeader(url), JsonImageDetailsDecoder::decodeImageInfos)); @@ -122,7 +121,7 @@ void testComputedGeometryPreferenceNoComputedGeometry() { @Test @MapillaryURLWireMockErrors(MapillaryURLWireMockErrors.Type.APPLICATION_REQUEST_LIMIT_REACHED) - void testDecodeImageInfosWithFetchErrorsApplicationRequestLimitReached() throws IOException { + void testDecodeImageInfosWithFetchErrorsApplicationRequestLimitReached() { final long[] images = new long[] { 148137757289079L, 311799370533334L, 4235112816526838L, 464249047982277L, 308609047601518L, 135511895288847L, 311681117131457L, }; @@ -131,7 +130,7 @@ void testDecodeImageInfosWithFetchErrorsApplicationRequestLimitReached() throws .forEach(data::addPrimitive); for (long image : images) { - final URL url = new URL( + final URI url = URI.create( MapillaryConfig.getUrls().getImageInformation(image, MapillaryImageUtils.ImageProperties.values())); assertDoesNotThrow( () -> JsonDecoder.decodeData(OAuthUtils.getWithHeader(url), JsonImageDetailsDecoder::decodeImageInfos)); diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoderTest.java index e2c32e9d2..09ed0c25c 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonImageDetectionDecoderTest.java @@ -6,9 +6,8 @@ import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; -import javax.json.Json; -import javax.json.JsonReader; - +import jakarta.json.Json; +import jakarta.json.JsonReader; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.openstreetmap.josm.plugins.mapillary.testutils.annotations.MapillaryCaches; @@ -25,7 +24,7 @@ class JsonImageDetectionDecoderTest { */ @ParameterizedTest @ValueSource(strings = { "GiB4AgoGbXB5LW9yKIAgEhEYAwgBIgsJxheqLxIEFQAeDw==" }) - void decodeImageDetectionGeometryNonRegression21254(final String geometry) { + void testDecodeImageDetectionGeometryNonRegression21254(final String geometry) { final String jsonString = "{\"value\":\"construction--barrier--concrete-block\",\"id\":\"1\",\"geometry\":\"" + geometry + "\",\"image\":{\"id\":\"1\"}}"; try (JsonReader jsonReader = Json diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonMapObjectDecoderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonMapObjectDecoderTest.java index 054730905..a03bdb8dd 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonMapObjectDecoderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonMapObjectDecoderTest.java @@ -11,17 +11,16 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.stream.LongStream; import java.util.stream.Stream; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonValue; - +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; +import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -50,7 +49,7 @@ class JsonMapObjectDecoderTest { @Test void testDecodeMapObject() throws IOException { - final JsonObject jsonObject = OAuthUtils.getWithHeader(new URL(MapillaryConfig.getUrls() + final JsonObject jsonObject = OAuthUtils.getWithHeader(URI.create(MapillaryConfig.getUrls() .getMapFeatureInformation(496980935069177L, MapillaryMapFeatureUtils.MapFeatureProperties.values()))); final VectorNode node1 = new VectorNode("test"); Collection exampleMapObjects = JsonDecoder.decodeData(jsonObject, @@ -77,7 +76,7 @@ void testDecodeMapObject() throws IOException { @Test void testNoOverwriteFromInitialVector() throws IOException { - final JsonObject jsonObject = OAuthUtils.getWithHeader(new URL(MapillaryConfig.getUrls() + final JsonObject jsonObject = OAuthUtils.getWithHeader(URI.create(MapillaryConfig.getUrls() .getMapFeatureInformation(496980935069177L, MapillaryMapFeatureUtils.MapFeatureProperties.values()))); final VectorNode node1 = new VectorNode("test"); node1.setCoor(new LatLon(12, 2)); diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonSequencesDecoderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonSequencesDecoderTest.java index 7d18e9125..5ef070292 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonSequencesDecoderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonSequencesDecoderTest.java @@ -5,22 +5,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import static org.openstreetmap.josm.plugins.mapillary.utils.api.JsonDecoderTest.stringToJsonValue; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.stream.Collectors; -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonValue; - +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonReader; +import jakarta.json.JsonValue; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; @@ -41,7 +39,7 @@ class JsonSequencesDecoderTest { static JOSMTestRules rules = new JOSMTestRules().main(); @Test - void testDecodeSequencesInvalid() { + void testDecodeSequencesInvalid() throws IOException { // null input assertThrows(NullPointerException.class, () -> JsonDecoder.decodeData(null, JsonSequencesDecoder::decodeSequence)); @@ -58,24 +56,23 @@ void testDecodeSequencesInvalid() { } @Test - void testDecodeSequencesWithArbitraryObjectAsFeature() { + void testDecodeSequencesWithArbitraryObjectAsFeature() throws IOException { assertNumberOfDecodedSequences(0, "{\"type\": \"FeatureCollection\", \"features\": [{}]}"); } - private static void assertNumberOfDecodedSequences(int expectedNumberOfSequences, String jsonString) { + private static void assertNumberOfDecodedSequences(int expectedNumberOfSequences, String jsonString) + throws IOException { try (InputStream stream = new ByteArrayInputStream(jsonString.getBytes(StandardCharsets.UTF_8)); JsonReader reader = Json.createReader(stream)) { assertEquals(expectedNumberOfSequences, JsonDecoder.decodeData(reader.readObject(), JsonSequencesDecoder::decodeSequence).size()); - } catch (IOException e) { - fail(jsonString, e); } } @Test void testDecodeSequence() throws IOException { final JsonObject json = OAuthUtils - .getWithHeader(new URL(MapillaryConfig.getUrls().getImagesBySequences("7nfcwfvjdtphz7yj6zat6a"))); + .getWithHeader(URI.create(MapillaryConfig.getUrls().getImagesBySequences("7nfcwfvjdtphz7yj6zat6a"))); final Collection exampleSequences = JsonDecoder.decodeData(json, JsonSequencesDecoder::decodeSequence); // Since the sequence key isn't returned in the API response, we have to rely upon the sequence key // being present in the vector tiles. Therefore, we cannot test that the expected sequence id is in the diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonUserProfileDecoderTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonUserProfileDecoderTest.java index 78bdf691f..3c8b33ed8 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonUserProfileDecoderTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/api/JsonUserProfileDecoderTest.java @@ -15,9 +15,8 @@ import java.nio.file.Files; import java.nio.file.Paths; -import javax.json.Json; -import javax.json.JsonReader; - +import jakarta.json.Json; +import jakarta.json.JsonReader; import org.junit.jupiter.api.Test; import org.openstreetmap.josm.plugins.mapillary.model.UserProfile; import org.openstreetmap.josm.plugins.mapillary.utils.JsonUtil;