Search in sources :

Example 1 with ChangeLogParameters

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);
    }
}
Also used : ChangeLogParameters(liquibase.changelog.ChangeLogParameters) PreconditionFailedException(liquibase.exception.PreconditionFailedException)

Example 2 with ChangeLogParameters

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");
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ArrayList(java.util.ArrayList) ChangeLogSerializer(liquibase.serializer.ChangeLogSerializer) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) CommandResult(liquibase.command.CommandResult) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ChangeLogParameters(liquibase.changelog.ChangeLogParameters) ChangeLogParser(liquibase.parser.ChangeLogParser) FileOutputStream(java.io.FileOutputStream) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) File(java.io.File)

Example 3 with ChangeLogParameters

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();
}
Also used : ChangeLogParameters(liquibase.changelog.ChangeLogParameters) Database(liquibase.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ChangeLogParameters

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();
}
Also used : ChangeLogParameters(liquibase.changelog.ChangeLogParameters) Database(liquibase.database.Database) LiquibaseException(liquibase.exception.LiquibaseException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with ChangeLogParameters

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;
}
Also used : ChangeLogParameters(liquibase.changelog.ChangeLogParameters) CommandScope(liquibase.command.CommandScope)

Aggregations

ChangeLogParameters (liquibase.changelog.ChangeLogParameters)19 Database (liquibase.database.Database)7 LiquibaseException (liquibase.exception.LiquibaseException)7 ResourceAccessor (liquibase.resource.ResourceAccessor)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)5 ChangeLogParser (liquibase.parser.ChangeLogParser)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 InputStream (java.io.InputStream)3 ChangeSet (liquibase.changelog.ChangeSet)3 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)3 XMLChangeLogSAXParser (liquibase.parser.core.xml.XMLChangeLogSAXParser)3 CompositeResourceAccessor (liquibase.resource.CompositeResourceAccessor)3 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2