Opened 3 years ago
Last modified 3 years ago
#22898 closed defect
JOSM Validator CLI errors out when is run with --load-preferences argument — at Initial Version
| Reported by: | Owned by: | team | |
|---|---|---|---|
| Priority: | normal | Milestone: | 23.04 |
| Component: | Core | Version: | latest |
| Keywords: | Cc: |
Description
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);
- should be called before
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.
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/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
+++ b/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
@@ -165,10 +165,17 @@ public class ValidatorCLI implements CLIModule {
// Ensure that preferences are only in memory
Config.setPreferencesInstance(new MemoryPreferences());
Logging.setLogLevel(Level.INFO);
+ Logging.setLogLevel(this.logLevel);
+ HttpClient.setFactory(Http1Client::new);
+ Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file
+ Config.setUrlsProvider(JosmUrls.getInstance());
+ ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT)));
+
this.parseArguments(argArray);
if (this.input.isEmpty()) {
throw new IllegalArgumentException(tr("Missing argument - input data file ({0})", "--input|-i"));
}
+
this.initialize();
final ProgressMonitor fileMonitor = progressMonitorFactory.get();
fileMonitor.beginTask(tr("Processing files..."), this.input.size());
@@ -345,12 +352,6 @@ public class ValidatorCLI implements CLIModule {
* Arguments may need to be parsed first.
*/
void initialize() {
- Logging.setLogLevel(this.logLevel);
- HttpClient.setFactory(Http1Client::new);
- Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file
- Config.setUrlsProvider(JosmUrls.getInstance());
- ProjectionRegistry.setProjection(Projections.getProjectionByCode("epsg:3857".toUpperCase(Locale.ROOT)));
-
Territories.initializeInternalData();
OsmValidator.initialize();
MapPaintStyles.readFromPreferences();
@@ -430,7 +431,7 @@ public class ValidatorCLI implements CLIModule {
final IPreferences pref = Config.getPref();
if (pref instanceof MemoryPreferences) {
final MemoryPreferences memoryPreferences = (MemoryPreferences) pref;
- tempPreferences.getAllSettings().entrySet().stream().filter(entry -> entry.getValue().isNew())
+ tempPreferences.getAllSettings().entrySet().stream()
.forEach(entry -> memoryPreferences.putSetting(entry.getKey(), entry.getValue()));
} else {
throw new JosmRuntimeException(tr("Preferences are not the expected type"));


