Class ValidatorCLI
java.lang.Object
org.openstreetmap.josm.data.validation.ValidatorCLI
- All Implemented Interfaces:
CLIModule
Add a validate command to the JOSM command line interface.
- Since:
- 18365
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionThe change files.The input file(s)static final ValidatorCLIThe unique instance.private LevelThe log levelThe output file(s).private static final Supplier<ProgressMonitor> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the action keyword that the user needs to provide as first command line argument to invoke this module.private static StringgetDefaultOutputName(String inputString) Get the default output nameprivate static String[]getFileParts(String inputString) Split a string into a filename + extension.private static StringgetHelp()handleOption(String currentInput, ValidatorCLI.Option option, String argument) Handle an optionprivate voidhandleOption(ValidatorCLI.Option option) (package private) voidInitialize everything that might be needed Arguments may need to be parsed first.(package private) voidparseArguments(String[] argArray) Parse command line arguments and do some low-level error checking.voidprocessArguments(String[] argArray) Process the remaining command line arguments and run any of the requested actions.private voidprocessFile(String inputFile) Process an OSM fileprivate static voidprocessMapcssFile(String inputFile) Process a standard mapcss fileprivate static voidprocessValidatorFile(String inputFile) Process a validator fileprivate static voidshowHelp()private voidwriteErrors(GeoJSONMapRouletteWriter geoJSONMapRouletteWriter, OutputStream fileOutputStream, Collection<TestError> errors) private voidwriteToFile(OutputStream fileOutputStream, byte[] bytes) Write to a file.
-
Field Details
-
INSTANCE
The unique instance. -
input
The input file(s) -
changeFiles
The change files. input file → list of change files -
output
The output file(s). Ifnull, use input filename as base (replace extension with geojson). input → output -
progressMonitorFactory
-
logLevel
The log level
-
-
Constructor Details
-
ValidatorCLI
public ValidatorCLI()
-
-
Method Details
-
getActionKeyword
Description copied from interface:CLIModuleGet the action keyword that the user needs to provide as first command line argument to invoke this module.- Specified by:
getActionKeywordin interfaceCLIModule- Returns:
- the action keyword of this module
-
processArguments
Description copied from interface:CLIModuleProcess the remaining command line arguments and run any of the requested actions.- Specified by:
processArgumentsin interfaceCLIModule- Parameters:
argArray- command line arguments without the initial action keyword
-
processMapcssFile
Process a standard mapcss file- Parameters:
inputFile- The mapcss file to validate- Throws:
ParseException- if the file does not match the mapcss syntax
-
processValidatorFile
Process a validator file- Parameters:
inputFile- The file to check- Throws:
IOException- if there is a problem reading the fileParseException- if the file does not match the validator mapcss syntax
-
processFile
Process an OSM file- Parameters:
inputFile- The input filename- Throws:
IllegalArgumentException- If an argument is not validIllegalDataException- If there is bad dataIOException- If a file could not be read or written
-
writeErrors
private void writeErrors(GeoJSONMapRouletteWriter geoJSONMapRouletteWriter, OutputStream fileOutputStream, Collection<TestError> errors) -
getDefaultOutputName
Get the default output name- Parameters:
inputString- The input file- Returns:
- The default output name for the input file (extension stripped, ".geojson" added)
-
getFileParts
Split a string into a filename + extension. Example: "foo.bar.txt" → ["foo.bar", "txt"]Please note that future versions of Java may make this method redundant. It is not as of Java 21 (look for something like
Path#getExtension, see JDK-8298318. That may be in Java 22.- Parameters:
inputString- The string to get the filename and extension from- Returns:
- The filename and the (optional) extension
-
writeToFile
Write to a file. Synchronized to avoid writing to the same file in different threads.- Parameters:
fileOutputStream- The file output stream to readbytes- The bytes to write (surrounded by RS and LF)- Throws:
IOException- If we couldn't write to file
-
initialize
void initialize()Initialize everything that might be needed Arguments may need to be parsed first. -
parseArguments
Parse command line arguments and do some low-level error checking.- Parameters:
argArray- the arguments array
-
handleOption
-
handleOption
private Optional<String> handleOption(String currentInput, ValidatorCLI.Option option, String argument) Handle an option- Parameters:
currentInput- The current input file, if any. May benull.option- The option to parseargument- The argument for the option- Returns:
- The new input file, if any.
-
showHelp
-
getHelp
-