use of liquibase.command.CommandScope in project liquibase by liquibase.
the class Main method createLiquibaseCommand.
private CommandScope createLiquibaseCommand(Database database, Liquibase liquibase, String commandName, Map<String, Object> argsMap) throws LiquibaseException {
argsMap.put("rollbackScript", rollbackScript);
argsMap.put("changeLogFile", changeLogFile);
argsMap.put("database", database);
argsMap.put("liquibase", liquibase);
if (!commandParams.contains("--help")) {
argsMap.put("changeLog", liquibase.getDatabaseChangeLog());
}
ChangeLogParameters clp = new ChangeLogParameters(database);
for (Map.Entry<String, Object> entry : changeLogParameters.entrySet()) {
clp.set(entry.getKey(), entry.getValue());
}
argsMap.put("changeLogParameters", clp);
if (this.commandParams.contains("--force") || this.commandParams.contains("--force=true")) {
argsMap.put("force", Boolean.TRUE);
}
if (this.commandParams.contains("--help")) {
argsMap.put("help", Boolean.TRUE);
}
if (liquibaseProLicenseKey != null) {
argsMap.put("liquibaseProLicenseKey", liquibaseProLicenseKey);
}
String liquibaseHubApiKey = HubConfiguration.LIQUIBASE_HUB_API_KEY.getCurrentValue();
if (liquibaseHubApiKey != null) {
argsMap.put("liquibaseHubApiKey", liquibaseHubApiKey);
}
CommandScope liquibaseCommand = new CommandScope(commandName);
for (Map.Entry<String, Object> entry : argsMap.entrySet()) {
liquibaseCommand.addArgumentValue(entry.getKey(), entry.getValue());
}
return liquibaseCommand;
}
use of liquibase.command.CommandScope in project liquibase by liquibase.
the class CommandLineUtils method doDiff.
public static void doDiff(Database referenceDatabase, Database targetDatabase, String snapshotTypes, CompareControl.SchemaComparison[] schemaComparisons, ObjectChangeFilter objectChangeFilter, PrintStream output) throws LiquibaseException {
CommandScope diffCommand = createDiffCommand(referenceDatabase, targetDatabase, snapshotTypes, schemaComparisons, objectChangeFilter, output);
Scope.getCurrentScope().getUI().sendMessage("");
Scope.getCurrentScope().getUI().sendMessage(coreBundle.getString("diff.results"));
try {
diffCommand.execute();
} catch (CommandExecutionException e) {
throw new LiquibaseException(e);
}
}
use of liquibase.command.CommandScope in project liquibase by liquibase.
the class HubUpdater method registerChangeLog.
//
// Register the specified changelog
//
private void registerChangeLog(UUID hubProjectId, DatabaseChangeLog changeLog, String changeLogFile) throws LiquibaseException {
String apiKey = StringUtil.trimToNull(HubConfiguration.LIQUIBASE_HUB_API_KEY.getCurrentValue());
if (apiKey == null) {
throw new LiquibaseException("The command 'RegisterChangeLog' " + " failed because the Liquibase API Key has not been set. Learn more at https://hub.liquibase.com");
}
CommandScope registerChangeLogCommand = new CommandScope("registerChangeLog");
registerChangeLogCommand.addArgumentValue(RegisterChangelogCommandStep.CHANGELOG_FILE_ARG, changeLogFile);
try {
if (hubProjectId != null) {
try {
registerChangeLogCommand.addArgumentValue(RegisterChangelogCommandStep.HUB_PROJECT_ID_ARG, hubProjectId);
} catch (IllegalArgumentException e) {
throw new LiquibaseException("The command 'RegisterChangeLog' " + " failed because parameter 'hubProjectId' has invalid value '" + hubProjectId + "'. Learn more at https://hub.liquibase.com");
}
}
} catch (IllegalArgumentException e) {
throw new LiquibaseException("Unexpected hubProjectId format: " + hubProjectId, e);
}
//
// Execute registerChangeLog and reset the changeLog ID
//
CommandResults results = registerChangeLogCommand.execute();
String registerChangeLogId = results.getResult(RegisterChangelogCommandStep.REGISTERED_CHANGELOG_ID);
if (registerChangeLogId != null) {
changeLog.setChangeLogId(registerChangeLogId);
}
}
use of liquibase.command.CommandScope in project liquibase by liquibase.
the class CommandRunner method call.
@Override
public CommandResults call() throws Exception {
List<String> command = new ArrayList<>();
command.add(spec.commandLine().getCommandName());
CommandLine parentCommand = spec.commandLine().getParent();
while (!parentCommand.getCommandName().equals("liquibase")) {
command.add(0, parentCommand.getCommandName());
parentCommand = parentCommand.getParent();
}
final String[] commandName = LiquibaseCommandLine.getCommandNames(spec.commandLine());
for (int i = 0; i < commandName.length; i++) {
commandName[i] = StringUtil.toCamelCase(commandName[i]);
}
final CommandScope commandScope = new CommandScope(commandName);
final File outputFile = LiquibaseCommandLineConfiguration.OUTPUT_FILE.getCurrentValue();
OutputStream outputStream = null;
try {
if (outputFile != null) {
outputStream = new FileOutputStream(outputFile);
commandScope.setOutput(outputStream);
}
return commandScope.execute();
} catch (CommandValidationException cve) {
Throwable cause = cve.getCause();
if (cause instanceof MissingRequiredArgumentException) {
// This is a list of the arguments which the init project command supports. The thinking here is that if the user
// forgets to supply one of these arguments, we're going to remind them about the init project command, which
// can help them figure out what they should be providing here.
final Set<String> initProjectArguments = Stream.of(CommonArgumentNames.CHANGELOG_FILE, CommonArgumentNames.URL, CommonArgumentNames.USERNAME, CommonArgumentNames.PASSWORD).map(CommonArgumentNames::getArgumentName).collect(Collectors.toSet());
throw new CommandValidationException(cve.getMessage() + (initProjectArguments.contains(((MissingRequiredArgumentException) cause).getArgumentName()) ? ". If you need to configure new liquibase project files and arguments, run the 'liquibase init project' command." : ""));
} else {
throw cve;
}
} finally {
if (outputStream != null) {
outputStream.flush();
outputStream.close();
}
}
}
use of liquibase.command.CommandScope in project liquibase by liquibase.
the class DiffCommand method run.
@Override
public CommandResult run() throws Exception {
final CommandScope commandScope = new CommandScope("diffInternal");
commandScope.addArgumentValue(InternalDiffCommandStep.REFERENCE_DATABASE_ARG, this.referenceDatabase);
commandScope.addArgumentValue(InternalDiffCommandStep.TARGET_DATABASE_ARG, this.targetDatabase);
commandScope.addArgumentValue(InternalDiffCommandStep.SNAPSHOT_TYPES_ARG, this.snapshotTypes);
commandScope.addArgumentValue(InternalDiffCommandStep.SNAPSHOT_LISTENER_ARG, this.snapshotListener);
commandScope.addArgumentValue(InternalDiffCommandStep.REFERENCE_SNAPSHOT_CONTROL_ARG, this.referenceSnapshotControl);
commandScope.addArgumentValue(InternalDiffCommandStep.TARGET_SNAPSHOT_CONTROL_ARG, this.targetSnapshotControl);
commandScope.addArgumentValue(InternalDiffCommandStep.OBJECT_CHANGE_FILTER_ARG, this.objectChangeFilter);
commandScope.addArgumentValue(InternalDiffCommandStep.COMPARE_CONTROL_ARG, this.compareControl);
commandScope.setOutput(this.outputStream);
commandScope.execute();
return new CommandResult("OK");
}
Aggregations