Search in sources :

Example 11 with Resource

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);
}
Also used : FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Resource(org.flywaydb.core.internal.util.scanner.Resource) FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Location(org.flywaydb.core.internal.util.Location) Test(org.testng.annotations.Test)

Example 12 with Resource

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);
}
Also used : FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Resource(org.flywaydb.core.internal.util.scanner.Resource) FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Location(org.flywaydb.core.internal.util.Location) Test(org.testng.annotations.Test)

Example 13 with 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");
}
Also used : FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Resource(org.flywaydb.core.internal.util.scanner.Resource) FileSystemResource(org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource) Location(org.flywaydb.core.internal.util.Location) Test(org.testng.annotations.Test)

Example 14 with Resource

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()]);
}
Also used : TreeSet(java.util.TreeSet) Resource(org.flywaydb.core.internal.util.scanner.Resource) File(java.io.File)

Example 15 with Resource

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);
}
Also used : Resource(org.flywaydb.core.internal.util.scanner.Resource) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) ClassPathScanner(org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) ClassPathResource(org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource) Test(org.junit.Test)

Aggregations

Resource (org.flywaydb.core.internal.util.scanner.Resource)17 Location (org.flywaydb.core.internal.util.Location)11 Test (org.junit.Test)11 DB2MigrationMediumTest (org.flywaydb.core.internal.dbsupport.db2.DB2MigrationMediumTest)7 ClassPathResource (org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource)4 ClassPathScanner (org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner)4 FileSystemResource (org.flywaydb.core.internal.util.scanner.filesystem.FileSystemResource)3 Test (org.testng.annotations.Test)3 File (java.io.File)2 HashSet (java.util.HashSet)2 MigrationVersion (org.flywaydb.core.api.MigrationVersion)2 ResolvedMigrationImpl (org.flywaydb.core.internal.resolver.ResolvedMigrationImpl)2 AfterClass (org.junit.AfterClass)2 BeforeClass (org.junit.BeforeClass)2 Hashing (com.google.common.hash.Hashing)1 ByteSource (com.google.common.io.ByteSource)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1