diff --git a/.github/workflows/ant-release.yml b/.github/workflows/ant-release.yml deleted file mode 100644 index 5767c11..0000000 --- a/.github/workflows/ant-release.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Release - -on: - release: - types: [created] - -jobs: - call-workflow: - uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v2 - with: - josm-revision: "r15229" - update-pluginssource: true - plugin-jar-name: 'highwaynamemodification' - secrets: - trac-username: ${{ secrets.TRAC_USERNAME }} - trac-password: ${{ secrets.TRAC_PASSWORD }} - - diff --git a/.github/workflows/ant.yml b/.github/workflows/ant.yml index 05cfc18..15468ca 100644 --- a/.github/workflows/ant.yml +++ b/.github/workflows/ant.yml @@ -16,7 +16,9 @@ jobs: call-workflow: strategy: matrix: - josm-revision: ["", "r15229"] - uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v2 + josm-revision: ["", "r19044"] + uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v3 with: josm-revision: ${{ matrix.josm-revision }} + perform-revision-tagging: ${{ matrix.josm-revision == 'r19044' && github.repository == 'JOSM/highwayNameModification' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }} + secrets: inherit diff --git a/gradle.properties b/gradle.properties index 319c82c..1735fbc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ # The minimum JOSM version this plugin is compatible with (can be any numeric version) -plugin.main.version = 15229 +plugin.main.version = 19044 # The JOSM version this plugin is currently compiled against # 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. -plugin.compile.version = 15229 +plugin.compile.version = 19044 plugin.canloadatruntime = true plugin.author = Taylor Smock plugin.class = org.openstreetmap.josm.plugins.highwaynamemodification.HighwayNameModification diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9d79b2d --- /dev/null +++ b/pom.xml @@ -0,0 +1,47 @@ + + 4.0.0 + + org.openstreetmap.josm.plugins + plugin-root + SNAPSHOT + + highwayNameModification + + ${plugin.link} + + + taylor.smock + tsmock@meta.com + Taylor Smock + + + + src/main/java + src/main/resources + 19044 + Taylor Smock <incoming+gokaart/JOSM_highwayNameModification@incoming.gitlab.com> + org.openstreetmap.josm.plugins.highwaynamemodification.HighwayNameModification + Modify addr tags when a highway name is changed + images/deltasignmod.svg + https://gitlab.com/gokaart/JOSM_highwayNameModification + true + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + ${plugin.link} + ${plugin.icon} + ${plugin.canloadatruntime} + + + + + + + diff --git a/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/DownloadAdditionalWays.java b/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/DownloadAdditionalWays.java index fdbd5b9..91d3330 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/DownloadAdditionalWays.java +++ b/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/DownloadAdditionalWays.java @@ -1,6 +1,9 @@ // License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.highwaynamemodification; +import static java.util.function.Predicate.not; + +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -48,6 +51,8 @@ private DownloadAdditionalWays() { */ public static boolean checkIfDownloaded(Collection ways) { boolean rValue = false; + final Collection layers = new ArrayList<>(MainApplication.getLayerManager().getLayers()); + downloadedLayerWays.keySet().removeIf(not(layers::contains)); for (HashMap> map : downloadedLayerWays.values()) { for (HashSet set : map.values()) { if (set.containsAll(ways)) { diff --git a/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameChangeAction.java b/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameChangeAction.java index a569c23..dd628ee 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameChangeAction.java +++ b/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameChangeAction.java @@ -42,8 +42,7 @@ public HighwayNameChangeAction(String name, String imageIcon, HighwayNameListene public void actionPerformed(ActionEvent e) { DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); Collection selection = ds.getAllSelected(); - ModifyWays modifyWays = listener.getModifyWays(); - modifyWays.setNameChangeInformation(selection, null, true); + ModifyWays modifyWays = new ModifyWays(selection, null, true); modifyWays.setDownloadTask(true); MainApplication.worker.execute(modifyWays); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameListener.java b/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameListener.java index 99a3562..1e46308 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameListener.java +++ b/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/HighwayNameListener.java @@ -1,7 +1,12 @@ // License: GPL. For details, see LICENSE file. package org.openstreetmap.josm.plugins.highwaynamemodification; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.openstreetmap.josm.data.osm.OsmPrimitive; import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; @@ -22,7 +27,7 @@ * @author Taylor Smock */ public class HighwayNameListener implements DataSetListener { - private final ModifyWays modifyWays = ModifyWays.getInstance(); + private static final String[] EMPTY_STRING_ARRAY = new String[0]; @Override public void primitivesAdded(PrimitivesAddedEvent event) { @@ -36,23 +41,16 @@ public void primitivesRemoved(PrimitivesRemovedEvent event) { @Override public void tagsChanged(TagsChangedEvent event) { - final OsmPrimitive osm = event.getPrimitive(); - final Map originalKeys = event.getOriginalKeys(); - if (osm.hasKey("highway") && originalKeys.containsKey("name") && osm.hasKey("name")) { - String newName = osm.get("name"); - String oldName = originalKeys.get("name"); + final String[] oldNew = getOldNewName(event); + if (oldNew.length == 2) { + String newName = oldNew[0]; + String oldName = oldNew[1]; if (newName.equals(oldName)) return; - modifyWays.setNameChangeInformation(event.getPrimitives(), oldName); - modifyWays.setDownloadTask(true); - MainApplication.worker.execute(modifyWays); + performTagChanges(oldName, Collections.singleton(event)); } } - public ModifyWays getModifyWays() { - return modifyWays; - } - @Override public void nodeMoved(NodeMovedEvent event) { // Don't care @@ -78,11 +76,33 @@ public void dataChanged(DataChangedEvent event) { // Validation fixes don't call tagsChanged, so we call it for them. if (event == null || event.getEvents() == null) return; - for (AbstractDatasetChangedEvent tEvent : event.getEvents()) { - if (DatasetEventType.TAGS_CHANGED == tEvent.getType()) { - tagsChanged((TagsChangedEvent) tEvent); - } + final Map> groupedEvents = event.getEvents().stream() + .filter(tEvent -> DatasetEventType.TAGS_CHANGED == tEvent.getType()) + .map(TagsChangedEvent.class::cast) + .collect(Collectors.groupingBy(tEvent -> String.join("----xxxx----", getOldNewName(tEvent)))); + for (List events : groupedEvents.values()) { + String oldName = getOldNewName(events.get(0))[0]; + performTagChanges(oldName, events); } } + private void performTagChanges(String oldName, Collection events) { + final Collection objects = events.stream().flatMap(event -> event.getPrimitives().stream()).collect(Collectors.toList()); + final ModifyWays modifyWays = new ModifyWays(objects, oldName); + modifyWays.setDownloadTask(true); + MainApplication.worker.execute(modifyWays); + } + + private String[] getOldNewName(TagsChangedEvent event) { + final OsmPrimitive osm = event.getPrimitive(); + final Map originalKeys = event.getOriginalKeys(); + if (osm.hasKey("highway") && originalKeys.containsKey("name") && osm.hasKey("name")) { + String newName = osm.get("name"); + String oldName = originalKeys.get("name"); + if (!newName.equals(oldName)) { + return new String[] {oldName, newName}; + } + } + return EMPTY_STRING_ARRAY; + } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/ModifyWays.java b/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/ModifyWays.java index f52fb4b..0497b43 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/ModifyWays.java +++ b/src/main/java/org/openstreetmap/josm/plugins/highwaynamemodification/ModifyWays.java @@ -42,45 +42,32 @@ final class ModifyWays implements Runnable { String originalName; boolean ignoreNewName; - private static class InstanceHolder { - static final ModifyWays INSTANCE = new ModifyWays(); - } - - private ModifyWays() { - // Do nothing - } - - public static ModifyWays getInstance() { - return InstanceHolder.INSTANCE; - } - - public synchronized void setDownloadTask(boolean b) { - this.downloadTask = b; - } - /** - * Set the name change information + * Create a new {@link ModifyWays} object * * @param osmCollection The objects to change names for * @param originalName The original name */ - public void setNameChangeInformation(Collection osmCollection, String originalName) { - setNameChangeInformation(osmCollection, originalName, false); + ModifyWays(Collection osmCollection, String originalName) { + this(osmCollection, originalName, false); } - /** - * Initialize a new ModifyWays method + * Create a new {@link ModifyWays} object * * @param osmCollection The collection of ways that are changing names * @param originalName The old name of the ways * @param ignoreNameChange If true, don't stop if the new name is the same as * the old name */ - public synchronized void setNameChangeInformation(Collection osmCollection, - String originalName, boolean ignoreNameChange) { - wayChangingName = osmCollection; + ModifyWays(Collection osmCollection, + String originalName, boolean ignoreNameChange) { + this.wayChangingName = osmCollection; this.originalName = originalName; - ignoreNewName = ignoreNameChange; + this.ignoreNewName = ignoreNameChange; + } + + public void setDownloadTask(boolean b) { + this.downloadTask = b; } private static class DownloadAdditionalAsk implements Runnable { @@ -124,23 +111,21 @@ public boolean get() throws InterruptedException { @Override public void run() { try { - synchronized (this) { - if (originalName != null && downloadTask - && !DownloadAdditionalWays.checkIfDownloaded(wayChangingName)) { - DownloadAdditionalAsk ask = new DownloadAdditionalAsk(); - GuiHelper.runInEDTAndWait(ask); - if (ask.get()) { - DownloadAdditionalWays.getAdditionalWays(wayChangingName, originalName); - } + if (originalName != null && downloadTask + && !DownloadAdditionalWays.checkIfDownloaded(wayChangingName)) { + DownloadAdditionalAsk ask = new DownloadAdditionalAsk(); + GuiHelper.runInEDTAndWait(ask); + if (ask.get()) { + DownloadAdditionalWays.getAdditionalWays(wayChangingName, originalName); } - for (OsmPrimitive osm : wayChangingName) { - if (originalName != null) { - doRealRun(osm, originalName); - } else { - for (String key : osm.keySet()) { - if (key.contains("name") && !"name".equals(key)) { - doRealRun(osm, osm.get(key)); - } + } + for (OsmPrimitive osm : wayChangingName) { + if (originalName != null) { + doRealRun(osm, originalName); + } else { + for (String key : osm.keySet()) { + if (key.contains("name") && !"name".equals(key)) { + doRealRun(osm, osm.get(key)); } } }