Search in sources :

Example 21 with FileSystemResourceAccessor

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

the class AbstractLiquibaseChangeLogMojo method getResourceAccessor.

@Override
protected ResourceAccessor getResourceAccessor(ClassLoader cl) {
    List<ResourceAccessor> resourceAccessors = new ArrayList<ResourceAccessor>();
    resourceAccessors.add(new MavenResourceAccessor(cl));
    resourceAccessors.add(new FileSystemResourceAccessor(project.getBasedir()));
    resourceAccessors.add(new ClassLoaderResourceAccessor(getClass().getClassLoader()));
    if (changeLogDirectory != null) {
        calculateChangeLogDirectoryAbsolutePath();
        resourceAccessors.add(new FileSystemResourceAccessor(new File(changeLogDirectory)));
    }
    return new CompositeResourceAccessor(resourceAccessors);
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ArrayList(java.util.ArrayList) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) File(java.io.File)

Example 22 with FileSystemResourceAccessor

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

the class LiquibaseRegisterChangeLogMojo method getResourceAccessor.

/**
 * Override this method in order to create a ResourceAccessor which only
 * looks for files in root and src/main/resources paths
 *
 * @param   cl
 * @return  ResourceAccessor
 */
@Override
protected ResourceAccessor getResourceAccessor(ClassLoader cl) {
    List<ResourceAccessor> resourceAccessors = new ArrayList<ResourceAccessor>();
    File baseDir = project.getBasedir();
    File sourceDir = new File(baseDir, "src/main/resources");
    resourceAccessors.add(new FileSystemResourceAccessor(baseDir, sourceDir));
    return new CompositeResourceAccessor(resourceAccessors);
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) File(java.io.File)

Example 23 with FileSystemResourceAccessor

use of liquibase.resource.FileSystemResourceAccessor in project collect by openforis.

the class LiquibaseRelationalSchemaCreator method createRelationalSchema.

@Override
public void createRelationalSchema(RelationalSchema schema, Connection targetConn) throws CollectRdbException {
    PrintStream ps = null;
    try {
        LiquidbaseDatabaseSnapshotBuilder snapshotGen = new LiquidbaseDatabaseSnapshotBuilder();
        Database rdb = getDatabaseImplementation(targetConn);
        boolean dbSupportsFKs = rdb instanceof SQLiteDatabase ? false : true;
        DatabaseSnapshot generatedSnapshot = snapshotGen.createSnapshot(schema, dbSupportsFKs);
        String targetSchema = schema.getName();
        rdb.setDefaultSchemaName(targetSchema);
        DatabaseSnapshot emptyDbSnapshot = new DatabaseSnapshot(rdb, targetSchema);
        // Generate change set
        Diff diff = new Diff(generatedSnapshot, emptyDbSnapshot);
        DiffResult diffResult = diff.compare();
        File tmpFile = File.createTempFile("collect-schemagen", ".xml");
        ps = new PrintStream(new FileOutputStream(tmpFile));
        diffResult.setChangeSetAuthor("collect3");
        diffResult.setChangeSetContext("schemagen");
        System.out.println("Writing change log to " + tmpFile.getAbsolutePath());
        diffResult.printChangeLog(ps, rdb);
        ps.flush();
        // Execute change set
        Liquibase liq = new Liquibase(tmpFile.getName(), new FileSystemResourceAccessor(tmpFile.getParent()), rdb);
        liq.update("schemagen");
    } catch (LiquibaseException e) {
        throw new CollectRdbException("Failed to update schema", e);
    } catch (IOException e) {
        throw new CollectRdbException("Failed to create temp db changelog file", e);
    } catch (ParserConfigurationException e) {
        throw new CollectRdbException("Failed to write temp db changelog file", e);
    } finally {
        if (ps != null) {
            ps.close();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) Diff(liquibase.diff.Diff) IOException(java.io.IOException) Liquibase(liquibase.Liquibase) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) CollectRdbException(org.openforis.collect.relational.CollectRdbException) FileOutputStream(java.io.FileOutputStream) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) Database(liquibase.database.Database) DiffResult(liquibase.diff.DiffResult) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) LiquibaseException(liquibase.exception.LiquibaseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) File(java.io.File)

Example 24 with FileSystemResourceAccessor

use of liquibase.resource.FileSystemResourceAccessor in project Singularity by HubSpot.

the class SingularityCuratorTestBase method setup.

@BeforeAll
public synchronized void setup() throws Exception {
    JerseyGuiceUtils.reset();
    singularityTestModule = new SingularityTestModule(useDBTests, customConfigSetup);
    singularityTestModule.getInjector().injectMembers(this);
    singularityTestModule.start();
    leaderCacheCoordinator.activateLeaderCache();
    configuration.setThreadpoolShutdownDelayInSeconds(0);
    if (useDBTests) {
        Handle handle = dbiProvider.get().open();
        handle.getConnection().setAutoCommit(true);
        Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(handle.getConnection()));
        Liquibase liquibase = new Liquibase("singularity_test.sql", new FileSystemResourceAccessor(), database);
        liquibase.update((String) null);
        try {
            database.close();
            handle.close();
        } catch (Throwable t) {
        }
    }
}
Also used : Liquibase(liquibase.Liquibase) Database(liquibase.database.Database) SingularityTestModule(com.hubspot.singularity.scheduler.SingularityTestModule) JdbcConnection(liquibase.database.jvm.JdbcConnection) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) Handle(org.jdbi.v3.core.Handle) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

FileSystemResourceAccessor (liquibase.resource.FileSystemResourceAccessor)24 ResourceAccessor (liquibase.resource.ResourceAccessor)17 CompositeResourceAccessor (liquibase.resource.CompositeResourceAccessor)16 Database (liquibase.database.Database)11 Liquibase (liquibase.Liquibase)10 File (java.io.File)9 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)8 JdbcConnection (liquibase.database.jvm.JdbcConnection)6 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Contexts (liquibase.Contexts)3 ChangeLogParameters (liquibase.changelog.ChangeLogParameters)3 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)3 DiffOutputControl (liquibase.diff.output.DiffOutputControl)3 FileNotFoundException (java.io.FileNotFoundException)2 PrintStream (java.io.PrintStream)2 HashMap (java.util.HashMap)2