org.liquibase.maven.plugins.AbstractLiquibaseFlowMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-maven-plugin Show documentation
Show all versions of liquibase-maven-plugin Show documentation
A Maven plugin wraps up some of the functionality of Liquibase
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 flowFile 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 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();
}