Search in sources :

Example 11 with ResourceAccessor

use of liquibase.resource.ResourceAccessor in project liquibase by liquibase.

the class LiquibaseDatabaseDiff method performLiquibaseTask.

@Override
protected void performLiquibaseTask(Liquibase liquibase) throws LiquibaseException {
    ClassLoader cl = null;
    ResourceAccessor fileOpener;
    try {
        cl = getClassLoaderIncludingProjectClasspath();
        Thread.currentThread().setContextClassLoader(cl);
        ClassLoader artifactClassLoader = getMavenArtifactClassLoader();
        fileOpener = getFileOpener(artifactClassLoader);
    } catch (MojoExecutionException e) {
        throw new LiquibaseException("Could not create the class loader, " + e, e);
    }
    Database db = liquibase.getDatabase();
    Database referenceDatabase = CommandLineUtils.createDatabaseObject(fileOpener, referenceUrl, referenceUsername, referencePassword, referenceDriver, referenceDefaultCatalogName, referenceDefaultSchemaName, outputDefaultCatalog, outputDefaultSchema, null, null, propertyProviderClass, null, null, databaseChangeLogTableName, databaseChangeLogLockTableName);
    getLog().info("Performing Diff on database " + db.toString());
    if (diffChangeLogFile != null) {
        try {
            DiffOutputControl diffOutputControl = new DiffOutputControl(diffIncludeCatalog, diffIncludeSchema, diffIncludeTablespace, null).addIncludedSchema(new CatalogAndSchema(referenceDefaultCatalogName, referenceDefaultSchemaName));
            if (diffExcludeObjects != null && diffIncludeObjects != null) {
                throw new UnexpectedLiquibaseException("Cannot specify both excludeObjects and includeObjects");
            }
            if (diffExcludeObjects != null) {
                diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.EXCLUDE, diffExcludeObjects));
            }
            if (diffIncludeObjects != null) {
                diffOutputControl.setObjectChangeFilter(new StandardObjectChangeFilter(StandardObjectChangeFilter.FilterType.INCLUDE, diffIncludeObjects));
            }
            CommandLineUtils.doDiffToChangeLog(diffChangeLogFile, referenceDatabase, db, diffOutputControl, StringUtils.trimToNull(diffTypes));
            getLog().info("Differences written to Change Log File, " + diffChangeLogFile);
        } catch (IOException e) {
            throw new LiquibaseException(e);
        } catch (ParserConfigurationException e) {
            throw new LiquibaseException(e);
        }
    } else {
        CommandLineUtils.doDiff(referenceDatabase, db, StringUtils.trimToNull(diffTypes));
    }
}
Also used : ResourceAccessor(liquibase.resource.ResourceAccessor) StandardObjectChangeFilter(liquibase.diff.output.StandardObjectChangeFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Database(liquibase.database.Database) DiffOutputControl(liquibase.diff.output.DiffOutputControl) LiquibaseException(liquibase.exception.LiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CatalogAndSchema(liquibase.CatalogAndSchema) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 12 with ResourceAccessor

use of liquibase.resource.ResourceAccessor in project liquibase by liquibase.

the class AbstractLiquibaseMojoTest method loadPropertiesFileIfPresent.

protected void loadPropertiesFileIfPresent(AbstractLiquibaseMojo mojo) throws MojoExecutionException, MojoFailureException {
    File rootDir = new File(getBasedir(), "target/test-classes");
    ResourceAccessor fo = new FileSystemResourceAccessor(rootDir.getAbsolutePath());
    mojo.configureFieldsAndValues(fo);
}
Also used : ResourceAccessor(liquibase.resource.ResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) File(java.io.File)

Example 13 with ResourceAccessor

use of liquibase.resource.ResourceAccessor in project liquibase by liquibase.

the class Liquibase method calculateCheckSum.

public CheckSum calculateCheckSum(final String filename, final String id, final String author) throws LiquibaseException {
    log.info(String.format("Calculating checksum for changeset %s::%s::%s", filename, id, author));
    final ChangeLogParameters changeLogParameters = this.getChangeLogParameters();
    final ResourceAccessor resourceAccessor = this.getResourceAccessor();
    final DatabaseChangeLog changeLog = ChangeLogParserFactory.getInstance().getParser(this.changeLogFile, resourceAccessor).parse(this.changeLogFile, changeLogParameters, resourceAccessor);
    // TODO: validate?
    final ChangeSet changeSet = changeLog.getChangeSet(filename, author, id);
    if (changeSet == null) {
        throw new LiquibaseException(new IllegalArgumentException("No such changeSet: " + filename + "::" + id + "::" + author));
    }
    return changeSet.generateCheckSum();
}
Also used : ResourceAccessor(liquibase.resource.ResourceAccessor) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Aggregations

ResourceAccessor (liquibase.resource.ResourceAccessor)13 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)8 CompositeResourceAccessor (liquibase.resource.CompositeResourceAccessor)7 Database (liquibase.database.Database)5 Liquibase (liquibase.Liquibase)4 LiquibaseException (liquibase.exception.LiquibaseException)4 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)4 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)4 File (java.io.File)2 Connection (java.sql.Connection)2 Contexts (liquibase.Contexts)2 JdbcConnection (liquibase.database.jvm.JdbcConnection)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1