Search in sources :

Example 16 with CommandScope

use of liquibase.command.CommandScope 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 17 with CommandScope

use of liquibase.command.CommandScope 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)

Example 18 with CommandScope

use of liquibase.command.CommandScope in project liquibase by liquibase.

the class LiquibaseRollbackOneUpdateSQL method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    // 
    // Check the Pro license
    // 
    boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
    if (!hasProLicense) {
        throw new LiquibaseException("The 'rollbackOneUpdateSQL' command requires a valid Liquibase Pro license. Get a free Pro license key at https://liquibase.com/protrial and add liquibase.pro.licenseKey=<yourKey> into your defaults file or use --pro-license-key=<yourKey> before your command in the CLI.");
    }
    Database database = liquibase.getDatabase();
    CommandScope liquibaseCommand = new CommandScope("internalRollbackOneUpdateSQL");
    Map<String, Object> argsMap = getCommandArgsObjectMap(liquibase);
    Writer outputWriter = null;
    try {
        outputWriter = createOutputWriter();
        argsMap.put("outputWriter", outputWriter);
    } catch (IOException ioe) {
        throw new LiquibaseException("Error executing rollbackOneChangeSetSQL.  Unable to create output writer.", ioe);
    }
    ChangeLogParameters clp = new ChangeLogParameters(database);
    argsMap.put("changeLogParameters", clp);
    if (force != null && !Boolean.parseBoolean(force)) {
        throw new LiquibaseException("Invalid value for --force.  You must specify 'liquibase.force=true' to use rollbackOneUpdateSQL.");
    }
    argsMap.put("force", Boolean.TRUE);
    argsMap.put("liquibase", liquibase);
    for (Map.Entry<String, Object> entry : argsMap.entrySet()) {
        liquibaseCommand.addArgumentValue(entry.getKey(), entry.getValue());
    }
    liquibaseCommand.execute();
}
Also used : ChangeLogParameters(liquibase.changelog.ChangeLogParameters) Database(liquibase.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) CommandScope(liquibase.command.CommandScope) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with CommandScope

use of liquibase.command.CommandScope in project liquibase by liquibase.

the class LiquibaseHistoryMojo method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    CommandScope historyCommand = new CommandScope(InternalHistoryCommandStep.COMMAND_NAME);
    historyCommand.addArgumentValue(InternalHistoryCommandStep.DATABASE_ARG, getLiquibase().getDatabase());
    historyCommand.execute();
}
Also used : CommandScope(liquibase.command.CommandScope)

Aggregations

CommandScope (liquibase.command.CommandScope)19 LiquibaseException (liquibase.exception.LiquibaseException)6 Database (liquibase.database.Database)5 CommandResult (liquibase.command.CommandResult)4 CompareControl (liquibase.diff.compare.CompareControl)4 CommandExecutionException (liquibase.exception.CommandExecutionException)4 ChangeLogParameters (liquibase.changelog.ChangeLogParameters)2 CommandResults (liquibase.command.CommandResults)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 SQLException (java.sql.SQLException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 UUID (java.util.UUID)1 JarFile (java.util.jar.JarFile)1