Package liquibase.command.core.init
Class InitProjectUtil
java.lang.Object
liquibase.command.core.init.InitProjectUtil
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enum class which indicates the outcome of the attempt to create a file. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
calcBackupFile
(File defaultsFile) static void
copyChecksPackageFile
(String format, File projectDirFile) Copy the example flow files of the format specified to the project directory if they do not existcopyExampleChangelog
(String format, File projectDirFile, String changelogFilePath, ConfiguredValue<String> changelogFileConfig) Copy the example changelog file of the format specified to the project directory if necessary Return the File object representing the properties filestatic void
copyExampleFlowFiles
(String format, File projectDirFile) Copy the example flow files of the format specified to the project directory if they do not existstatic File
copyExampleProperties
(String format, String projectDirFile, String targetDefaultsFilename) Copy the example properties file to the project directory Return the File object representing the properties filestatic void
createProjectDirectory
(File projectDirFile) Create the project directory, including any non-existent segmentsstatic String
determineFormatType
(String changelogFilePath, String defaultFormat) Given a path to a changelog file, determine the format based on the extension.static File[]
findChangeLogsInProjectDir
(File projectDirFile) Return true if a file with a name matching *changelog* is found in the project directorystatic String
getExtension
(String changelogFilePath) Return any extension, i.e. the part of the path after the last '.' characterstatic boolean
hasRecognizedExtension
(File file) Check a file against the recognized extensionsstatic String
makeBackup
(Resource resource, Resource backupResource, String contents, String extraMessage, boolean printMessage) Make a backup copy of the checks or flow filestatic void
outputBackedUpDefaultsFileMessage
(String absolutePath) Print out a message to the console and logs indicating that the defaults file was backed up.static String
removeDotsFromPath
(String path) static String
replaceProperty
(String key, String configValue, String contents, boolean newDefaultsFile) Replace the contents where "key=" with the value from the ConfiguredValue 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 static String
replaceProperty
(String key, ConfiguredValue<String> config, String contents, boolean newDefaultsFile) Replace the contents where "key=" with the value from the ConfiguredValue 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) Update the defaults file with any argument valuesstatic void
validateChangelogFilePath
(String changelogFilePath) Make sure the changelog path does not have any path elementsstatic void
validateProjectDirectory
(File projectDirFile) Make sure the input project directory is not a filestatic boolean
wasH2Used
(ConfiguredValue<String> urlConfig, ConfiguredValue<String> usernameConfig, ConfiguredValue<String> passwordConfig) Determine if H2 was used.
-
Field Details
-
SQL
- See Also:
-
JSON
- See Also:
-
YML
- See Also:
-
YAML
- See Also:
-
XML
- See Also:
-
MODIFIED_DEFAULTS_FILE_CONTENTS
- See Also:
-
-
Constructor Details
-
InitProjectUtil
public InitProjectUtil()
-
-
Method Details
-
createProjectDirectory
Create the project directory, including any non-existent segments- Parameters:
projectDirFile
- Directory to create- Throws:
CommandExecutionException
-
validateChangelogFilePath
Make sure the changelog path does not have any path elements- Parameters:
changelogFilePath
- Path to changelog
-
validateProjectDirectory
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 updatingnewDefaultsFile
- True if this is a new file False if notformat
- The current format valuechangelogConfig
- The ConfiguredValue for changelogfileurlConfig
- The ConfiguredValue for urlusernameConfig
- The ConfiguredValue for usernamepasswordConfig
- The ConfiguredValue for passwordchangelogFileCreationResult
- 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 upbackupResource
- The resource to back up tocontents
- The contents of the fileextraMessage
- Extra message text to includeprintMessage
- 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
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 replaceconfig
- The ConfiguredValue of the propertycontents
- The current defaults file contentsnewDefaultsFile
- 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 replaceconfigValue
- The property valuecontents
- The current defaults file contentsnewDefaultsFile
- 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 replaceconfigValue
- The property valuecontents
- The current defaults file contentscommented
- If true, put in the new value with the entire line commented out with a # symbolincludeKeyPrefix
- 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 changelogprojectDirFile
- The project directory File objecttargetDefaultsFilename
- 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 changelogprojectDirFile
- The project directory File objectchangelogFilePath
- The path to the changelogchangelogFileConfig
- 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 changelogprojectDirFile
- 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 changelogprojectDirFile
- 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
-
determineFormatType
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 filedefaultFormat
- The default format- Returns:
- String
-
getExtension
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
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
Check a file against the recognized extensions- Parameters:
file
- The File object to check- Returns:
- boolean True if recognized extension false if not
-
calcBackupFile
-