Search in sources :

Example 11 with CommandExecutionException

use of liquibase.exception.CommandExecutionException in project liquibase by liquibase.

the class CommandScope method execute.

/**
 * Executes the command in this scope, and returns the results.
 */
public CommandResults execute() throws CommandExecutionException {
    CommandResultsBuilder resultsBuilder = new CommandResultsBuilder(this, outputStream);
    for (ConfigurationValueProvider provider : Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).getProviders()) {
        provider.validate(this);
    }
    for (CommandArgumentDefinition<?> definition : commandDefinition.getArguments().values()) {
        definition.validate(this);
    }
    final List<CommandStep> pipeline = commandDefinition.getPipeline();
    Scope.getCurrentScope().getLog(getClass()).fine("Pipeline for command '" + StringUtil.join(commandDefinition.getName(), " ") + ": " + StringUtil.join(pipeline, " then ", obj -> obj.getClass().getName()));
    for (CommandStep step : pipeline) {
        step.validate(this);
    }
    try {
        for (CommandStep command : pipeline) {
            command.run(resultsBuilder);
        }
    } catch (Exception e) {
        if (e instanceof CommandExecutionException) {
            throw (CommandExecutionException) e;
        } else {
            throw new CommandExecutionException(e);
        }
    } finally {
        try {
            this.outputStream.flush();
        } catch (Exception e) {
            Scope.getCurrentScope().getLog(getClass()).warning("Error flushing command output stream: " + e.getMessage(), e);
        }
    }
    return resultsBuilder.build();
}
Also used : CommandExecutionException(liquibase.exception.CommandExecutionException) CommandExecutionException(liquibase.exception.CommandExecutionException)

Example 12 with CommandExecutionException

use of liquibase.exception.CommandExecutionException in project liquibase by liquibase.

the class CommandLineUtils method doGenerateChangeLog.

public static void doGenerateChangeLog(String changeLogFile, Database originalDatabase, CatalogAndSchema[] schemas, String snapshotTypes, String author, String context, String dataDir, DiffOutputControl diffOutputControl) throws IOException, ParserConfigurationException, LiquibaseException {
    CompareControl.SchemaComparison[] comparisons = new CompareControl.SchemaComparison[schemas.length];
    int i = 0;
    for (CatalogAndSchema schema : schemas) {
        comparisons[i++] = new CompareControl.SchemaComparison(schema, schema);
    }
    CompareControl compareControl = new CompareControl(comparisons, snapshotTypes);
    diffOutputControl.setDataDir(dataDir);
    CommandScope command = new CommandScope("internalGenerateChangeLog");
    command.addArgumentValue(InternalGenerateChangelogCommandStep.REFERENCE_DATABASE_ARG, originalDatabase).addArgumentValue(InternalGenerateChangelogCommandStep.SNAPSHOT_TYPES_ARG, InternalGenerateChangelogCommandStep.parseSnapshotTypes(snapshotTypes)).addArgumentValue(InternalGenerateChangelogCommandStep.COMPARE_CONTROL_ARG, compareControl).addArgumentValue(InternalGenerateChangelogCommandStep.CHANGELOG_FILE_ARG, changeLogFile).addArgumentValue(InternalGenerateChangelogCommandStep.DIFF_OUTPUT_CONTROL_ARG, diffOutputControl).addArgumentValue(InternalGenerateChangelogCommandStep.AUTHOR_ARG, author).addArgumentValue(InternalGenerateChangelogCommandStep.CONTEXT_ARG, context);
    command.setOutput(System.out);
    try {
        command.execute();
    } catch (CommandExecutionException e) {
        throw new LiquibaseException(e);
    }
}
Also used : CompareControl(liquibase.diff.compare.CompareControl) CommandExecutionException(liquibase.exception.CommandExecutionException) LiquibaseException(liquibase.exception.LiquibaseException) CatalogAndSchema(liquibase.CatalogAndSchema) CommandScope(liquibase.command.CommandScope)

Example 13 with CommandExecutionException

use of liquibase.exception.CommandExecutionException in project liquibase by liquibase.

the class CommandLineUtils method doDiffToChangeLog.

public static void doDiffToChangeLog(String changeLogFile, Database referenceDatabase, Database targetDatabase, DiffOutputControl diffOutputControl, ObjectChangeFilter objectChangeFilter, String snapshotTypes, CompareControl.SchemaComparison[] schemaComparisons) throws LiquibaseException, IOException, ParserConfigurationException {
    CommandScope command = new CommandScope("internalDiffChangeLog");
    command.addArgumentValue(InternalDiffChangelogCommandStep.REFERENCE_DATABASE_ARG, referenceDatabase).addArgumentValue(InternalDiffChangelogCommandStep.TARGET_DATABASE_ARG, targetDatabase).addArgumentValue(InternalDiffChangelogCommandStep.SNAPSHOT_TYPES_ARG, InternalDiffChangelogCommandStep.parseSnapshotTypes(snapshotTypes)).addArgumentValue(InternalDiffChangelogCommandStep.COMPARE_CONTROL_ARG, new CompareControl(schemaComparisons, snapshotTypes)).addArgumentValue(InternalDiffChangelogCommandStep.OBJECT_CHANGE_FILTER_ARG, objectChangeFilter).addArgumentValue(InternalDiffChangelogCommandStep.CHANGELOG_FILE_ARG, changeLogFile).addArgumentValue(InternalDiffChangelogCommandStep.DIFF_OUTPUT_CONTROL_ARG, diffOutputControl);
    command.setOutput(System.out);
    try {
        command.execute();
    } catch (CommandExecutionException e) {
        throw new LiquibaseException(e);
    }
}
Also used : CompareControl(liquibase.diff.compare.CompareControl) CommandExecutionException(liquibase.exception.CommandExecutionException) LiquibaseException(liquibase.exception.LiquibaseException) CommandScope(liquibase.command.CommandScope)

Aggregations

CommandExecutionException (liquibase.exception.CommandExecutionException)13 LiquibaseException (liquibase.exception.LiquibaseException)5 CommandScope (liquibase.command.CommandScope)4 HubServiceFactory (liquibase.hub.HubServiceFactory)4 UUID (java.util.UUID)3 HubService (liquibase.hub.HubService)3 HubChangeLog (liquibase.hub.model.HubChangeLog)3 Project (liquibase.hub.model.Project)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 ChangelogRewriter (liquibase.changelog.ChangelogRewriter)2 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)2 CompareControl (liquibase.diff.compare.CompareControl)2 LockException (liquibase.exception.LockException)2 File (java.io.File)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 RandomAccessFile (java.io.RandomAccessFile)1 SQLException (java.sql.SQLException)1 CatalogAndSchema (liquibase.CatalogAndSchema)1