use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.
the class ChangeLogPropertyDefinedPrecondition method check.
@Override
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
ChangeLogParameters changeLogParameters = changeLog.getChangeLogParameters();
if (changeLogParameters == null) {
throw new PreconditionFailedException("No Changelog properties were set", changeLog, this);
}
Object propertyValue = changeLogParameters.getValue(property, changeLog);
if (propertyValue == null) {
throw new PreconditionFailedException("Changelog property '" + property + "' was not set", changeLog, this);
}
if (value != null && !propertyValue.toString().equals(value)) {
throw new PreconditionFailedException("Expected changelog property '" + property + "' to have a value of '" + value + "'. Got '" + propertyValue + "'", changeLog, this);
}
}
use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.
the class ConvertCommand method run.
@Override
protected CommandResult run() throws Exception {
List<ResourceAccessor> openers = new ArrayList<ResourceAccessor>();
openers.add(new FileSystemResourceAccessor());
openers.add(new ClassLoaderResourceAccessor());
if (classpath != null) {
openers.add(new FileSystemResourceAccessor(classpath));
}
ResourceAccessor resourceAccessor = new CompositeResourceAccessor(openers);
ChangeLogParser sourceParser = ChangeLogParserFactory.getInstance().getParser(src, resourceAccessor);
ChangeLogSerializer outSerializer = ChangeLogSerializerFactory.getInstance().getSerializer(out);
DatabaseChangeLog changeLog = sourceParser.parse(src, new ChangeLogParameters(), resourceAccessor);
File outFile = new File(out);
if (!outFile.exists()) {
outFile.getParentFile().mkdirs();
}
FileOutputStream outputStream = new FileOutputStream(outFile);
try {
outSerializer.write(changeLog.getChangeSets(), outputStream);
} finally {
outputStream.flush();
outputStream.close();
}
return new CommandResult("Converted successfully");
}
use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.
the class LiquibaseRollbackOneChangeSetSQL 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 command 'rollbackOneChangeSetSQL' requires a Liquibase Pro License, available at http://www.liquibase.org/download or sales@liquibase.com." + "Add liquibase.pro.licenseKey as a Maven property or add liquibase.pro.licenseKey=<yourKey> into your defaults file.");
}
Database database = liquibase.getDatabase();
CommandScope liquibaseCommand = new CommandScope("internalRollbackOneChangeSetSQL");
Map<String, Object> argsMap = getCommandArgsObjectMap(liquibase);
ChangeLogParameters clp = new ChangeLogParameters(database);
Writer outputWriter = null;
try {
outputWriter = createOutputWriter();
argsMap.put("outputWriter", outputWriter);
} catch (IOException ioe) {
throw new LiquibaseException("Error executing rollbackOneChangeSet. Unable to create output writer.", ioe);
}
argsMap.put("changeLogParameters", clp);
argsMap.put("liquibase", liquibase);
for (Map.Entry<String, Object> entry : argsMap.entrySet()) {
liquibaseCommand.addArgumentValue(entry.getKey(), entry.getValue());
}
liquibaseCommand.execute();
}
use of liquibase.changelog.ChangeLogParameters in project liquibase by liquibase.
the class LiquibaseRollbackOneUpdateMojo method performLiquibaseTask.
@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
//
// Call the base class method so that
// Hub settings will be made
//
super.performLiquibaseTask(liquibase);
//
// Check the Pro license
//
boolean hasProLicense = MavenUtils.checkProLicense(liquibaseProLicenseKey, commandName, getLog());
if (!hasProLicense) {
throw new LiquibaseException("The command 'rollbackOneUpdate' requires a Liquibase Pro License, available at http://www.liquibase.org/download or sales@liquibase.com." + "Add liquibase.pro.licenseKey as a Maven property or add liquibase.pro.licenseKey=<yourKey> into your defaults file.");
}
Database database = liquibase.getDatabase();
CommandScope liquibaseCommand = new CommandScope("internalRollbackOneUpdate");
Map<String, Object> argsMap = getCommandArgsObjectMap(liquibase);
ChangeLogParameters clp = new ChangeLogParameters(database);
argsMap.put("changeLogParameters", clp);
if (force == null || (force != null && !Boolean.parseBoolean(force))) {
throw new LiquibaseException("Invalid value for --force. You must specify 'liquibase.force=true' to use rollbackOneUpdate.");
}
argsMap.put("force", Boolean.TRUE);
argsMap.put("liquibase", liquibase);
argsMap.put("liquibaseProLicenseKey", liquibaseProLicenseKey);
for (Map.Entry<String, Object> entry : argsMap.entrySet()) {
liquibaseCommand.addArgumentValue(entry.getKey(), entry.getValue());
}
liquibaseCommand.execute();
}
use of liquibase.changelog.ChangeLogParameters 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;
}
Aggregations