Changeset 19048 in josm for trunk/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
- Timestamp:
- 2024-04-19T16:21:11+02:00 (4 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/ValidatorCLI.java
r18950 r19048 11 11 import java.nio.charset.StandardCharsets; 12 12 import java.nio.file.Files; 13 import java.nio.file.Path;14 13 import java.nio.file.Paths; 15 14 import java.util.ArrayList; … … 27 26 import java.util.stream.Collectors; 28 27 29 import org.apache.commons. compress.utils.FileNameUtils;28 import org.apache.commons.io.FilenameUtils; 30 29 import org.openstreetmap.josm.actions.ExtensionFileFilter; 31 30 import org.openstreetmap.josm.cli.CLIModule; 32 31 import org.openstreetmap.josm.data.Preferences; 33 import org.openstreetmap.josm.data.osm.DataSet;34 32 import org.openstreetmap.josm.data.preferences.JosmBaseDirectories; 35 33 import org.openstreetmap.josm.data.preferences.JosmUrls; … … 176 174 } 177 175 this.initialize(); 178 final ProgressMonitor fileMonitor = progressMonitorFactory.get();176 final var fileMonitor = progressMonitorFactory.get(); 179 177 fileMonitor.beginTask(tr("Processing files..."), this.input.size()); 180 178 for (String inputFile : this.input) { … … 202 200 */ 203 201 private static void processMapcssFile(final String inputFile) throws ParseException { 204 final MapCSSStyleSourcestyleSource = new MapCSSStyleSource(new File(inputFile).toURI().getPath(), inputFile, inputFile);202 final var styleSource = new MapCSSStyleSource(new File(inputFile).toURI().getPath(), inputFile, inputFile); 205 203 styleSource.loadStyleSource(); 206 204 if (!styleSource.getErrors().isEmpty()) { … … 221 219 // Check asserts 222 220 Config.getPref().putBoolean("validator.check_assert_local_rules", true); 223 final MapCSSTagChecker mapCSSTagChecker = new MapCSSTagChecker();224 final Collection<String> assertionErrors = new ArrayList<>();221 final var mapCSSTagChecker = new MapCSSTagChecker(); 222 final var assertionErrors = new ArrayList<String>(); 225 223 final MapCSSTagChecker.ParseResult result = mapCSSTagChecker.addMapCSS(new File(inputFile).toURI().getPath(), 226 224 assertionErrors::add); … … 247 245 */ 248 246 private void processFile(final String inputFile) throws IllegalDataException, IOException { 249 final FileinputFileFile = new File(inputFile);247 final var inputFileFile = new File(inputFile); 250 248 final List<FileImporter> inputFileImporters = ExtensionFileFilter.getImporters().stream() 251 249 .filter(importer -> importer.acceptFile(inputFileFile)).collect(Collectors.toList()); 252 final Stopwatchstopwatch = Stopwatch.createStarted();250 final var stopwatch = Stopwatch.createStarted(); 253 251 if (inputFileImporters.stream().noneMatch(fileImporter -> 254 252 fileImporter.importDataHandleExceptions(inputFileFile, progressMonitorFactory.get()))) { … … 263 261 .stream().filter(layer -> inputFileFile.equals(layer.getAssociatedFile())) 264 262 .findFirst().orElseThrow(() -> new JosmRuntimeException(tr("Could not find a layer for {0}", inputFile))); 265 final DataSetdataSet = dataLayer.getDataSet();263 final var dataSet = dataLayer.getDataSet(); 266 264 if (this.changeFiles.containsKey(inputFile)) { 267 ProgressMonitor changeFilesMonitor = progressMonitorFactory.get();265 final var changeFilesMonitor = progressMonitorFactory.get(); 268 266 for (String changeFile : this.changeFiles.getOrDefault(inputFile, Collections.emptyList())) { 269 try ( InputStreamchangeStream = Compression.getUncompressedFileInputStream(Paths.get(changeFile))) {267 try (var changeStream = Compression.getUncompressedFileInputStream(Paths.get(changeFile))) { 270 268 dataSet.mergeFrom(OsmChangeReader.parseDataSet(changeStream, changeFilesMonitor)); 271 269 } 272 270 } 273 271 } 274 Pathpath = Paths.get(outputFile);272 final var path = Paths.get(outputFile); 275 273 if (path.toFile().isFile() && !Files.deleteIfExists(path)) { 276 274 Logging.error("Could not delete {0}, attempting to append", outputFile); 277 275 } 278 GeoJSONMapRouletteWriter geoJSONMapRouletteWriter = new GeoJSONMapRouletteWriter(dataSet);276 final var geoJSONMapRouletteWriter = new GeoJSONMapRouletteWriter(dataSet); 279 277 OsmValidator.initializeTests(); 280 278 281 try ( OutputStreamfileOutputStream = Files.newOutputStream(path)) {279 try (var fileOutputStream = Files.newOutputStream(path)) { 282 280 // The first writeErrors catches anything that was written, for whatever reason. This is probably never 283 281 // going to be called. 284 ValidationTaskvalidationTask = new ValidationTask(errors -> writeErrors(geoJSONMapRouletteWriter, fileOutputStream, errors),282 final var validationTask = new ValidationTask(errors -> writeErrors(geoJSONMapRouletteWriter, fileOutputStream, errors), 285 283 progressMonitorFactory.get(), OsmValidator.getEnabledTests(false), 286 284 dataSet.allPrimitives(), Collections.emptyList(), false); … … 320 318 */ 321 319 private static String getDefaultOutputName(final String inputString) { 322 final String extension = File NameUtils.getExtension(inputString);320 final String extension = FilenameUtils.getExtension(inputString); 323 321 if (!Arrays.asList("zip", "bz", "xz", "geojson").contains(extension)) { 324 return File NameUtils.getBaseName(inputString) + ".geojson";322 return FilenameUtils.getBaseName(inputString) + ".geojson"; 325 323 } else if ("geojson".equals(extension)) { 326 324 // Account for geojson input files 327 return File NameUtils.getBaseName(inputString) + ".validated.geojson";328 } 329 return File NameUtils.getBaseName(FileNameUtils.getBaseName(inputString)) + ".geojson";325 return FilenameUtils.getBaseName(inputString) + ".validated.geojson"; 326 } 327 return FilenameUtils.getBaseName(FilenameUtils.getBaseName(inputString)) + ".geojson"; 330 328 } 331 329 … … 348 346 /** 349 347 * Initialize everything that might be needed 350 * 348 * <p> 351 349 * Arguments may need to be parsed first. 352 350 */ … … 369 367 Logging.setLogLevel(Level.INFO); 370 368 371 OptionParser parser = new OptionParser("JOSM validate");372 final AtomicReference<String> currentInput = new AtomicReference<>(null);369 final var parser = new OptionParser("JOSM validate"); 370 final var currentInput = new AtomicReference<String>(null); 373 371 for (Option o : Option.values()) { 374 372 if (o.requiresArgument()) { … … 425 423 break; 426 424 case LOAD_PREFERENCES: 427 final PreferencestempPreferences = new Preferences();425 final var tempPreferences = new Preferences(); 428 426 tempPreferences.enableSaveOnPut(false); 429 CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(tempPreferences);427 final var config = new CustomConfigurator.XMLCommandProcessor(tempPreferences); 430 428 try (InputStream is = Utils.openStream(new File(argument).toURI().toURL())) { 431 429 config.openAndReadXML(is); … … 435 433 final IPreferences pref = Config.getPref(); 436 434 if (pref instanceof MemoryPreferences) { 437 final MemoryPreferencesmemoryPreferences = (MemoryPreferences) pref;435 final var memoryPreferences = (MemoryPreferences) pref; 438 436 tempPreferences.getAllSettings().forEach(memoryPreferences::putSetting); 439 437 } else { … … 454 452 455 453 private static String getHelp() { 456 final StringhelpPadding = "\t ";454 final var helpPadding = "\t "; 457 455 // CHECKSTYLE.OFF: SingleSpaceSeparator 458 456 return tr("JOSM Validation command line interface") + "\n\n" +
Note:
See TracChangeset
for help on using the changeset viewer.