Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #23699: Don't throw an exception when selected MR task in mapview isn't in list #7

Merged
merged 6 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ant-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: workflow_dispatch

jobs:
call-workflow:
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v2
with:
java-version: 17

4 changes: 2 additions & 2 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
release_needed: ${{ steps.create_release_needed.outputs.release_needed }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: ${{ (github.repository == 'JOSM/MapRoulette' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request') && '0' || '1' }}

Expand All @@ -44,7 +44,7 @@ jobs:
strategy:
matrix:
josm-revision: ["", "r18877"]
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v2
with:
josm-revision: ${{ matrix.josm-revision }}
java-version: 17
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ permissions:

jobs:
call-workflow:
uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v1
uses: JOSM/JOSMPluginAction/.github/workflows/reports.yaml@v2
30 changes: 28 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="MapRoulette" default="dist" basedir=".">
<project name="MapRoulette" default="dist" basedir="." xmlns:mvn="antlib:org.apache.maven.resolver.ant">
<property name="plugin.src.dir" value="src/main/java"/>
<property name="plugin.test.dir" location="src/test"/>
<property name="plugin.resources.dir" value="src/main/resources"/>
Expand All @@ -20,7 +20,33 @@
<!-- ** include targets that all plugins have in common ** -->
<import file="../build-common.xml"/>

<target name="pre-compile" depends="fetch_dependencies">
<target name="download-maven-artifact-resolver">
<mkdir dir="${ivy.jar.dir}"/>
<get src="https://repo1.maven.org/maven2/org/apache/maven/resolver/maven-resolver-ant-tasks/1.5.1/maven-resolver-ant-tasks-1.5.1-uber.jar"
dest="${ivy.jar.dir}/maven-resolver-ant-tasks-uber.jar"
usetimestamp="true"/>
</target>
<target name="init-maven" depends="download-maven-artifact-resolver">
<path id="maven.lib.path">
<fileset dir="${ivy.jar.dir}" includes="maven-resolver-ant-tasks-uber.jar"/>
</path>
<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml" classpathref="maven.lib.path"/>
</target>
<target name="fetch-maven-dependencies" depends="init-maven">
<mvn:pom file="pom.xml"/>
<mvn:resolve>
<!-- I wish this stanza wasn't necessary, but the repos aren't read from pom.xml -->
<mvn:remoterepos>
<mvn:remoterepo id="JOSM-central" url="https://josm.openstreetmap.de/nexus/content/repositories/central/" />
<mvn:remoterepo id="JOSM-releases" url="https://josm.openstreetmap.de/nexus/content/repositories/releases/" />
<mvn:remoterepo id="JOSM-snapshots" url="https://josm.openstreetmap.de/nexus/content/repositories/snapshots/" />
<mvn:remoterepo id="JOSM-osgeo" url="https://josm.openstreetmap.de/nexus/content/repositories/osgeo/" />
</mvn:remoterepos>
<mvn:files refid="lib.files" dir="lib" layout="{artifactId}-{version}-{classifier}.{extension}" scopes="compile"/>
</mvn:resolve>
</target>

<target name="pre-compile" depends="fetch-maven-dependencies">
<!-- include fetch_dependencies task -->
</target>
</project>
12 changes: 0 additions & 12 deletions ivy.xml

This file was deleted.

57 changes: 37 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>org.openstreetmap.josm</groupId>
<artifactId>josm</artifactId>
<version>18511</version>
<version>18905</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -27,21 +27,21 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>2.35.0</version>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<version>3.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.2</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -50,28 +50,22 @@
<version>1.49.a</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-jcs3-core</artifactId>
<version>3.1</version>
<version>3.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.4</version>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark</artifactId>
<version>0.21.0</version>
<version>0.22.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand All @@ -80,19 +74,19 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.13.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.30.0</version>
<version>2.43.0</version>
<configuration>
<java>
<eclipse>
<version>4.21.0</version>
<version>4.21</version>
<file>${project.basedir}/../00_core_tools/eclipse/formatter.xml</file>
</eclipse>
<removeUnusedImports/>
Expand All @@ -109,6 +103,29 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.6.3</version>
</requireMavenVersion>
<requireJavaVersion>
<version>17</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.openstreetmap.josm.gui.progress.ProgressMonitor;
import org.openstreetmap.josm.gui.progress.ProgressTaskId;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.io.OsmApiException;
import org.openstreetmap.josm.io.OsmTransferException;
import org.openstreetmap.josm.plugins.maproulette.api.TaskAPI;
import org.openstreetmap.josm.plugins.maproulette.api.UnauthorizedException;
Expand Down Expand Up @@ -108,7 +109,7 @@ protected void realRun() throws IOException, OsmTransferException {
}
});
// This is specifically so that user's don't get a bug report message
final var transferException = new OsmTransferException(unauthorizedException);
final var transferException = new OsmApiException(unauthorizedException);
transferException.setUrl(MapRouletteConfig.getBaseUrl());
throw transferException;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public static TaskBundle parseBundle(InputStream bundle) {
*
* @param id The id of the bundle to get
* @return The specified bundle
* @throws UnauthorizedException if the user hasn't logged in to MapRoulette
*/
@Nonnull
public static TaskBundle getBundle(long id) {
public static TaskBundle getBundle(long id) throws UnauthorizedException {
final var client = get(getBaseUrl() + PATH + "/" + id);
try {
try (var inputStream = client.connect().getContent()) {
Expand All @@ -104,8 +105,9 @@ public static TaskBundle getBundle(long id) {
*
* @param id The bundle to delete
* @return {@code true} if the deletion was successful
* @throws UnauthorizedException if the user hasn't logged in to MapRoulette
*/
public static boolean deleteBundle(long id) {
public static boolean deleteBundle(long id) throws UnauthorizedException {
final var client = delete(getBaseUrl() + PATH + "/" + id);
try {
int responseCode = client.connect().getResponseCode();
Expand All @@ -126,9 +128,10 @@ public static boolean deleteBundle(long id) {
* @param original The original bundle
* @param taskIds The tasks to remove
* @return The new bundle
* @throws UnauthorizedException if the user hasn't logged in to MapRoulette
*/
@Nonnull
public static TaskBundle unbundle(TaskBundle original, long... taskIds) {
public static TaskBundle unbundle(TaskBundle original, long... taskIds) throws UnauthorizedException {
final var client = get(getBaseUrl() + PATH + "/" + original.id() + "/unbundle",
Map.of("taskIds", LongStream.of(taskIds).mapToObj(Long::toString).collect(Collectors.joining(","))));
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.maproulette.api;

import java.io.IOException;
import java.io.Serial;

/**
* Thrown if the user is not authorized for the specified operation
*/
public class UnauthorizedException extends RuntimeException {
public class UnauthorizedException extends IOException {
/**
* The serial UID for this exception
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
Expand All @@ -20,6 +21,7 @@
import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
import org.openstreetmap.josm.io.IllegalDataException;
import org.openstreetmap.josm.io.OsmChangeReader;
import org.openstreetmap.josm.plugins.maproulette.api.UnauthorizedException;
import org.openstreetmap.josm.plugins.maproulette.api.enums.TaskStatus;
import org.openstreetmap.josm.plugins.maproulette.api.model.ElementCreate;
import org.openstreetmap.josm.plugins.maproulette.api.model.ElementTagChange;
Expand Down Expand Up @@ -61,21 +63,33 @@ private TaskParser() {
*
* @param inputStream the stream to get the task from
* @return The new task. May be a singular task or an array of tasks.
* @throws UnauthorizedException if the user hasn't logged in to MapRoulette
*/
@Nonnull
public static Object parseTask(InputStream inputStream) {
public static Object parseTask(InputStream inputStream) throws UnauthorizedException {
try (var reader = Json.createParser(inputStream)) {
while (reader.hasNext()) {
var value = switch (reader.next()) {
case START_OBJECT -> parseTask(reader.getObject());
case START_ARRAY -> reader.getArrayStream().filter(JsonObject.class::isInstance)
.map(JsonObject.class::cast).map(TaskParser::parseTask).toArray(Task[]::new);
.map(JsonObject.class::cast).map(obj -> {
try {
return parseTask(obj);
} catch (UnauthorizedException e) {
throw new UncheckedIOException(e);
}
}).toArray(Task[]::new);
default -> null;
};
if (value != null) {
return value;
}
}
} catch (UncheckedIOException e) {
if (e.getCause()instanceof UnauthorizedException unauthorizedException) {
throw unauthorizedException;
}
throw e;
}
throw new IllegalArgumentException("InputStream did not contain expected JSON data");
}
Expand All @@ -85,9 +99,10 @@ public static Object parseTask(InputStream inputStream) {
*
* @param obj the JsonObject to get the task from
* @return The new task
* @throws UnauthorizedException if the user hasn't logged in to MapRoulette
*/
@Nonnull
private static Task parseTask(JsonObject obj) {
private static Task parseTask(JsonObject obj) throws UnauthorizedException {
MessageParser.parse(obj);
try {
return new Task(obj.getJsonNumber("id").longValue(), obj.getString("name"),
Expand Down
Loading
Loading