See #23220: Use jakarta.annotation instead of javax.annotation (JSR305)

Some lint issues were also fixed.

Signed-off-by: Taylor Smock <tsmock@meta.com>
pull/43/head
Taylor Smock 2023-10-24 13:24:07 -06:00
rodzic 4af7ac225f
commit e796f49d8e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 233BB2E466604E27
16 zmienionych plików z 145 dodań i 175 usunięć

Wyświetl plik

@ -18,12 +18,12 @@ jobs:
call-workflow: call-workflow:
strategy: strategy:
matrix: matrix:
josm-revision: ["", "r18723"] josm-revision: ["", "r18877"]
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1 uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
with: with:
java-version: 17 java-version: 17
josm-revision: ${{ matrix.josm-revision }} josm-revision: ${{ matrix.josm-revision }}
plugin-jar-name: 'mapwithai' plugin-jar-name: 'mapwithai'
perform-revision-tagging: ${{ github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' && matrix.josm-revision == 'r18723' }} perform-revision-tagging: ${{ matrix.josm-revision == 'r18877' && github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }}
secrets: inherit secrets: inherit

Wyświetl plik

@ -1,9 +1,9 @@
# The minimum JOSM version this plugin is compatible with (can be any numeric version # The minimum JOSM version this plugin is compatible with (can be any numeric version
plugin.main.version = 18723 plugin.main.version = 18877
# The JOSM version this plugin is currently compiled against # The JOSM version this plugin is currently compiled against
# Please make sure this version is available at https://josm.openstreetmap.de/download # Please make sure this version is available at https://josm.openstreetmap.de/download
# The special values "latest" and "tested" are also possible here, but not recommended. # The special values "latest" and "tested" are also possible here, but not recommended.
plugin.compile.version = 18724 plugin.compile.version = 18877
plugin.canloadatruntime = true plugin.canloadatruntime = true
plugin.author = Taylor Smock plugin.author = Taylor Smock
plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin

Wyświetl plik

@ -36,7 +36,6 @@ public class DataAvailability {
static final Map<String, String> POSSIBLE_DATA_POINTS = new TreeMap<>(); static final Map<String, String> POSSIBLE_DATA_POINTS = new TreeMap<>();
private static final String PROVIDES = "provides"; private static final String PROVIDES = "provides";
private static final String EMPTY_STRING = "";
private static final int SEVEN_DAYS_IN_SECONDS = 604_800; private static final int SEVEN_DAYS_IN_SECONDS = 604_800;
/** /**
@ -150,7 +149,7 @@ public class DataAvailability {
* @return A string that doesn't have quotes at the beginning or end * @return A string that doesn't have quotes at the beginning or end
*/ */
public static String stripQuotes(String string) { public static String stripQuotes(String string) {
return string.replaceAll("((^\")|(\"$))", EMPTY_STRING); return string.replaceAll("((^\")|(\"$))", "");
} }
/** /**
@ -224,7 +223,7 @@ public class DataAvailability {
* @return The url or "" * @return The url or ""
*/ */
public String getTermsOfUseUrl() { public String getTermsOfUseUrl() {
return EMPTY_STRING; return "";
} }
/** /**
@ -247,11 +246,10 @@ public class DataAvailability {
DATA_SOURCES.stream().map(clazz -> { DATA_SOURCES.stream().map(clazz -> {
try { try {
return clazz.getConstructor().newInstance().getTermsOfUseUrl(); return clazz.getConstructor().newInstance().getTermsOfUseUrl();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException } catch (ReflectiveOperationException e) {
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
Logging.debug(e); Logging.debug(e);
} }
return EMPTY_STRING; return "";
})).filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty()) })).filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -267,11 +265,10 @@ public class DataAvailability {
DATA_SOURCES.stream().map(clazz -> { DATA_SOURCES.stream().map(clazz -> {
try { try {
return clazz.getConstructor().newInstance().getPrivacyPolicyUrl(); return clazz.getConstructor().newInstance().getPrivacyPolicyUrl();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException } catch (ReflectiveOperationException e) {
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
Logging.debug(e); Logging.debug(e);
} }
return EMPTY_STRING; return "";
})) }))
.filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty()).distinct() .filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty()).distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());

Wyświetl plik

@ -3,12 +3,9 @@ package org.openstreetmap.josm.plugins.mapwithai.commands;
import static org.openstreetmap.josm.tools.I18n.tr; import static org.openstreetmap.josm.tools.I18n.tr;
import javax.annotation.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.openstreetmap.josm.command.Command; import org.openstreetmap.josm.command.Command;
@ -17,6 +14,8 @@ import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.data.osm.Relation; import org.openstreetmap.josm.data.osm.Relation;
import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.data.osm.Way;
import jakarta.annotation.Nullable;
/** /**
* This is similar to the ReplaceGeometryUtils.buildUpgradeNodeCommand method * This is similar to the ReplaceGeometryUtils.buildUpgradeNodeCommand method
* *
@ -46,19 +45,19 @@ public final class MergeBuildingNodeCommand {
private static Node getNewOrNoTagNode(OsmPrimitive referenceObject) { private static Node getNewOrNoTagNode(OsmPrimitive referenceObject) {
List<Node> nodes; List<Node> nodes;
if (referenceObject instanceof Way) { if (referenceObject instanceof Way way) {
nodes = ((Way) referenceObject).getNodes(); nodes = way.getNodes();
} else if (referenceObject instanceof Relation) { } else if (referenceObject instanceof Relation relation) {
nodes = ((Relation) referenceObject).getMemberPrimitives().stream().flatMap(o -> { nodes = relation.getMemberPrimitives().stream().flatMap(o -> {
if (o instanceof Way) { if (o instanceof Way way) {
return ((Way) o).getNodes().stream(); return way.getNodes().stream();
} else if (o instanceof Node) { } else if (o instanceof Node node) {
return Stream.of((Node) o); return Stream.of(node);
} }
return null; return null;
}).filter(Objects::nonNull).collect(Collectors.toList()); }).filter(Objects::nonNull).toList();
} else if (referenceObject instanceof Node) { } else if (referenceObject instanceof Node node) {
nodes = Collections.singletonList((Node) referenceObject); nodes = Collections.singletonList(node);
} else { } else {
throw new IllegalArgumentException(tr("Unknown OsmPrimitive type")); throw new IllegalArgumentException(tr("Unknown OsmPrimitive type"));
} }

Wyświetl plik

@ -3,15 +3,11 @@ package org.openstreetmap.josm.plugins.mapwithai.commands;
import static org.openstreetmap.josm.tools.I18n.tr; import static org.openstreetmap.josm.tools.I18n.tr;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -34,6 +30,9 @@ import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIPreferenceHelpe
import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Pair; import org.openstreetmap.josm.tools.Pair;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
/** /**
* Merge duplicate ways * Merge duplicate ways
*/ */
@ -83,7 +82,7 @@ public class MergeDuplicateWays extends Command {
* @param way2 The second way * @param way2 The second way
*/ */
public MergeDuplicateWays(DataSet data, Way way1, Way way2) { public MergeDuplicateWays(DataSet data, Way way1, Way way2) {
this(data, Stream.of(way1, way2).filter(Objects::nonNull).collect(Collectors.toList())); this(data, Stream.of(way1, way2).filter(Objects::nonNull).toList());
} }
/** /**
@ -94,7 +93,7 @@ public class MergeDuplicateWays extends Command {
*/ */
public MergeDuplicateWays(DataSet data, List<Way> ways) { public MergeDuplicateWays(DataSet data, List<Way> ways) {
super(data); super(data);
this.ways = ways.stream().filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList()); this.ways = ways.stream().filter(MergeDuplicateWays::nonDeletedWay).toList();
this.commands = new ArrayList<>(); this.commands = new ArrayList<>();
} }
@ -110,11 +109,11 @@ public class MergeDuplicateWays extends Command {
} else if (ways.size() == 1) { } else if (ways.size() == 1) {
checkForDuplicateWays(ways.get(0), commands); checkForDuplicateWays(ways.get(0), commands);
} else { } else {
Iterator<Way> it = ways.iterator(); final var it = ways.iterator();
Way way1 = it.next(); var way1 = it.next();
while (it.hasNext()) { while (it.hasNext()) {
Way way2 = it.next(); final var way2 = it.next();
final Command tCommand = checkForDuplicateWays(way1, way2); final var tCommand = checkForDuplicateWays(way1, way2);
if (tCommand != null) { if (tCommand != null) {
commands.add(tCommand); commands.add(tCommand);
tCommand.executeCommand(); tCommand.executeCommand();
@ -122,8 +121,7 @@ public class MergeDuplicateWays extends Command {
way1 = way2; way1 = way2;
} }
} }
final List<Command> realCommands = commands.stream().filter(Objects::nonNull).distinct() final List<Command> realCommands = commands.stream().filter(Objects::nonNull).distinct().toList();
.collect(Collectors.toList());
commands.clear(); commands.clear();
commands.addAll(realCommands); commands.addAll(realCommands);
if (!commands.isEmpty() && (commands.size() != 1)) { if (!commands.isEmpty() && (commands.size() != 1)) {
@ -165,14 +163,13 @@ public class MergeDuplicateWays extends Command {
final List<Way> ways = (bound == null ? dataSet.getWays() : dataSet.searchWays(bound.toBBox())).stream() final List<Way> ways = (bound == null ? dataSet.getWays() : dataSet.searchWays(bound.toBBox())).stream()
.filter(prim -> !prim.isIncomplete() && !prim.isDeleted()) .filter(prim -> !prim.isIncomplete() && !prim.isDeleted())
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
for (int i = 0; i < ways.size(); i++) { for (var i = 0; i < ways.size(); i++) {
final Way way1 = ways.get(i); final var way1 = ways.get(i);
final Collection<Way> nearbyWays = dataSet.searchWays(way1.getBBox()).stream() final var nearbyWays = dataSet.searchWays(way1.getBBox()).stream()
.filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList()); .filter(MergeDuplicateWays::nonDeletedWay).filter(w -> !Objects.equals(w, way1)).toList();
nearbyWays.remove(way1);
for (final Way way2 : nearbyWays) { for (final Way way2 : nearbyWays) {
final Command command = checkForDuplicateWays(way1, way2); final var command = checkForDuplicateWays(way1, way2);
final Collection<OsmPrimitive> deletedWays = new ArrayList<>(); final var deletedWays = new ArrayList<OsmPrimitive>();
if (command != null) { if (command != null) {
commands.add(command); commands.add(command);
command.executeCommand(); command.executeCommand();
@ -194,11 +191,10 @@ public class MergeDuplicateWays extends Command {
*/ */
public static void checkForDuplicateWays(Way way, List<Command> commands) { public static void checkForDuplicateWays(Way way, List<Command> commands) {
final Collection<Way> nearbyWays = way.getDataSet().searchWays(way.getBBox()).stream() final Collection<Way> nearbyWays = way.getDataSet().searchWays(way.getBBox()).stream()
.filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList()); .filter(MergeDuplicateWays::nonDeletedWay).filter(w -> !Objects.equals(w, way)).toList();
nearbyWays.remove(way);
for (final Way way2 : nearbyWays) { for (final Way way2 : nearbyWays) {
if (!way2.isDeleted()) { if (!way2.isDeleted()) {
final Command tCommand = checkForDuplicateWays(way, way2); final var tCommand = checkForDuplicateWays(way, way2);
if (tCommand != null) { if (tCommand != null) {
commands.add(tCommand); commands.add(tCommand);
tCommand.executeCommand(); tCommand.executeCommand();
@ -230,10 +226,8 @@ public class MergeDuplicateWays extends Command {
Logging.error("{0}", way2); Logging.error("{0}", way2);
} }
if ((compressed.size() > 1) && duplicateEntrySet.stream().noneMatch(entry -> entry.getValue().size() > 1)) { if ((compressed.size() > 1) && duplicateEntrySet.stream().noneMatch(entry -> entry.getValue().size() > 1)) {
final List<Integer> initial = compressed.stream().map(entry -> entry.a.a).sorted() final var initial = compressed.stream().map(entry -> entry.a.a).sorted().toList();
.collect(Collectors.toList()); final var after = compressed.stream().map(entry -> entry.b.a).sorted().toList();
final List<Integer> after = compressed.stream().map(entry -> entry.b.a).sorted()
.collect(Collectors.toList());
if (sorted(initial) && sorted(after)) { if (sorted(initial) && sorted(after)) {
returnCommand = mergeWays(way1, way2, compressed); returnCommand = mergeWays(way1, way2, compressed);
} }
@ -278,12 +272,12 @@ public class MergeDuplicateWays extends Command {
} }
} }
Collections.reverse(before); Collections.reverse(before);
final Way newWay = new Way(way1); final var newWay = new Way(way1);
List<Command> commands = new ArrayList<>(); List<Command> commands = new ArrayList<>();
before.forEach(node -> newWay.addNode(0, node)); before.forEach(node -> newWay.addNode(0, node));
after.forEach(newWay::addNode); after.forEach(newWay::addNode);
if (newWay.getNodesCount() > 0) { if (newWay.getNodesCount() > 0) {
final ChangeCommand changeCommand = new ChangeCommand(way1, newWay); final var changeCommand = new ChangeCommand(way1, newWay);
commands.add(changeCommand); commands.add(changeCommand);
/* /*
* This must be executed, otherwise the delete command will believe that way2 * This must be executed, otherwise the delete command will believe that way2
@ -315,8 +309,8 @@ public class MergeDuplicateWays extends Command {
* @return The node that the param {@code node} duplicates * @return The node that the param {@code node} duplicates
*/ */
public static Node nodeInCompressed(Node node, Set<Pair<Pair<Integer, Node>, Pair<Integer, Node>>> compressed) { public static Node nodeInCompressed(Node node, Set<Pair<Pair<Integer, Node>, Pair<Integer, Node>>> compressed) {
Node returnNode = node; var returnNode = node;
for (final Pair<Pair<Integer, Node>, Pair<Integer, Node>> pair : compressed) { for (final var pair : compressed) {
if (node.equals(pair.a.b)) { if (node.equals(pair.a.b)) {
returnNode = pair.b.b; returnNode = pair.b.b;
} else if (node.equals(pair.b.b)) { } else if (node.equals(pair.b.b)) {
@ -326,26 +320,26 @@ public class MergeDuplicateWays extends Command {
break; break;
} }
} }
final Node tReturnNode = returnNode; final var tReturnNode = returnNode;
node.getKeys().forEach(tReturnNode::put); node.getKeys().forEach(tReturnNode::put);
return returnNode; return returnNode;
} }
/** /**
* Check if the node pairs increment in the same direction (only checks first * Check if the node pairs increment in the same direction (only checks first
* two pairs), ensure that they are sorted with {@link sorted} * two pairs), ensure that they are sorted with {@link #sorted}
* *
* @param compressed The set of duplicate node/placement pairs * @param compressed The set of duplicate node/placement pairs
* @return true if the node pairs increment in the same direction * @return true if the node pairs increment in the same direction
*/ */
public static boolean checkDirection(Set<Pair<Pair<Integer, Node>, Pair<Integer, Node>>> compressed) { public static boolean checkDirection(Set<Pair<Pair<Integer, Node>, Pair<Integer, Node>>> compressed) {
final Iterator<Pair<Pair<Integer, Node>, Pair<Integer, Node>>> iterator = compressed.iterator(); final var iterator = compressed.iterator();
boolean returnValue = false; var returnValue = false;
if (compressed.size() > 1) { if (compressed.size() > 1) {
final Pair<Pair<Integer, Node>, Pair<Integer, Node>> first = iterator.next(); final var first = iterator.next();
final Pair<Pair<Integer, Node>, Pair<Integer, Node>> second = iterator.next(); final var second = iterator.next();
final boolean way1Forward = first.a.a < second.a.a; final var way1Forward = first.a.a < second.a.a;
final boolean way2Forward = first.b.a < second.b.a; final var way2Forward = first.b.a < second.b.a;
returnValue = way1Forward == way2Forward; returnValue = way1Forward == way2Forward;
} }
return returnValue; return returnValue;
@ -358,10 +352,10 @@ public class MergeDuplicateWays extends Command {
* @return true if there are no gaps and it increases * @return true if there are no gaps and it increases
*/ */
public static boolean sorted(List<Integer> collection) { public static boolean sorted(List<Integer> collection) {
boolean returnValue = true; var returnValue = true;
if (collection.size() > 1) { if (collection.size() > 1) {
Integer last = collection.get(0); Integer last = collection.get(0);
for (int i = 1; i < collection.size(); i++) { for (var i = 1; i < collection.size(); i++) {
final Integer next = collection.get(i); final Integer next = collection.get(i);
if ((next - last) != 1) { if ((next - last) != 1) {
returnValue = false; returnValue = false;
@ -381,17 +375,16 @@ public class MergeDuplicateWays extends Command {
* @return A map of node -&gt; node(s) duplicates * @return A map of node -&gt; node(s) duplicates
*/ */
public static Map<Pair<Integer, Node>, Map<Integer, Node>> getDuplicateNodes(Way way1, Way way2) { public static Map<Pair<Integer, Node>, Map<Integer, Node>> getDuplicateNodes(Way way1, Way way2) {
final Map<Pair<Integer, Node>, Map<Integer, Node>> duplicateNodes = new LinkedHashMap<>(); final var duplicateNodes = new LinkedHashMap<Pair<Integer, Node>, Map<Integer, Node>>();
for (int j = 0; j < way1.getNodesCount(); j++) { for (var j = 0; j < way1.getNodesCount(); j++) {
final Node origNode = way1.getNode(j); final var origNode = way1.getNode(j);
for (int k = 0; k < way2.getNodesCount(); k++) { for (var k = 0; k < way2.getNodesCount(); k++) {
final Node possDupeNode = way2.getNode(k); final var possDupeNode = way2.getNode(k);
if (origNode.equals(possDupeNode) || (origNode if (origNode.equals(possDupeNode) || (origNode
.greatCircleDistance(possDupeNode) < MapWithAIPreferenceHelper.getMaxNodeDistance())) { .greatCircleDistance(possDupeNode) < MapWithAIPreferenceHelper.getMaxNodeDistance())) {
final Pair<Integer, Node> origNodePair = new Pair<>(j, origNode); final var origNodePair = new Pair<>(j, origNode);
final Map<Integer, Node> dupeNodeMap = duplicateNodes.getOrDefault(origNodePair, new HashMap<>()); final var dupeNodeMap = duplicateNodes.computeIfAbsent(origNodePair, ignored -> new HashMap<>());
dupeNodeMap.put(k, possDupeNode); dupeNodeMap.put(k, possDupeNode);
duplicateNodes.put(origNodePair, dupeNodeMap);
} }
} }
} }

Wyświetl plik

@ -3,9 +3,7 @@ package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
import static org.openstreetmap.josm.tools.I18n.marktr; import static org.openstreetmap.josm.tools.I18n.marktr;
import javax.annotation.Nonnull; import java.io.Serial;
import javax.swing.ImageIcon;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -13,11 +11,15 @@ import java.util.EnumMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import javax.swing.ImageIcon;
import org.openstreetmap.josm.data.sources.ISourceCategory; import org.openstreetmap.josm.data.sources.ISourceCategory;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
import org.openstreetmap.josm.tools.ImageProvider; import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
import jakarta.annotation.Nonnull;
/** /**
* The category for a MapWithAI source (i.e., buildings/highways/addresses/etc.) * The category for a MapWithAI source (i.e., buildings/highways/addresses/etc.)
* *
@ -98,6 +100,7 @@ public enum MapWithAICategory implements ISourceCategory<MapWithAICategory> {
*/ */
public static class DescriptionComparator implements Comparator<MapWithAICategory>, Serializable { public static class DescriptionComparator implements Comparator<MapWithAICategory>, Serializable {
@Serial
private static final long serialVersionUID = 9131636715279880580L; private static final long serialVersionUID = 9131636715279880580L;
@Override @Override

Wyświetl plik

@ -3,9 +3,6 @@ package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
import static org.openstreetmap.josm.tools.I18n.tr; import static org.openstreetmap.josm.tools.I18n.tr;
import javax.annotation.Nonnull;
import javax.swing.SwingUtilities;
import java.io.IOException; import java.io.IOException;
import java.io.Serial; import java.io.Serial;
import java.time.Instant; import java.time.Instant;
@ -25,6 +22,8 @@ import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.RecursiveTask; import java.util.concurrent.RecursiveTask;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.SwingUtilities;
import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo; import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
import org.openstreetmap.josm.actions.ExpertToggleAction; import org.openstreetmap.josm.actions.ExpertToggleAction;
import org.openstreetmap.josm.data.Preferences; import org.openstreetmap.josm.data.Preferences;
@ -48,6 +47,8 @@ import org.openstreetmap.josm.tools.ListenerList;
import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Utils; import org.openstreetmap.josm.tools.Utils;
import jakarta.annotation.Nonnull;
/** /**
* Manages the list of imagery entries that are shown in the imagery menu. * Manages the list of imagery entries that are shown in the imagery menu.
*/ */
@ -280,8 +281,8 @@ public class MapWithAILayerInfo {
} }
// This is literally to avoid allocations on startup // This is literally to avoid allocations on startup
final Preferences preferences; final Preferences preferences;
if (Config.getPref() instanceof Preferences) { if (Config.getPref() instanceof Preferences pref) {
preferences = (Preferences) Config.getPref(); preferences = pref;
} else { } else {
preferences = null; preferences = null;
} }

Wyświetl plik

@ -1,10 +1,10 @@
// License: GPL. For details, see LICENSE file. // License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai; package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai;
import javax.annotation.Nonnull;
import org.openstreetmap.josm.data.sources.ISourceType; import org.openstreetmap.josm.data.sources.ISourceType;
import jakarta.annotation.Nonnull;
/** /**
* Type of MapWithAI entry * Type of MapWithAI entry
* *

Wyświetl plik

@ -4,9 +4,6 @@ package org.openstreetmap.josm.plugins.mapwithai.data.validation.tests;
import static org.openstreetmap.josm.tools.I18n.marktr; import static org.openstreetmap.josm.tools.I18n.marktr;
import static org.openstreetmap.josm.tools.I18n.tr; import static org.openstreetmap.josm.tools.I18n.tr;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -33,6 +30,9 @@ import org.openstreetmap.josm.plugins.mapwithai.tools.Access;
import org.openstreetmap.josm.spi.preferences.Config; import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.Pair; import org.openstreetmap.josm.tools.Pair;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
/** /**
* A test for routing islands * A test for routing islands
* *
@ -181,7 +181,7 @@ public class RoutingIslandsTest extends Test {
getDefaultAccessTags(way).getOrDefault(currentTransportMode, Access.AccessTags.NO.getKey()))) getDefaultAccessTags(way).getOrDefault(currentTransportMode, Access.AccessTags.NO.getKey())))
.collect(Collectors.toSet())).stream() .collect(Collectors.toSet())).stream()
.map(way -> new Pair<>((incomingWays.containsAll(way) ? marktr("outgoing") : marktr("incoming")), way)) .map(way -> new Pair<>((incomingWays.containsAll(way) ? marktr("outgoing") : marktr("incoming")), way))
.collect(Collectors.toList()); .toList();
createErrors(problematic, currentTransportMode); createErrors(problematic, currentTransportMode);
} }
@ -198,9 +198,9 @@ public class RoutingIslandsTest extends Test {
private static void findConnectedWays(String currentTransportMode, Collection<Way> potentialWays, private static void findConnectedWays(String currentTransportMode, Collection<Way> potentialWays,
Collection<Way> incomingWays, Collection<Way> outgoingWays) { Collection<Way> incomingWays, Collection<Way> outgoingWays) {
potentialWays.stream().filter(Way::isUsable).filter(Way::isOutsideDownloadArea).forEach(way -> { potentialWays.stream().filter(Way::isUsable).filter(Way::isOutsideDownloadArea).forEach(way -> {
Node firstNode = firstNode(way, currentTransportMode); final var firstNode = firstNode(way, currentTransportMode);
Node lastNode = lastNode(way, currentTransportMode); final var lastNode = lastNode(way, currentTransportMode);
Integer isOneway = isOneway(way, currentTransportMode); final var isOneway = isOneway(way, currentTransportMode);
if (firstNode != null && firstNode.isOutsideDownloadArea()) { if (firstNode != null && firstNode.isOutsideDownloadArea()) {
incomingWays.add(way); incomingWays.add(way);
} }
@ -223,14 +223,14 @@ public class RoutingIslandsTest extends Test {
* @return a list of sets of ways that are connected * @return a list of sets of ways that are connected
*/ */
private static List<Set<Way>> collectConnected(Collection<Way> ways) { private static List<Set<Way>> collectConnected(Collection<Way> ways) {
ArrayList<Set<Way>> collected = new ArrayList<>(); final var collected = new ArrayList<Set<Way>>();
ArrayList<Way> listOfWays = new ArrayList<>(ways); final var listOfWays = new ArrayList<>(ways);
final int maxLoop = Config.getPref().getInt("validator.routingislands.maxrecursion", MAX_LOOPS); final var maxLoop = Config.getPref().getInt("validator.routingislands.maxrecursion", MAX_LOOPS);
for (int i = 0; i < listOfWays.size(); i++) { for (var i = 0; i < listOfWays.size(); i++) {
Way initial = listOfWays.get(i); final var initial = listOfWays.get(i);
Set<Way> connected = new HashSet<>(); Set<Way> connected = new HashSet<>();
connected.add(initial); connected.add(initial);
int loopCounter = 0; var loopCounter = 0;
while (!getConnected(connected) && loopCounter < maxLoop) { while (!getConnected(connected) && loopCounter < maxLoop) {
loopCounter++; loopCounter++;
} }
@ -281,8 +281,8 @@ public class RoutingIslandsTest extends Test {
*/ */
public static void checkForUnconnectedWays(Collection<Way> incoming, Collection<Way> outgoing, public static void checkForUnconnectedWays(Collection<Way> incoming, Collection<Way> outgoing,
String currentTransportMode) { String currentTransportMode) {
int loopCount = 0; var loopCount = 0;
int maxLoops = Config.getPref().getInt("validator.routingislands.maxrecursion", MAX_LOOPS); var maxLoops = Config.getPref().getInt("validator.routingislands.maxrecursion", MAX_LOOPS);
do { do {
loopCount++; loopCount++;
} while (loopCount <= maxLoops && getWaysFor(incoming, currentTransportMode, } while (loopCount <= maxLoops && getWaysFor(incoming, currentTransportMode,
@ -325,11 +325,11 @@ public class RoutingIslandsTest extends Test {
* clean up and work with via ways * clean up and work with via ways
*/ */
public static boolean checkAccessibility(Way from, Way to, String currentTransportMode) { public static boolean checkAccessibility(Way from, Way to, String currentTransportMode) {
boolean isAccessible = true; var isAccessible = true;
List<Relation> relations = from.getReferrers().stream().distinct().filter(Relation.class::isInstance) List<Relation> relations = from.getReferrers().stream().distinct().filter(Relation.class::isInstance)
.map(Relation.class::cast).filter(relation -> "restriction".equals(relation.get("type"))) .map(Relation.class::cast).filter(relation -> "restriction".equals(relation.get("type")))
.collect(Collectors.toList()); .toList();
for (Relation relation : relations) { for (Relation relation : relations) {
if (((relation.hasKey("except") && relation.get("except").contains(currentTransportMode)) if (((relation.hasKey("except") && relation.get("except").contains(currentTransportMode))
|| (currentTransportMode == null || currentTransportMode.trim().isEmpty())) || (currentTransportMode == null || currentTransportMode.trim().isEmpty()))
@ -432,7 +432,7 @@ public class RoutingIslandsTest extends Test {
* @return The map of access tags to access * @return The map of access tags to access
*/ */
public static TagMap getDefaultAccessTags(OsmPrimitive primitive) { public static TagMap getDefaultAccessTags(OsmPrimitive primitive) {
TagMap access = new TagMap(); final var access = new TagMap();
final TagMap tags; final TagMap tags;
if (primitive.hasKey(HIGHWAY)) { if (primitive.hasKey(HIGHWAY)) {
tags = getDefaultHighwayAccessTags(primitive.getKeys()); tags = getDefaultHighwayAccessTags(primitive.getKeys());
@ -451,13 +451,9 @@ public class RoutingIslandsTest extends Test {
} }
private static String getCachedDirectionMode(String direction, String mode) { private static String getCachedDirectionMode(String direction, String mode) {
if (!DIRECTION_MAP.containsKey(direction)) { DIRECTION_MAP.computeIfAbsent(direction, d -> new HashMap<>(Access.getTransportModes().size()));
DIRECTION_MAP.put(direction, new HashMap<>(Access.getTransportModes().size()));
}
final var directionMap = DIRECTION_MAP.get(direction); final var directionMap = DIRECTION_MAP.get(direction);
if (!directionMap.containsKey(mode)) { directionMap.computeIfAbsent(mode, direction::concat);
directionMap.put(mode, direction.concat(mode));
}
return directionMap.get(mode); return directionMap.get(mode);
} }

Wyświetl plik

@ -4,22 +4,6 @@ package org.openstreetmap.josm.plugins.mapwithai.gui.preferences.mapwithai;
import static org.openstreetmap.josm.tools.I18n.marktr; import static org.openstreetmap.josm.tools.I18n.marktr;
import static org.openstreetmap.josm.tools.I18n.tr; import static org.openstreetmap.josm.tools.I18n.tr;
import javax.annotation.Nonnull;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
@ -43,6 +27,22 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import org.openstreetmap.gui.jmapviewer.Coordinate; import org.openstreetmap.gui.jmapviewer.Coordinate;
import org.openstreetmap.gui.jmapviewer.MapPolygonImpl; import org.openstreetmap.gui.jmapviewer.MapPolygonImpl;
import org.openstreetmap.gui.jmapviewer.MapRectangleImpl; import org.openstreetmap.gui.jmapviewer.MapRectangleImpl;
@ -52,6 +52,7 @@ import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.preferences.NamedColorProperty; import org.openstreetmap.josm.data.preferences.NamedColorProperty;
import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.bbox.JosmMapViewer;
import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser; import org.openstreetmap.josm.gui.bbox.SlippyMapBBoxChooser;
import org.openstreetmap.josm.gui.preferences.imagery.ImageryProvidersPanel; import org.openstreetmap.josm.gui.preferences.imagery.ImageryProvidersPanel;
import org.openstreetmap.josm.gui.util.GuiHelper; import org.openstreetmap.josm.gui.util.GuiHelper;
@ -72,6 +73,8 @@ import org.openstreetmap.josm.tools.ListenerList;
import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.OpenBrowser; import org.openstreetmap.josm.tools.OpenBrowser;
import jakarta.annotation.Nonnull;
/** /**
* A panel displaying imagery providers. Largely duplicates * A panel displaying imagery providers. Largely duplicates
* {@link ImageryProvidersPanel}. * {@link ImageryProvidersPanel}.
@ -376,7 +379,7 @@ public class MapWithAIProvidersPanel extends JPanel {
// Add default item map // Add default item map
defaultMap = new SlippyMapBBoxChooser(); defaultMap = new SlippyMapBBoxChooser();
defaultMap.setTileSource(SlippyMapBBoxChooser.DefaultOsmTileSourceProvider.get()); // for attribution defaultMap.setTileSource(JosmMapViewer.DefaultOsmTileSourceProvider.get()); // for attribution
defaultMap.addMouseListener(new MouseAdapter() { defaultMap.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
@ -408,36 +411,36 @@ public class MapWithAIProvidersPanel extends JPanel {
defaultTableListener = new DefListSelectionListener(); defaultTableListener = new DefListSelectionListener();
defaultTable.getSelectionModel().addListSelectionListener(defaultTableListener); defaultTable.getSelectionModel().addListSelectionListener(defaultTableListener);
defaultToolbar = new JToolBar(JToolBar.VERTICAL); defaultToolbar = new JToolBar(SwingConstants.VERTICAL);
defaultToolbar.setFloatable(false); defaultToolbar.setFloatable(false);
defaultToolbar.setBorderPainted(false); defaultToolbar.setBorderPainted(false);
defaultToolbar.setOpaque(false); defaultToolbar.setOpaque(false);
defaultToolbar.add(new ReloadAction()); defaultToolbar.add(new ReloadAction());
add(defaultToolbar, GBC.eol().anchor(GBC.SOUTH).insets(0, 0, 5, 0)); add(defaultToolbar, GBC.eol().anchor(GridBagConstraints.SOUTH).insets(0, 0, 5, 0));
final var help = new HtmlPanel( final var help = new HtmlPanel(
tr("New default entries can be added in the <a href=\"{0}\">GitHub Repository</a>.", tr("New default entries can be added in the <a href=\"{0}\">GitHub Repository</a>.",
"https://github.com/JOSM/MapWithAI/blob/pages/json/sources.json")); "https://github.com/JOSM/MapWithAI/blob/pages/json/sources.json"));
help.enableClickableHyperlinks(); help.enableClickableHyperlinks();
add(help, GBC.eol().insets(10, 0, 0, 0).fill(GBC.HORIZONTAL)); add(help, GBC.eol().insets(10, 0, 0, 0).fill(GridBagConstraints.HORIZONTAL));
final var activate = new ActivateAction(); final var activate = new ActivateAction();
defaultTable.getSelectionModel().addListSelectionListener(activate); defaultTable.getSelectionModel().addListSelectionListener(activate);
final var btnActivate = new JButton(activate); final var btnActivate = new JButton(activate);
middleToolbar = new JToolBar(JToolBar.HORIZONTAL); middleToolbar = new JToolBar(SwingConstants.HORIZONTAL);
middleToolbar.setFloatable(false); middleToolbar.setFloatable(false);
middleToolbar.setBorderPainted(false); middleToolbar.setBorderPainted(false);
middleToolbar.setOpaque(false); middleToolbar.setOpaque(false);
middleToolbar.add(btnActivate); middleToolbar.add(btnActivate);
add(middleToolbar, GBC.eol().anchor(GBC.CENTER).insets(5, 5, 5, 0)); add(middleToolbar, GBC.eol().anchor(GridBagConstraints.CENTER).insets(5, 5, 5, 0));
add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
final var scroll = new JScrollPane(activeTable); final var scroll = new JScrollPane(activeTable);
scroll.setPreferredSize(new Dimension(200, 200)); scroll.setPreferredSize(new Dimension(200, 200));
activeToolbar = new JToolBar(JToolBar.VERTICAL); activeToolbar = new JToolBar(SwingConstants.VERTICAL);
activeToolbar.setFloatable(false); activeToolbar.setFloatable(false);
activeToolbar.setBorderPainted(false); activeToolbar.setBorderPainted(false);
activeToolbar.setOpaque(false); activeToolbar.setOpaque(false);
@ -448,7 +451,7 @@ public class MapWithAIProvidersPanel extends JPanel {
add(new JLabel(tr("Selected entries:")), GBC.eol().insets(5, 0, 0, 0)); add(new JLabel(tr("Selected entries:")), GBC.eol().insets(5, 0, 0, 0));
add(scroll, GBC.std().fill(GridBagConstraints.BOTH).span(GridBagConstraints.RELATIVE).weight(1.0, 0.4) add(scroll, GBC.std().fill(GridBagConstraints.BOTH).span(GridBagConstraints.RELATIVE).weight(1.0, 0.4)
.insets(5, 0, 0, 5)); .insets(5, 0, 0, 5));
add(activeToolbar, GBC.eol().anchor(GBC.NORTH).insets(0, 0, 5, 5)); add(activeToolbar, GBC.eol().anchor(GridBagConstraints.NORTH).insets(0, 0, 5, 5));
} }
} }

Wyświetl plik

@ -1,9 +1,6 @@
// License: GPL. For details, see LICENSE file. // License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai; package org.openstreetmap.josm.plugins.mapwithai.io.mapwithai;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -36,6 +33,8 @@ import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.HttpClient; import org.openstreetmap.josm.tools.HttpClient;
import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Logging;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import jakarta.json.Json; import jakarta.json.Json;
import jakarta.json.JsonArray; import jakarta.json.JsonArray;
import jakarta.json.JsonNumber; import jakarta.json.JsonNumber;
@ -55,6 +54,7 @@ public class ESRISourceReader {
/** The cache storing ESRI source information (json) */ /** The cache storing ESRI source information (json) */
public static final CacheAccess<String, String> SOURCE_CACHE = JCSCacheManager.getCache("mapwithai:esrisources", 5, public static final CacheAccess<String, String> SOURCE_CACHE = JCSCacheManager.getCache("mapwithai:esrisources", 5,
50_000, new File(Config.getDirs().getCacheDirectory(true), "mapwithai").getPath()); 50_000, new File(Config.getDirs().getCacheDirectory(true), "mapwithai").getPath());
private static final String ACCESS_INFORMATION = "accessInformation";
private final MapWithAIInfo source; private final MapWithAIInfo source;
private boolean fastFail; private boolean fastFail;
private final List<MapWithAICategory> ignoreConflationCategories; private final List<MapWithAICategory> ignoreConflationCategories;
@ -187,9 +187,9 @@ public class ESRISourceReader {
if (this.ignoreConflationCategories.contains(newInfo.getCategory())) { if (this.ignoreConflationCategories.contains(newInfo.getCategory())) {
newInfo.setConflation(false); newInfo.setConflation(false);
} }
if (feature.containsKey("accessInformation") if (feature.containsKey(ACCESS_INFORMATION)
&& feature.get("accessInformation").getValueType() != JsonValue.ValueType.NULL) { && feature.get(ACCESS_INFORMATION).getValueType() != JsonValue.ValueType.NULL) {
newInfo.setAttributionText(feature.getString("accessInformation")); newInfo.setAttributionText(feature.getString(ACCESS_INFORMATION));
} }
newInfo.setDescription(feature.getString("snippet")); newInfo.setDescription(feature.getString("snippet"));
if (newInfo.getSource() != null) { if (newInfo.getSource() != null) {

Wyświetl plik

@ -8,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.data.Bounds; import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.osm.DataSet; import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.gui.progress.NullProgressMonitor; import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
@ -17,10 +16,10 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIType;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAIConfig; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAIConfig;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences; import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.BasicWiremock; import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
import org.openstreetmap.josm.testutils.annotations.HTTP; import org.openstreetmap.josm.testutils.annotations.HTTP;
import org.openstreetmap.josm.testutils.annotations.OsmApi;
import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.admin.model.GetServeEventsResult; import com.github.tomakehurst.wiremock.admin.model.GetServeEventsResult;
@ -41,12 +40,11 @@ import com.github.tomakehurst.wiremock.verification.LoggedRequest;
*/ */
@BasicPreferences @BasicPreferences
@HTTP @HTTP
@Wiremock
@MapWithAIConfig @MapWithAIConfig
@OsmApi(OsmApi.APIType.FAKE)
@Wiremock
class BoundingBoxMapWithAIDownloaderTest { class BoundingBoxMapWithAIDownloaderTest {
private static final String TEST_DATA = "<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/><node id=\"2\" lat=\"1\" lon=\"1\" version=\"1\"/></osm>"; private static final String TEST_DATA = "<osm version=\"0.6\"><node id=\"1\" lat=\"0\" lon=\"0\" version=\"1\"/><node id=\"2\" lat=\"1\" lon=\"1\" version=\"1\"/></osm>";
@RegisterExtension
JOSMTestRules josmTestRules = new JOSMTestRules().fakeAPI();
@BasicWiremock @BasicWiremock
public WireMockServer wireMockServer; public WireMockServer wireMockServer;

Wyświetl plik

@ -11,31 +11,25 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.actions.downloadtasks.DownloadParams; import org.openstreetmap.josm.actions.downloadtasks.DownloadParams;
import org.openstreetmap.josm.gui.progress.NullProgressMonitor; import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences; import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.OsmApi;
import org.openstreetmap.josm.testutils.annotations.Projection; import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.testutils.annotations.Territories; import org.openstreetmap.josm.testutils.annotations.Territories;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@BasicPreferences @BasicPreferences
@MapWithAISources @MapWithAISources
@NoExceptions @NoExceptions
@Wiremock @OsmApi(OsmApi.APIType.FAKE)
@Territories
@Projection @Projection
@Territories
@Wiremock
class DownloadMapWithAITaskTest { class DownloadMapWithAITaskTest {
@RegisterExtension
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
JOSMTestRules rule = new MapWithAITestRules().fakeAPI();
@Test @Test
void testDownloadOsmServerReaderDownloadParamsBoundsProgressMonitor() void testDownloadOsmServerReaderDownloadParamsBoundsProgressMonitor()

Wyświetl plik

@ -17,7 +17,6 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.TestUtils; import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.Bounds; import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.coor.LatLon;
@ -28,30 +27,24 @@ import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.data.projection.ProjectionRegistry; import org.openstreetmap.josm.data.projection.ProjectionRegistry;
import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.OsmDataLayer; import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions;
import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.annotations.OsmApi;
import org.openstreetmap.josm.testutils.annotations.Projection; import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.testutils.annotations.Territories; import org.openstreetmap.josm.testutils.annotations.Territories;
import org.openstreetmap.josm.tools.Geometry; import org.openstreetmap.josm.tools.Geometry;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/** /**
* Test class for {@link GetDataRunnable} * Test class for {@link GetDataRunnable}
* *
* @author Taylor Smock * @author Taylor Smock
*/ */
@NoExceptions
@MapWithAISources @MapWithAISources
@NoExceptions
@OsmApi(OsmApi.APIType.FAKE)
@Projection @Projection
@Territories @Territories
class GetDataRunnableTest { class GetDataRunnableTest {
@RegisterExtension
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
static JOSMTestRules rule = new MapWithAITestRules().fakeAPI();
@Test @Test
void testAddMissingElement() { void testAddMissingElement() {
Way way1 = TestUtils.newWay("", new Node(new LatLon(-5.7117803, 34.5011898)), Way way1 = TestUtils.newWay("", new Node(new LatLon(-5.7117803, 34.5011898)),

Wyświetl plik

@ -17,7 +17,6 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.openstreetmap.josm.TestUtils; import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.Bounds; import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.coor.ILatLon; import org.openstreetmap.josm.data.coor.ILatLon;
@ -32,19 +31,16 @@ import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.GpxLayer; import org.openstreetmap.josm.gui.layer.GpxLayer;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo; import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.testutils.MapWithAITestRules;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.MapWithAISources;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.NoExceptions;
import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock; import org.openstreetmap.josm.plugins.mapwithai.testutils.annotations.Wiremock;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.annotations.BasicPreferences; import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
import org.openstreetmap.josm.testutils.annotations.Main; import org.openstreetmap.josm.testutils.annotations.Main;
import org.openstreetmap.josm.testutils.annotations.OsmApi;
import org.openstreetmap.josm.testutils.annotations.Projection; import org.openstreetmap.josm.testutils.annotations.Projection;
import org.openstreetmap.josm.testutils.annotations.Territories; import org.openstreetmap.josm.testutils.annotations.Territories;
import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Logging;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/** /**
* Test class for {@link MapWithAIDataUtils} * Test class for {@link MapWithAIDataUtils}
* *
@ -54,6 +50,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@Main @Main
@MapWithAISources @MapWithAISources
@NoExceptions @NoExceptions
@OsmApi(OsmApi.APIType.FAKE)
@Projection @Projection
@Territories @Territories
@Wiremock @Wiremock
@ -61,10 +58,6 @@ public class MapWithAIDataUtilsTest {
/** This is the default MapWithAI URL */ /** This is the default MapWithAI URL */
private static final String DEFAULT_MAPWITHAI_API = "https://www.mapwith.ai/maps/ml_roads?conflate_with_osm=true&theme=ml_road_vector&collaborator=josm&token=ASb3N5o9HbX8QWn8G_NtHIRQaYv3nuG2r7_f3vnGld3KhZNCxg57IsaQyssIaEw5rfRNsPpMwg4TsnrSJtIJms5m&hash=ASawRla3rBcwEjY4HIY&bbox={bbox}"; private static final String DEFAULT_MAPWITHAI_API = "https://www.mapwith.ai/maps/ml_roads?conflate_with_osm=true&theme=ml_road_vector&collaborator=josm&token=ASb3N5o9HbX8QWn8G_NtHIRQaYv3nuG2r7_f3vnGld3KhZNCxg57IsaQyssIaEw5rfRNsPpMwg4TsnrSJtIJms5m&hash=ASawRla3rBcwEjY4HIY&bbox={bbox}";
@RegisterExtension
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
static JOSMTestRules test = new MapWithAITestRules().fakeAPI();
/** /**
* This gets data from MapWithAI. This test may fail if someone adds the data to * This gets data from MapWithAI. This test may fail if someone adds the data to
* OSM. * OSM.

Wyświetl plik

@ -62,7 +62,7 @@ import mockit.Mock;
@MapWithAISources @MapWithAISources
@Projection @Projection
@Wiremock @Wiremock
class MapWithAIAddComandTest { class MapWithAIAddCommandTest {
private final static String HIGHWAY_RESIDENTIAL = "highway=residential"; private final static String HIGHWAY_RESIDENTIAL = "highway=residential";
@BeforeEach @BeforeEach
@ -70,7 +70,7 @@ class MapWithAIAddComandTest {
// Required to avoid an NPE with AutoZoomHandler // Required to avoid an NPE with AutoZoomHandler
new WindowMocker() { new WindowMocker() {
@Mock @Mock
void pack() { public void pack() {
// Do nothing // Do nothing
} }
}; };