Skip to content

Commit

Permalink
Use jakarta.json instead of javax.json
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Aug 22, 2023
1 parent 708c5c2 commit 3d113ab
Show file tree
Hide file tree
Showing 34 changed files with 219 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ant-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ jobs:
call-workflow:
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
with:
josm-revision: "r18613"
josm-revision: "r18723"


2 changes: 1 addition & 1 deletion .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,7 +54,7 @@ public final class Caches {

/** The cache for metadata objects */
public static final MapillaryCacheAccess<String> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -333,7 +333,7 @@ private static List<ImageDetection<?>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,7 +64,7 @@ public static synchronized Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 3d113ab

Please sign in to comment.