Class ValidatorCLI

java.lang.Object
org.openstreetmap.josm.data.validation.ValidatorCLI
All Implemented Interfaces:
CLIModule

public class ValidatorCLI extends Object implements CLIModule
Add a validate command to the JOSM command line interface.
Since:
18365
  • Field Details

  • Constructor Details

  • Method Details

    • getActionKeyword

      Description copied from interface: CLIModule
      Get the action keyword that the user needs to provide as first command line argument to invoke this module.
      Specified by:
      getActionKeyword in interface CLIModule
      Returns:
      the action keyword of this module
    • processArguments

      public void processArguments(String[] argArray)
      Description copied from interface: CLIModule
      Process the remaining command line arguments and run any of the requested actions.
      Specified by:
      processArguments in interface CLIModule
      Parameters:
      argArray - command line arguments without the initial action keyword
    • processMapcssFile

      private static void processMapcssFile(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(String inputFile) throws ParseException, IOException
      Process a validator file
      Parameters:
      inputFile - The file to check
      Throws:
      IOException - if there is a problem reading the file
      ParseException - if the file does not match the validator mapcss syntax
    • processFile

      private void processFile(String inputFile) throws IllegalDataException, IOException
      Process an OSM file
      Parameters:
      inputFile - The input filename
      Throws:
      IllegalArgumentException - If an argument is not valid
      IllegalDataException - If there is bad data
      IOException - If a file could not be read or written
    • writeErrors

      private void writeErrors(GeoJSONMapRouletteWriter geoJSONMapRouletteWriter, OutputStream fileOutputStream, Collection<TestError> errors)
    • getDefaultOutputName

      private static String getDefaultOutputName(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 String[] getFileParts(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(OutputStream fileOutputStream, byte[] bytes) throws IOException
      Write to a file. Synchronized to avoid writing to the same file in different threads.
      Parameters:
      fileOutputStream - The file output stream to read
      bytes - 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

      void parseArguments(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 Optional<String> handleOption(String currentInput, ValidatorCLI.Option option, String argument)
      Handle an option
      Parameters:
      currentInput - The current input file, if any. May be null.
      option - The option to parse
      argument - The argument for the option
      Returns:
      The new input file, if any.
    • showHelp

      private static void showHelp()
    • getHelp

      private static String getHelp()