use of org.flywaydb.core.internal.util.scanner.Resource in project che by eclipse.
the class SqlScriptCreatorTest method createsScript.
@Test
public void createsScript() throws Exception {
final Location location = new Location("filesystem:schema");
final Resource resource = new FileSystemResource("schema/5.0.0-M7/v1__init.sql");
final SqlScriptCreator scriptsCreator = new SqlScriptCreator();
final SqlScript script = scriptsCreator.createScript(location, resource);
assertEquals(script.name, "v1__init.sql");
assertEquals(script.location, location);
assertEquals(script.dir, "5.0.0-M7");
assertEquals(script.resource.getLocation(), resource.getLocation());
assertNull(script.vendor);
}
use of org.flywaydb.core.internal.util.scanner.Resource in project che by eclipse.
the class SqlScriptCreatorTest method failsToCreateResourceWhenPathIsInvalid.
@Test(expectedExceptions = FlywayException.class)
public void failsToCreateResourceWhenPathIsInvalid() throws Exception {
final Location location = new Location("filesystem:schema");
final Resource resource = new FileSystemResource("schema/v1__init.sql");
new SqlScriptCreator().createScript(location, resource);
}
use of org.flywaydb.core.internal.util.scanner.Resource in project che by eclipse.
the class SqlScriptCreatorTest method createsVendorScript.
@Test
public void createsVendorScript() throws Exception {
final Location location = new Location("filesystem:schema");
final Resource resource = new FileSystemResource("schema/5.0.0-M7/postgresql/v1__init.sql");
final SqlScriptCreator scriptsCreator = new SqlScriptCreator();
final SqlScript script = scriptsCreator.createScript(location, resource);
assertEquals(script.name, "v1__init.sql");
assertEquals(script.location, location);
assertEquals(script.dir, "5.0.0-M7");
assertEquals(script.resource.getLocation(), resource.getLocation());
assertEquals(script.vendor, "postgresql");
}
use of org.flywaydb.core.internal.util.scanner.Resource in project flyway by flyway.
the class FileSystemScanner method scanForResources.
/**
* Scans the FileSystem for resources under the specified location, starting with the specified prefix and ending with
* the specified suffix.
*
* @param location The location in the filesystem to start searching. Subdirectories are also searched.
* @param prefix The prefix of the resource names to match.
* @param suffix The suffix of the resource names to match.
* @return The resources that were found.
* @throws java.io.IOException when the location could not be scanned.
*/
public Resource[] scanForResources(Location location, String prefix, String suffix) throws IOException {
String path = location.getPath();
LOG.debug("Scanning for filesystem resources at '" + path + "' (Prefix: '" + prefix + "', Suffix: '" + suffix + "')");
File dir = new File(path);
if (!dir.isDirectory() || !dir.canRead()) {
LOG.warn("Unable to resolve location filesystem:" + path);
return new Resource[0];
}
Set<Resource> resources = new TreeSet<Resource>();
Set<String> resourceNames = findResourceNames(path, prefix, suffix);
for (String resourceName : resourceNames) {
resources.add(new FileSystemResource(resourceName));
LOG.debug("Found filesystem resource: " + resourceName);
}
return resources.toArray(new Resource[resources.size()]);
}
use of org.flywaydb.core.internal.util.scanner.Resource in project flyway by flyway.
the class ClassUtilsSmallTest method addJarToClasspathNoDirectoryEntries.
/**
* Tests dynamically adding a jar file to the classpath.
*/
@Test
public void addJarToClasspathNoDirectoryEntries() throws Exception {
assertTrue(new ClassPathResource("db/migration/V1_11__Create_tbl_bob.sql", getClassLoader()).exists());
Resource[] resources = new ClassPathScanner(getClassLoader()).scanForResources(new Location("classpath:db/migration"), "V1_11", ".sql");
Class[] classes = new ClassPathScanner(getClassLoader()).scanForClasses(new Location("classpath:db/migration"), JdbcMigration.class);
assertEquals("db/migration/V1_11__Create_tbl_bob.sql", resources[0].getLocation());
assertEquals(0, classes.length);
}
Aggregations