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;
}
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);
}
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));
}
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());
}
}
}
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());
}
Aggregations