Search in sources :

Example 11 with FileSystemResourceAccessor

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

the class ConvertCommandStep method run.

@Override
public void run(CommandResultsBuilder resultsBuilder) throws Exception {
    CommandScope commandScope = resultsBuilder.getCommandScope();
    String src = commandScope.getArgumentValue(SRC_ARG);
    String out = commandScope.getArgumentValue(OUT_ARG);
    String classpath = commandScope.getArgumentValue(CLASSPATH_ARG);
    List<ResourceAccessor> openers = new ArrayList<>();
    openers.add(new FileSystemResourceAccessor());
    openers.add(new ClassLoaderResourceAccessor());
    if (classpath != null) {
        openers.add(new FileSystemResourceAccessor(new File(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();
    }
    try (FileOutputStream outputStream = new FileOutputStream(outFile)) {
        outSerializer.write(changeLog.getChangeSets(), outputStream);
    }
    Scope.getCurrentScope().getUI().sendMessage("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) 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 12 with FileSystemResourceAccessor

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

the class DataManager method initDatabaseSchema.

private void initDatabaseSchema() throws LiquibaseException {
    if (config.hasKey(Keys.DATABASE_CHANGELOG)) {
        ResourceAccessor resourceAccessor = new FileSystemResourceAccessor(new File("."));
        Database database = DatabaseFactory.getInstance().openDatabase(config.getString(Keys.DATABASE_URL), config.getString(Keys.DATABASE_USER), config.getString(Keys.DATABASE_PASSWORD), config.getString(Keys.DATABASE_DRIVER), null, null, null, resourceAccessor);
        Liquibase liquibase = new Liquibase(config.getString(Keys.DATABASE_CHANGELOG), resourceAccessor, database);
        liquibase.clearCheckSums();
        liquibase.update(new Contexts());
    }
}
Also used : Liquibase(liquibase.Liquibase) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ResourceAccessor(liquibase.resource.ResourceAccessor) Database(liquibase.database.Database) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) File(java.io.File) Contexts(liquibase.Contexts)

Example 13 with FileSystemResourceAccessor

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

the class BaseLiquibaseTask method createResourceAccessor.

/**
     * Creates a suitable ResourceAccessor for use in an Ant task..
     *
     * @param classLoader The ClassLoader to use in the ResourceAccessor. It is preferable that it is an AntClassLoader.
     * @return A ResourceAccessor.
     */
private ResourceAccessor createResourceAccessor(ClassLoader classLoader) {
    FileSystemResourceAccessor fileSystemResourceAccessor = new FileSystemResourceAccessor();
    ClassLoaderResourceAccessor classLoaderResourceAccessor = new ClassLoaderResourceAccessor(classLoader);
    return new CompositeResourceAccessor(fileSystemResourceAccessor, classLoaderResourceAccessor);
}
Also used : CompositeResourceAccessor(liquibase.resource.CompositeResourceAccessor) FileSystemResourceAccessor(liquibase.resource.FileSystemResourceAccessor) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor)

Example 14 with FileSystemResourceAccessor

use of liquibase.resource.FileSystemResourceAccessor 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 15 with FileSystemResourceAccessor

use of liquibase.resource.FileSystemResourceAccessor 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

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