Opened 2 years ago

Last modified 2 years ago

#22898 closed defect

[Patch] JOSM Validator CLI errors out when is run with --load-preferences argument — at Version 1

Reported by: emanuel_raymond@… Owned by: team
Priority: normal Milestone: 23.04
Component: Core Version: latest
Keywords: Cc:

Description (last modified by skyper)

Use case: would like to use --load-preferences argument to add custom mapcss rules for the validator when running in CLI mode.

Problem: When running with --load-preferences, JOSM Validator CLI errors out.

Description:

I notice the issue is coming from these lines:

  • Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance());
    • should be called before this.parseArguments(argArray);
  • tempPreferences.getAllSettings().entrySet().stream().filter(entry -> entry.getValue().isNew())
    • I removed the isNew filter because I noticed that they were not set to true.

The following code snippet is the git diff for the fix that I applied to mitigate this error. Note: I have little knowledge to the whole source code and this is my first time debugging and exploring the code myself.

  • src/org/openstreetmap/josm/data/validation/ValidatorCLI.java

    diff --git a/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java b/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
    index cd4164c37..a2807cfe5 100644
    a b public class ValidatorCLI implements CLIModule {  
    165165            // Ensure that preferences are only in memory
    166166            Config.setPreferencesInstance(new MemoryPreferences());
    167167            Logging.setLogLevel(Level.INFO);
     168            Logging.setLogLevel(this.logLevel);
     169            HttpClient.setFactory(Http1Client::new);
     170            Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file
     171            Config.setUrlsProvider(JosmUrls.getInstance());
     172            ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT)));
     173           
    168174            this.parseArguments(argArray);
    169175            if (this.input.isEmpty()) {
    170176                throw new IllegalArgumentException(tr("Missing argument - input data file ({0})", "--input|-i"));
    171177            }
     178           
    172179            this.initialize();
    173180            final ProgressMonitor fileMonitor = progressMonitorFactory.get();
    174181            fileMonitor.beginTask(tr("Processing files..."), this.input.size());
    public class ValidatorCLI implements CLIModule {  
    345352     * Arguments may need to be parsed first.
    346353     */
    347354    void initialize() {
    348         Logging.setLogLevel(this.logLevel);
    349         HttpClient.setFactory(Http1Client::new);
    350         Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file
    351         Config.setUrlsProvider(JosmUrls.getInstance());
    352         ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT)));
    353 
    354355        Territories.initializeInternalData();
    355356        OsmValidator.initialize();
    356357        MapPaintStyles.readFromPreferences();
    public class ValidatorCLI implements CLIModule {  
    430431            final IPreferences pref = Config.getPref();
    431432            if (pref instanceof MemoryPreferences) {
    432433                final MemoryPreferences memoryPreferences = (MemoryPreferences) pref;
    433                 tempPreferences.getAllSettings().entrySet().stream().filter(entry -> entry.getValue().isNew())
     434                tempPreferences.getAllSettings().entrySet().stream()
    434435                        .forEach(entry -> memoryPreferences.putSetting(entry.getKey(), entry.getValue()));
    435436            } else {
    436437                throw new JosmRuntimeException(tr("Preferences are not the expected type"));

Change History (1)

comment:1 by skyper, 2 years ago

Component: Core validatorCore
Description: modified (diff)
Summary: JOSM Validator CLI errors out when is run with --load-preferences argument[Patch] JOSM Validator CLI errors out when is run with --load-preferences argument
Note: See TracTickets for help on using tickets.