Search in sources :

Example 6 with ResourceAccessor

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

the class AbstractLiquibaseMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().info(MavenUtils.LOG_SEPARATOR);
    if (server != null) {
        AuthenticationInfo info = wagonManager.getAuthenticationInfo(server);
        if (info != null) {
            username = info.getUserName();
            password = info.getPassword();
        }
    }
    processSystemProperties();
    LiquibaseConfiguration liquibaseConfiguration = LiquibaseConfiguration.getInstance();
    if (!liquibaseConfiguration.getConfiguration(GlobalConfiguration.class).getShouldRun()) {
        getLog().info("Liquibase did not run because " + liquibaseConfiguration.describeValueLookupLogic(GlobalConfiguration.class, GlobalConfiguration.SHOULD_RUN) + " was set to false");
        return;
    }
    if (skip) {
        getLog().warn("Liquibase skipped due to maven configuration");
        return;
    }
    ClassLoader artifactClassLoader = getMavenArtifactClassLoader();
    ResourceAccessor fileOpener = getFileOpener(artifactClassLoader);
    configureFieldsAndValues(fileOpener);
    LogFactory.getInstance().setDefaultLoggingLevel(logging);
    // Displays the settings for the Mojo depending of verbosity mode.
    displayMojoSettings();
    // Check that all the parameters that must be specified have been by the user.
    checkRequiredParametersAreSpecified();
    Database database = null;
    try {
        String dbPassword = emptyPassword || password == null ? "" : password;
        String driverPropsFile = (driverPropertiesFile == null) ? null : driverPropertiesFile.getAbsolutePath();
        database = CommandLineUtils.createDatabaseObject(artifactClassLoader, url, username, dbPassword, driver, defaultCatalogName, defaultSchemaName, outputDefaultCatalog, outputDefaultSchema, databaseClass, driverPropsFile, propertyProviderClass, changelogCatalogName, changelogSchemaName, databaseChangeLogTableName, databaseChangeLogLockTableName);
        liquibase = createLiquibase(fileOpener, database);
        getLog().debug("expressionVars = " + String.valueOf(expressionVars));
        if (expressionVars != null) {
            for (Map.Entry<Object, Object> var : expressionVars.entrySet()) {
                this.liquibase.setChangeLogParameter(var.getKey().toString(), var.getValue());
            }
        }
        getLog().debug("expressionVariables = " + String.valueOf(expressionVariables));
        if (expressionVariables != null) {
            for (Map.Entry var : (Set<Map.Entry>) expressionVariables.entrySet()) {
                if (var.getValue() != null) {
                    this.liquibase.setChangeLogParameter(var.getKey().toString(), var.getValue());
                }
            }
        }
        if (clearCheckSums) {
            getLog().info("Clearing the Liquibase Checksums on the database");
            liquibase.clearCheckSums();
        }
        getLog().info("Executing on Database: " + url);
        if (isPromptOnNonLocalDatabase()) {
            if (!liquibase.isSafeToRunUpdate()) {
                if (UIFactory.getInstance().getFacade().promptForNonLocalDatabase(liquibase.getDatabase())) {
                    throw new LiquibaseException("User decided not to run against non-local database");
                }
            }
        }
        performLiquibaseTask(liquibase);
    } catch (LiquibaseException e) {
        cleanup(database);
        throw new MojoExecutionException("Error setting up or running Liquibase: " + e.getMessage(), e);
    }
    cleanup(database);
    getLog().info(MavenUtils.LOG_SEPARATOR);
    getLog().info("");
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) GlobalConfiguration(liquibase.configuration.GlobalConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) Database(liquibase.database.Database) LiquibaseConfiguration(liquibase.configuration.LiquibaseConfiguration) URLClassLoader(java.net.URLClassLoader) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LiquibaseException(liquibase.exception.LiquibaseException)

Example 7 with ResourceAccessor

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

the class Migrator method migrate.

/**
     * <p>migrate</p>
     *
     * @param migration a {@link org.opennms.core.schema.Migration} object.
     * @throws org.opennms.core.schema.MigrationException if any.
     */
public void migrate(final Migration migration) throws MigrationException {
    Connection connection = null;
    DatabaseConnection dbConnection = null;
    try {
        connection = m_dataSource.getConnection();
        dbConnection = new JdbcConnection(connection);
        ResourceAccessor accessor = migration.getAccessor();
        if (accessor == null)
            accessor = new SpringResourceAccessor();
        final Liquibase liquibase = new Liquibase(migration.getChangeLog(), accessor, dbConnection);
        liquibase.setChangeLogParameter("install.database.admin.user", migration.getAdminUser());
        liquibase.setChangeLogParameter("install.database.admin.password", migration.getAdminPassword());
        liquibase.setChangeLogParameter("install.database.user", migration.getDatabaseUser());
        liquibase.getDatabase().setDefaultSchemaName(migration.getSchemaName());
        final String contexts = System.getProperty("opennms.contexts", "production");
        liquibase.update(contexts);
    } catch (final Throwable e) {
        throw new MigrationException("unable to migrate the database", e);
    } finally {
        cleanUpDatabase(connection, dbConnection, null, null);
    }
}
Also used : Liquibase(liquibase.Liquibase) ResourceAccessor(liquibase.resource.ResourceAccessor) Connection(java.sql.Connection) DatabaseConnection(liquibase.database.DatabaseConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) DatabaseConnection(liquibase.database.DatabaseConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection)

Example 8 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)

Example 9 with ResourceAccessor

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

the class AbstractLiquibaseChangeLogMojo method getFileOpener.

@Override
protected ResourceAccessor getFileOpener(ClassLoader cl) {
    ResourceAccessor mFO = new MavenResourceAccessor(cl);
    ResourceAccessor fsFO = new FileSystemResourceAccessor(project.getBasedir().getAbsolutePath());
    return new CompositeResourceAccessor(mFO, fsFO);
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor)

Example 10 with ResourceAccessor

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

the class AbstractLiquibaseMojo method getFileOpener.

protected ResourceAccessor getFileOpener(ClassLoader cl) {
    ResourceAccessor mFO = new MavenResourceAccessor(cl);
    ResourceAccessor fsFO = new FileSystemResourceAccessor(project.getBasedir().getAbsolutePath());
    return new CompositeResourceAccessor(mFO, fsFO);
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor)

Aggregations

ResourceAccessor (liquibase.resource.ResourceAccessor)12 CompositeResourceAccessor (liquibase.resource.CompositeResourceAccessor)7 FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)7 Database (liquibase.database.Database)4 LiquibaseException (liquibase.exception.LiquibaseException)4 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)4 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)4 Liquibase (liquibase.Liquibase)3 File (java.io.File)2 Connection (java.sql.Connection)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 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1