Class ValidationUtils


  • public final class ValidationUtils
    extends java.lang.Object
    Utilities class for validating user's input and generation
    • Constructor Summary

      Constructors 
      Constructor Description
      ValidationUtils()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkGenerationReport​(com.devonfw.cobigen.api.to.GenerationReportTo report)
      Checks the generation report in order to find possible errors and warnings
      static java.lang.String getUserInput()
      Asks the user for input and returns the value
      static boolean isOutputRootPathValid​(java.nio.file.Path outputRootPath)
      Checks whether the current output root path is valid.
      static void throwNoTriggersMatched​(java.nio.file.Path inputFile, boolean isJavaInput, boolean isOpenApiInput)
      Prints an error message to the user informing that no triggers have been matched.
      boolean validateFile​(java.io.File inputFile)
      Validating user input file is correct or not.
      static boolean yesNoPrompt​(java.lang.String validInputMessage, java.lang.String invalidInputMessage, java.lang.String cancelMessage)
      Creates a simple looping yes/no prompt with customizable valid/invalid/cancel messages
      • Methods inherited from class java.lang.Object

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

      • ValidationUtils

        public ValidationUtils()
    • Method Detail

      • validateFile

        public boolean validateFile​(java.io.File inputFile)
        Validating user input file is correct or not. We check if file exists and it can be read
        Parameters:
        inputFile - user input file
        Returns:
        true when file is valid
      • isOutputRootPathValid

        public static boolean isOutputRootPathValid​(java.nio.file.Path outputRootPath)
        Checks whether the current output root path is valid. It can be either null because it is an optional parameter or either a folder that exists.
        Parameters:
        outputRootPath - where the user wants to generate the code
        Returns:
        true if it is a valid output root path
      • checkGenerationReport

        public static void checkGenerationReport​(com.devonfw.cobigen.api.to.GenerationReportTo report)
        Checks the generation report in order to find possible errors and warnings
        Parameters:
        report - the generation report returned by the CobiGen.generate method
      • throwNoTriggersMatched

        public static void throwNoTriggersMatched​(java.nio.file.Path inputFile,
                                                  boolean isJavaInput,
                                                  boolean isOpenApiInput)
        Prints an error message to the user informing that no triggers have been matched. Depending on the type of the input file will print different messages.
        Parameters:
        inputFile - User input file
        isJavaInput - true when input file is Java
        isOpenApiInput - true when input file is OpenAPI
      • getUserInput

        public static java.lang.String getUserInput()
        Asks the user for input and returns the value
        Returns:
        String containing the user input
      • yesNoPrompt

        public static boolean yesNoPrompt​(java.lang.String validInputMessage,
                                          java.lang.String invalidInputMessage,
                                          java.lang.String cancelMessage)
        Creates a simple looping yes/no prompt with customizable valid/invalid/cancel messages
        Parameters:
        validInputMessage - String for a message in case of a valid input
        invalidInputMessage - String for a message in case of an invalid input
        cancelMessage - String for a message in case the user cancelled the process
        Returns:
        boolean decision of the user