Changeset 16834 in josm


Ignore:
Timestamp:
2020-08-03T20:23:44+02:00 (4 years ago)
Author:
simon04
Message:

fix #19620 - Tag2Link: allow to customize sources

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Tag2Link.java

    r16780 r16834  
    2323
    2424import org.openstreetmap.josm.data.osm.OsmUtils;
     25import org.openstreetmap.josm.data.preferences.ListProperty;
     26import org.openstreetmap.josm.io.CachedFile;
    2527
    2628/**
     
    5456            .collect(Collectors.joining("|"));
    5557
     58    static final ListProperty PREF_SOURCE = new ListProperty("tag2link.source",
     59            Collections.singletonList("resource://META-INF/resources/webjars/tag2link/2020.7.15/index.json"));
     60
    5661    private Tag2Link() {
    5762        // private constructor for utility class
     
    7782        try {
    7883            wikidataRules.clear();
    79             initializeFromResources();
     84            for (String source : PREF_SOURCE.get()) {
     85                initializeFromResources(new CachedFile(source));
     86            }
    8087        } catch (Exception e) {
    8188            Logging.error("Failed to initialize tag2link rules");
     
    8794     * Initializes the tag2link rules from the resources.
    8895     *
     96     * @param resource the source
    8997     * @throws IOException in case of I/O error
    9098     */
    91     private static void initializeFromResources() throws IOException {
    92         final String resource = "META-INF/resources/webjars/tag2link/2020.7.15/index.json";
     99    private static void initializeFromResources(CachedFile resource) throws IOException {
    93100        final JsonArray rules;
    94         try (InputStream inputStream = Tag2Link.class.getClassLoader().getResourceAsStream(resource);
     101        try (InputStream inputStream = resource.getInputStream();
    95102             JsonReader jsonReader = Json.createReader(inputStream)) {
    96103            rules = jsonReader.readArray();
  • trunk/test/unit/org/openstreetmap/josm/tools/Tag2LinkTest.java

    r16774 r16834  
    77
    88import org.junit.Assert;
     9import org.junit.Rule;
    910import org.junit.Test;
     11import org.openstreetmap.josm.testutils.JOSMTestRules;
     12
     13import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1014
    1115/**
     
    2327        Assert.assertEquals(Arrays.asList(expected), links);
    2428    }
     29
     30    /**
     31     * Setup test.
     32     */
     33    @Rule
     34    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     35    public JOSMTestRules test = new JOSMTestRules().preferences();
    2536
    2637    /**
Note: See TracChangeset for help on using the changeset viewer.