Class 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 class  ValidatorCLI.Option  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.util.List<java.lang.String>> changeFiles
      The change files.
      private java.util.List<java.lang.String> input
      The input file(s)
      static ValidatorCLI INSTANCE
      The unique instance.
      private java.util.logging.Level logLevel
      The log level
      private java.util.Map<java.lang.String,​java.lang.String> output
      The 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.String getActionKeyword()
      Get the action keyword that the user needs to provide as first command line argument to invoke this module.
      private static java.lang.String getDefaultOutputName​(java.lang.String inputString)
      Get the default output name
      private static java.lang.String[] getFileParts​(java.lang.String inputString)
      Split a string into a filename + extension.
      private static java.lang.String getHelp()  
      private java.util.Optional<java.lang.String> handleOption​(java.lang.String currentInput, ValidatorCLI.Option option, java.lang.String argument)
      Handle an option
      private void handleOption​(ValidatorCLI.Option option)  
      (package private) void initialize()
      Initialize everything that might be needed Arguments may need to be parsed first.
      (package private) void parseArguments​(java.lang.String[] argArray)
      Parse command line arguments and do some low-level error checking.
      void processArguments​(java.lang.String[] argArray)
      Process the remaining command line arguments and run any of the requested actions.
      private void processFile​(java.lang.String inputFile)
      Process an OSM file
      private static void processMapcssFile​(java.lang.String inputFile)
      Process a standard mapcss file
      private static void processValidatorFile​(java.lang.String inputFile)
      Process a validator file
      private static void showHelp()  
      private void writeErrors​(GeoJSONMapRouletteWriter geoJSONMapRouletteWriter, java.io.OutputStream fileOutputStream, java.util.Collection<TestError> errors)  
      private void writeToFile​(java.io.OutputStream fileOutputStream, byte[] bytes)
      Write to a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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). If null, use input filename as base (replace extension with geojson). input → output
      • logLevel

        private java.util.logging.Level logLevel
        The log level
    • Method Detail

      • getActionKeyword

        public java.lang.String 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​(java.lang.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​(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 file
        ParseException - 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 valid
        IllegalDataException - If there is bad data
        java.io.IOException - If a file could not be read or written
      • 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 read
        bytes - 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 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 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 java.lang.String getHelp()