All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.liquibase.maven.plugins.AbstractLiquibaseFlowMojo Maven / Gradle / Ivy

There is a newer version: 4.30.0
Show newest version
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.IOException;
import java.nio.file.Files;
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(Files.newOutputStream(outputFile.toPath()));
            } catch (IOException e) {
                throw new CommandExecutionException(e);
            }
        }
        liquibaseCommand.execute();
    }

    public abstract String[] getCommandName();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy