/** Tests dynamically adding a jar file to the classpath. */
  @Test
  public void addJarToClasspath() throws Exception {
    assertFalse(
        new ClassPathResource("db/migration/V1__Initial_structure.sql.sql", getClassLoader())
            .exists());
    assertFalse(
        ClassUtils.isPresent("org.flywaydb.sample.migration.V1_2__Another_user", getClassLoader()));

    String jar = new ClassPathResource("flyway-sample.jar", getClassLoader()).getLocationOnDisk();
    assertTrue(new File(jar).isFile());
    Main.addJarOrDirectoryToClasspath(jar);

    assertTrue(
        new ClassPathResource("db/migration/V1__Initial_structure.sql", getClassLoader()).exists());
    assertTrue(
        ClassUtils.isPresent("org.flywaydb.sample.migration.V1_2__Another_user", getClassLoader()));

    Resource[] resources =
        new ClassPathScanner(getClassLoader())
            .scanForResources(new Location("classpath:db/migration"), "V1__", ".sql");
    assertEquals("db/migration/V1__Initial_structure.sql", resources[0].getLocation());

    Class<?>[] classes =
        new ClassPathScanner(getClassLoader())
            .scanForClasses(
                new Location("classpath:org/flywaydb/sample/migration"), SpringJdbcMigration.class);
    assertEquals("org.flywaydb.sample.migration.V1_2__Another_user", classes[0].getName());
  }
示例#2
0
 /** @return The installation directory of the Flyway Command-line tool. */
 @SuppressWarnings("ConstantConditions")
 private static String getInstallationDir() {
   final String path = ClassUtils.getLocationOnDisk(Migrator.class);
   return new File(path).getParentFile().getParentFile().getAbsolutePath();
 }