Class ValidatorCLI
- java.lang.Object
-
- org.openstreetmap.josm.data.validation.ValidatorCLI
-
- All Implemented Interfaces:
CLIModule
public class ValidatorCLI extends java.lang.Object implements CLIModule
Add a validate command to the JOSM command line interface.- Since:
- 18365
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classValidatorCLI.Option
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.List<java.lang.String>>changeFilesThe change files.private java.util.List<java.lang.String>inputThe input file(s)static ValidatorCLIINSTANCEThe unique instance.private java.util.logging.LevellogLevelThe log levelprivate java.util.Map<java.lang.String,java.lang.String>outputThe output file(s).private static java.util.function.Supplier<ProgressMonitor>progressMonitorFactory
-
Constructor Summary
Constructors Constructor Description ValidatorCLI()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetActionKeyword()Get the action keyword that the user needs to provide as first command line argument to invoke this module.private static java.lang.StringgetDefaultOutputName(java.lang.String inputString)Get the default output nameprivate static java.lang.String[]getFileParts(java.lang.String inputString)Split a string into a filename + extension.private static java.lang.StringgetHelp()private java.util.Optional<java.lang.String>handleOption(java.lang.String currentInput, ValidatorCLI.Option option, java.lang.String argument)Handle an optionprivate voidhandleOption(ValidatorCLI.Option option)(package private) voidinitialize()Initialize everything that might be needed Arguments may need to be parsed first.(package private) voidparseArguments(java.lang.String[] argArray)Parse command line arguments and do some low-level error checking.voidprocessArguments(java.lang.String[] argArray)Process the remaining command line arguments and run any of the requested actions.private voidprocessFile(java.lang.String inputFile)Process an OSM fileprivate static voidprocessMapcssFile(java.lang.String inputFile)Process a standard mapcss fileprivate static voidprocessValidatorFile(java.lang.String inputFile)Process a validator fileprivate static voidshowHelp()private voidwriteErrors(GeoJSONMapRouletteWriter geoJSONMapRouletteWriter, java.io.OutputStream fileOutputStream, java.util.Collection<TestError> errors)private voidwriteToFile(java.io.OutputStream fileOutputStream, byte[] bytes)Write to a file.
-
-
-
Field Detail
-
INSTANCE
public static final ValidatorCLI INSTANCE
The unique instance.
-
input
private final java.util.List<java.lang.String> input
The input file(s)
-
changeFiles
private final java.util.Map<java.lang.String,java.util.List<java.lang.String>> changeFiles
The change files. input file → list of change files
-
output
private final java.util.Map<java.lang.String,java.lang.String> output
The output file(s). Ifnull, use input filename as base (replace extension with geojson). input → output
-
progressMonitorFactory
private static final java.util.function.Supplier<ProgressMonitor> progressMonitorFactory
-
logLevel
private java.util.logging.Level logLevel
The log level
-
-
Constructor Detail
-
ValidatorCLI
public ValidatorCLI()
-
-
Method Detail
-
getActionKeyword
public java.lang.String 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
public void processArguments(java.lang.String[] argArray)
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
private static void processMapcssFile(java.lang.String inputFile) throws ParseException
Process a standard mapcss file- Parameters:
inputFile- The mapcss file to validate- Throws:
ParseException- if the file does not match the mapcss syntax
-
processValidatorFile
private static void processValidatorFile(java.lang.String inputFile) throws ParseException, java.io.IOException
Process a validator file- Parameters:
inputFile- The file to check- Throws:
java.io.IOException- if there is a problem reading the fileParseException- if the file does not match the validator mapcss syntax
-
processFile
private void processFile(java.lang.String inputFile) throws IllegalDataException, java.io.IOException
Process an OSM file- Parameters:
inputFile- The input filename- Throws:
java.lang.IllegalArgumentException- If an argument is not validIllegalDataException- If there is bad datajava.io.IOException- If a file could not be read or written
-
writeErrors
private void writeErrors(GeoJSONMapRouletteWriter geoJSONMapRouletteWriter, java.io.OutputStream fileOutputStream, java.util.Collection<TestError> errors)
-
getDefaultOutputName
private static java.lang.String getDefaultOutputName(java.lang.String inputString)
Get the default output name- Parameters:
inputString- The input file- Returns:
- The default output name for the input file (extension stripped, ".geojson" added)
-
getFileParts
private static java.lang.String[] getFileParts(java.lang.String inputString)
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
private void writeToFile(java.io.OutputStream fileOutputStream, byte[] bytes) throws java.io.IOException
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:
java.io.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
void parseArguments(java.lang.String[] argArray)
Parse command line arguments and do some low-level error checking.- Parameters:
argArray- the arguments array
-
handleOption
private void handleOption(ValidatorCLI.Option option)
-
handleOption
private java.util.Optional<java.lang.String> handleOption(java.lang.String currentInput, ValidatorCLI.Option option, java.lang.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
private static void showHelp()
-
getHelp
private static java.lang.String getHelp()
-
-