Search in sources :

Example 16 with Location

use of org.flywaydb.core.internal.util.Location in project che by eclipse.

the class ResourcesFinder method findResources.

/**
     * Finds script resources in configured {@link FlywayConfiguration#getLocations()}.
     *
     * @param configuration
     *         flyway configuration to find scripts
     * @return found scripts or an empty list if nothing found
     * @throws IOException
     *         when any io error occurs during scripts look up
     */
Map<Location, List<Resource>> findResources(FlywayConfiguration configuration) throws IOException {
    final String prefix = configuration.getSqlMigrationPrefix();
    final String suffix = configuration.getSqlMigrationSuffix();
    final ClassPathScanner cpScanner = new ClassPathScanner(configuration.getClassLoader());
    final FileSystemScanner fsScanner = new FileSystemScanner();
    final Map<Location, List<Resource>> resources = new HashMap<>();
    for (String rawLocation : configuration.getLocations()) {
        final Location location = new Location(rawLocation);
        if (location.isClassPath()) {
            resources.put(location, newArrayList(cpScanner.scanForResources(location, prefix, suffix)));
        } else {
            resources.put(location, newArrayList(fsScanner.scanForResources(location, prefix, suffix)));
        }
    }
    return resources;
}
Also used : HashMap(java.util.HashMap) ClassPathScanner(org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) FileSystemScanner(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemScanner) Location(org.flywaydb.core.internal.util.Location)

Example 17 with Location

use of org.flywaydb.core.internal.util.Location in project che by eclipse.

the class VersionResolverTest method failsToResolveVersions.

@Test(dataProvider = "invalidScripts", expectedExceptions = FlywayException.class)
public void failsToResolveVersions(String dir, String name) throws Exception {
    final SqlScript script = new SqlScript(new FileSystemResource("sql/" + dir + "/" + name), new Location("filesystem:sql"), dir, null, name);
    resolver.resolve(script, flyway);
}
Also used : FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Location(org.flywaydb.core.internal.util.Location) Test(org.testng.annotations.Test)

Example 18 with Location

use of org.flywaydb.core.internal.util.Location in project che by eclipse.

the class VersionResolverTest method resolvesVersion.

@Test(dataProvider = "validScripts")
public void resolvesVersion(String dir, String name, String expectedVersion) {
    final SqlScript script = new SqlScript(new FileSystemResource("sql/" + dir + "/" + name), new Location("filesystem:sql"), dir, null, name);
    assertEquals(resolver.resolve(script, flyway), MigrationVersion.fromVersion(expectedVersion));
}
Also used : FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Location(org.flywaydb.core.internal.util.Location) Test(org.testng.annotations.Test)

Example 19 with Location

use of org.flywaydb.core.internal.util.Location in project flyway by flyway.

the class MigrationTestCase method assertChecksum.

/**
     * Compares the DB checksum to the classpath checksum of this migration.
     *
     * @param migrationInfo
     *            The migration to check.
     */
protected void assertChecksum(MigrationInfo migrationInfo) {
    SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(dbSupport, new Scanner(Thread.currentThread().getContextClassLoader()), new Location(getBasedir()), PlaceholderReplacer.NO_PLACEHOLDERS, FlywayConfigurationForTests.create());
    List<ResolvedMigration> migrations = sqlMigrationResolver.resolveMigrations();
    for (ResolvedMigration migration : migrations) {
        if (migration.getVersion().toString().equals(migrationInfo.getVersion().toString())) {
            assertEquals("Wrong checksum for " + migrationInfo.getScript(), migration.getChecksum(), migrationInfo.getChecksum());
        }
    }
}
Also used : Scanner(org.flywaydb.core.internal.util.scanner.Scanner) SqlMigrationResolver(org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) Location(org.flywaydb.core.internal.util.Location)

Example 20 with Location

use of org.flywaydb.core.internal.util.Location in project flyway by flyway.

the class SqlMigrationResolverMediumTest method resolveMigrations.

@Test
public void resolveMigrations() throws Exception {
    @SuppressWarnings("ConstantConditions") String path = URLDecoder.decode(getClass().getClassLoader().getResource("migration/subdir").getPath(), "UTF-8");
    SqlMigrationResolver sqlMigrationResolver = new SqlMigrationResolver(null, new Scanner(Thread.currentThread().getContextClassLoader()), new Location("filesystem:" + new File(path).getPath()), PlaceholderReplacer.NO_PLACEHOLDERS, FlywayConfigurationForTests.create());
    Collection<ResolvedMigration> migrations = sqlMigrationResolver.resolveMigrations();
    assertEquals(3, migrations.size());
    List<ResolvedMigration> migrationList = new ArrayList<ResolvedMigration>(migrations);
    assertEquals("1", migrationList.get(0).getVersion().toString());
    assertEquals("1.1", migrationList.get(1).getVersion().toString());
    assertEquals("2.0", migrationList.get(2).getVersion().toString());
    assertEquals("dir1/V1__First.sql", migrationList.get(0).getScript());
    assertEquals("V1_1__Populate_table.sql", migrationList.get(1).getScript());
    assertEquals("dir2/V2_0__Add_foreign_key.sql", migrationList.get(2).getScript());
}
Also used : Scanner(org.flywaydb.core.internal.util.scanner.Scanner) ArrayList(java.util.ArrayList) ResolvedMigration(org.flywaydb.core.api.resolver.ResolvedMigration) File(java.io.File) Location(org.flywaydb.core.internal.util.Location) Test(org.junit.Test)

Aggregations

Location (org.flywaydb.core.internal.util.Location)29 Test (org.junit.Test)20 DB2MigrationMediumTest (org.flywaydb.core.internal.dbsupport.db2.DB2MigrationMediumTest)11 Resource (org.flywaydb.core.internal.util.scanner.Resource)11 ResolvedMigration (org.flywaydb.core.api.resolver.ResolvedMigration)7 FileSystemResource (org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource)6 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)5 Scanner (org.flywaydb.core.internal.util.scanner.Scanner)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 SqlMigrationResolver (org.flywaydb.core.internal.resolver.sql.SqlMigrationResolver)2 ClassPathResource (org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Hashing (com.google.common.hash.Hashing)1 ByteSource (com.google.common.io.ByteSource)1 File (java.io.File)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1