Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Liquibase flow command (DAT-10419) (#2946)
* make base license message public (DAT-10584) (#2941) * make BASE_INVALID_LICENSE_MESSAGE variable private * Added testing framework modifications for flow DAT 10586 (#2981) Co-authored-by: Steven Massaro <steven.massaro.web@gmail.com> * general changes to support flow file validation (DAT-10588) (#2986) add createIfNull(Map) method to CollectionUtil expose separate validate() method in CommandScope add constructor to CommandValidationException(Throwable) * do not allow commands to close the top level output stream * create the UnclosableOutputStream in the setOutput method * Sonar lint cleanup * Moved UnclosableOutputStream class into CommandScope and made it private Do not create if output stream is null DAT-10419 * add liquibase flow and flow.validate goals to maven plugin (DAT-10576) (#3015) Add a flow and flow.validate goal to the maven plugin. Also, add class check before casting in Main.java. * allow passing any arguments to flow commands from maven plugin (DAT-10944) (#3103) Add a flowCommandArguments Map to the mojo definition for flow and flow.validate maven goals. The arguments will be passed to every command that is run in flow. Co-authored-by: Wesley willard <wwillard@austin.rr.com> Co-authored-by: Wesley Willard <wwillard@datical.com> Co-authored-by: suryaaki2 <80348493+suryaaki2@users.noreply.github.com>
- Loading branch information
1 parent
6ad7472
commit 24102a9
Showing
10 changed files
with
235 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...testing/src/main/groovy/liquibase/extension/testing/setup/SetupModifyDbCredentials.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package liquibase.extension.testing.setup | ||
|
||
import liquibase.util.FileUtil | ||
|
||
/** | ||
* | ||
* This class allows modification of a text file to | ||
* replace tokens with the actual database credential | ||
* as specified in the environment | ||
* | ||
*/ | ||
class SetupModifyDbCredentials extends TestSetup { | ||
|
||
private static final String URL = "_URL_" | ||
private static final String USERNAME = "_USERNAME_" | ||
private static final String PASSWORD = "_PASSWORD_" | ||
private final File textFile | ||
|
||
SetupModifyDbCredentials(File textFile) { | ||
this.textFile = textFile | ||
} | ||
|
||
@Override | ||
void setup(TestSetupEnvironment testSetupEnvironment) throws Exception { | ||
String contents = FileUtil.getContents(textFile) | ||
contents = contents.replaceAll(URL, testSetupEnvironment.url) | ||
contents = contents.replaceAll(USERNAME, testSetupEnvironment.username) | ||
contents = contents.replaceAll(PASSWORD, testSetupEnvironment.password) | ||
FileUtil.write(contents, textFile) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...ase-maven-plugin/src/main/java/org/liquibase/maven/plugins/AbstractLiquibaseFlowMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.liquibase.maven.plugins; | ||
|
||
import liquibase.Liquibase; | ||
import liquibase.Scope; | ||
import liquibase.command.CommandScope; | ||
import liquibase.configuration.LiquibaseConfiguration; | ||
import liquibase.exception.CommandExecutionException; | ||
import liquibase.exception.LiquibaseException; | ||
import org.liquibase.maven.property.PropertyElement; | ||
import org.liquibase.maven.provider.FlowCommandArgumentValueProvider; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.util.Map; | ||
|
||
public abstract class AbstractLiquibaseFlowMojo extends AbstractLiquibaseMojo { | ||
/** | ||
* Specifies the <i>flowFile</i> to use. If not specified, the default | ||
* checks will be used and no file will be created. | ||
* | ||
* @parameter property="liquibase.flowFile" | ||
*/ | ||
@PropertyElement | ||
protected String flowFile; | ||
|
||
/** | ||
* @parameter property="liquibase.outputFile" | ||
*/ | ||
@PropertyElement | ||
protected File outputFile; | ||
|
||
/** | ||
* Arbitrary map of parameters that the underlying liquibase command will use. These arguments will be passed | ||
* verbatim to the underlying liquibase command that is being run. | ||
* | ||
* @parameter property="flowCommandArguments" | ||
*/ | ||
@PropertyElement | ||
protected Map<String, Object> flowCommandArguments; | ||
|
||
@Override | ||
public boolean databaseConnectionRequired() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException { | ||
CommandScope liquibaseCommand = new CommandScope(getCommandName()); | ||
liquibaseCommand.addArgumentValue("flowFile", flowFile); | ||
liquibaseCommand.addArgumentValue("flowIntegration", "maven"); | ||
if (flowCommandArguments != null) { | ||
FlowCommandArgumentValueProvider flowCommandArgumentValueProvider = new FlowCommandArgumentValueProvider(flowCommandArguments); | ||
Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).registerProvider(flowCommandArgumentValueProvider); | ||
} | ||
if (outputFile != null) { | ||
try { | ||
liquibaseCommand.setOutput(new FileOutputStream(outputFile)); | ||
} catch (FileNotFoundException e) { | ||
throw new CommandExecutionException(e); | ||
} | ||
} | ||
liquibaseCommand.execute(); | ||
} | ||
|
||
public abstract String[] getCommandName(); | ||
} |
14 changes: 14 additions & 0 deletions
14
liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseFlowMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.liquibase.maven.plugins; | ||
|
||
/** | ||
* Run a series of commands contained in one or more stages, as configured in a liquibase flow-file. | ||
* | ||
* @goal flow | ||
*/ | ||
public class LiquibaseFlowMojo extends AbstractLiquibaseFlowMojo { | ||
|
||
@Override | ||
public String[] getCommandName() { | ||
return new String[]{"flow"}; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ase-maven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseFlowValidateMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.liquibase.maven.plugins; | ||
|
||
/** | ||
* Validate a series of commands contained in one or more stages, as configured in a liquibase flow-file. | ||
* | ||
* @goal flow.validate | ||
*/ | ||
public class LiquibaseFlowValidateMojo extends AbstractLiquibaseFlowMojo{ | ||
@Override | ||
public String[] getCommandName() { | ||
return new String[]{"flow", "validate"}; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...n-plugin/src/main/java/org/liquibase/maven/provider/FlowCommandArgumentValueProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.liquibase.maven.provider; | ||
|
||
import liquibase.configuration.AbstractMapConfigurationValueProvider; | ||
|
||
import java.util.Map; | ||
|
||
public class FlowCommandArgumentValueProvider extends AbstractMapConfigurationValueProvider { | ||
|
||
private final Map<String, Object> args; | ||
|
||
public FlowCommandArgumentValueProvider(Map<String, Object> args) { | ||
this.args = args; | ||
} | ||
|
||
@Override | ||
public int getPrecedence() { | ||
return 250; | ||
} | ||
|
||
@Override | ||
protected Map<?, ?> getMap() { | ||
return args; | ||
} | ||
|
||
@Override | ||
protected String getSourceDescription() { | ||
return "Arguments provided through maven when invoking flow or flow.validate maven goals"; | ||
} | ||
|
||
@Override | ||
protected boolean keyMatches(String wantedKey, String storedKey) { | ||
if (super.keyMatches(wantedKey, storedKey)) { | ||
return true; | ||
} | ||
if (wantedKey.startsWith("liquibase.command.")) { | ||
return super.keyMatches(wantedKey.replaceFirst("^liquibase\\.command\\.", ""), storedKey); | ||
} | ||
|
||
return super.keyMatches(wantedKey.replaceFirst("^liquibase\\.", ""), storedKey); | ||
} | ||
} |