Class InitProjectUtil

java.lang.Object
liquibase.command.core.init.InitProjectUtil

public class InitProjectUtil extends Object
  • Field Details

  • Constructor Details

    • InitProjectUtil

      public InitProjectUtil()
  • Method Details

    • createProjectDirectory

      public static void createProjectDirectory(File projectDirFile) throws CommandExecutionException
      Create the project directory, including any non-existent segments
      Parameters:
      projectDirFile - Directory to create
      Throws:
      CommandExecutionException
    • validateChangelogFilePath

      public static void validateChangelogFilePath(String changelogFilePath)
      Make sure the changelog path does not have any path elements
      Parameters:
      changelogFilePath - Path to changelog
    • validateProjectDirectory

      public static void validateProjectDirectory(File projectDirFile) throws CommandExecutionException
      Make sure the input project directory is not a file
      Parameters:
      projectDirFile - The project directory File object
      Throws:
      CommandExecutionException
    • updateDefaultsFile

      public static void updateDefaultsFile(File defaultsFile, boolean newDefaultsFile, String format, ConfiguredValue<String> changelogConfig, ConfiguredValue<String> urlConfig, ConfiguredValue<String> usernameConfig, ConfiguredValue<String> passwordConfig, InitProjectUtil.FileCreationResultEnum changelogFileCreationResult, Boolean shouldBackupDefaultsFile, CommandResultsBuilder resultsBuilder) throws IOException
      Update the defaults file with any argument values
      Parameters:
      defaultsFile - The defaults file we are updating
      newDefaultsFile - True if this is a new file False if not
      format - The current format value
      changelogConfig - The ConfiguredValue for changelogfile
      urlConfig - The ConfiguredValue for url
      usernameConfig - The ConfiguredValue for username
      passwordConfig - The ConfiguredValue for password
      changelogFileCreationResult - boolean indicating whether the changelogfile was copied into the project directory. If the file was not copied, then an empty changelogfile property is used in the defaults file.
      shouldBackupDefaultsFile - If false, the defaults file will not be backed up and the caller will be responsible for both backing up the existing defaults file AND writing the new contents of the modified defaults file. The contents of the modified will be returned in the results builder.
      resultsBuilder - The results builder
      Throws:
      IOException
    • makeBackup

      public static String makeBackup(Resource resource, Resource backupResource, String contents, String extraMessage, boolean printMessage)
      Make a backup copy of the checks or flow file
      Parameters:
      resource - The resource to back up
      backupResource - The resource to back up to
      contents - The contents of the file
      extraMessage - Extra message text to include
      printMessage - Should the warning message be printed to the console? If an exception occurs, the exception message will be printed regardless of the value of printMessage.
    • outputBackedUpDefaultsFileMessage

      public static void outputBackedUpDefaultsFileMessage(String absolutePath)
      Print out a message to the console and logs indicating that the defaults file was backed up.
      Parameters:
      absolutePath - the path of the defaults file that was backed up (not the path of the backup file)
    • replaceProperty

      public static String replaceProperty(String key, ConfiguredValue<String> config, String contents, boolean newDefaultsFile)
      Replace the contents where "key=" with the value from the ConfiguredValue
      Parameters:
      key - The property key to replace
      config - The ConfiguredValue of the property
      contents - The current defaults file contents
      newDefaultsFile - Specify whether the defaults file was newly created (true), or it already existed (false)
      Returns:
      String
    • replaceProperty

      public static String replaceProperty(String key, String configValue, String contents, boolean newDefaultsFile)
      Replace the contents where "key=" with the value from the ConfiguredValue
      Parameters:
      key - The property key to replace
      configValue - The property value
      contents - The current defaults file contents
      newDefaultsFile - Specify whether the defaults file was newly created (true), or it already existed (false)
      Returns:
      String
    • replaceProperty

      public static String replaceProperty(String key, String configValue, String contents, boolean commented, boolean includeKeyPrefix, boolean addPropertyIfMissing, boolean newDefaultsFile, boolean useExistingValueIfExists)
      Replace the contents where "key=" with the value from the ConfiguredValue
      Parameters:
      key - The property key to replace
      configValue - The property value
      contents - The current defaults file contents
      commented - If true, put in the new value with the entire line commented out with a # symbol
      includeKeyPrefix - If true, the key will be prefixed with liquibase.command. unless it is found exactly as written in the existing contents.
      addPropertyIfMissing - If true, the key specified will be added to the file contents if it does not already exist. If false, and the key does not already exist, it will not be added.
      newDefaultsFile - Specify whether the defaults file was newly created (true), or it already existed (false)
      useExistingValueIfExists - If true, and the defaults file already existed and the existing value in the defaults file is not empty, it will remain there, untouched.
      Returns:
      String
    • copyExampleProperties

      public static File copyExampleProperties(String format, String projectDirFile, String targetDefaultsFilename) throws CommandExecutionException
      Copy the example properties file to the project directory Return the File object representing the properties file
      Parameters:
      format - The format of the associated changelog
      projectDirFile - The project directory File object
      targetDefaultsFilename - The name we will give to the copied file
      Returns:
      File The new properties File object
      Throws:
      CommandExecutionException
    • copyExampleChangelog

      public static InitProjectUtil.FileCreationResultEnum copyExampleChangelog(String format, File projectDirFile, String changelogFilePath, ConfiguredValue<String> changelogFileConfig) throws CommandExecutionException
      Copy the example changelog file of the format specified to the project directory if necessary Return the File object representing the properties file
      Parameters:
      format - The format of the changelog
      projectDirFile - The project directory File object
      changelogFilePath - The path to the changelog
      changelogFileConfig - Changelog file argument config
      Returns:
      boolean True if copied and false if not
      Throws:
      CommandExecutionException
    • copyExampleFlowFiles

      public static void copyExampleFlowFiles(String format, File projectDirFile) throws CommandExecutionException
      Copy the example flow files of the format specified to the project directory if they do not exist
      Parameters:
      format - The format of the changelog
      projectDirFile - The project directory File object
      Throws:
      CommandExecutionException - if we do not recognize the format, or we cannot create the files
    • copyChecksPackageFile

      public static void copyChecksPackageFile(String format, File projectDirFile) throws CommandExecutionException
      Copy the example flow files of the format specified to the project directory if they do not exist
      Parameters:
      format - The format of the changelog
      projectDirFile - The project directory File object
      Throws:
      CommandExecutionException - if we do not recognize the format, or we cannot create the files
    • wasH2Used

      public static boolean wasH2Used(ConfiguredValue<String> urlConfig, ConfiguredValue<String> usernameConfig, ConfiguredValue<String> passwordConfig)
      Determine if H2 was used.
    • removeDotsFromPath

      public static String removeDotsFromPath(String path)
    • determineFormatType

      public static String determineFormatType(String changelogFilePath, String defaultFormat)
      Given a path to a changelog file, determine the format based on the extension. If the format is unrecognized then return null. If there is no extension then return the default format.
      Parameters:
      changelogFilePath - The path to the changelog file
      defaultFormat - The default format
      Returns:
      String
    • getExtension

      public static String getExtension(String changelogFilePath)
      Return any extension, i.e. the part of the path after the last '.' character
      Parameters:
      changelogFilePath - The path to the changelog file to check
      Returns:
      String
    • findChangeLogsInProjectDir

      public static File[] findChangeLogsInProjectDir(File projectDirFile)
      Return true if a file with a name matching *changelog* is found in the project directory
      Parameters:
      projectDirFile - The File object for the project directory
      Returns:
      File[] The list of changelog files
    • hasRecognizedExtension

      public static boolean hasRecognizedExtension(File file)
      Check a file against the recognized extensions
      Parameters:
      file - The File object to check
      Returns:
      boolean True if recognized extension false if not
    • calcBackupFile

      public static File calcBackupFile(File defaultsFile)