use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class AndroidScanner method scanForClasses.
public Class<?>[] scanForClasses(Location location, Class<?> implementedInterface) throws Exception {
String pkg = location.getPath().replace("/", ".");
List<Class> classes = new ArrayList<Class>();
DexFile dex = new DexFile(context.getApplicationInfo().sourceDir);
Enumeration<String> entries = dex.entries();
while (entries.hasMoreElements()) {
String className = entries.nextElement();
if (className.startsWith(pkg)) {
Class<?> clazz = classLoader.loadClass(className);
if (Modifier.isAbstract(clazz.getModifiers())) {
LOG.debug("Skipping abstract class: " + className);
continue;
}
if (!implementedInterface.isAssignableFrom(clazz)) {
continue;
}
try {
ClassUtils.instantiate(className, classLoader);
} catch (Exception e) {
throw new FlywayException("Unable to instantiate class: " + className);
}
classes.add(clazz);
LOG.debug("Found class: " + className);
}
}
return classes.toArray(new Class<?>[classes.size()]);
}
use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class MetaDataTableImpl method createIfNotExists.
/**
* Creates the metatable if it doesn't exist, upgrades it if it does.
*/
private void createIfNotExists() {
int retries = 0;
while (!table.exists()) {
if (retries == 0) {
LOG.info("Creating Metadata table: " + table);
}
try {
String resourceName = "org/flywaydb/core/internal/dbsupport/" + dbSupport.getDbName() + "/createMetaDataTable.sql";
String source = new ClassPathResource(resourceName, getClass().getClassLoader()).loadAsString("UTF-8");
Map<String, String> placeholders = new HashMap<String, String>();
placeholders.put("schema", table.getSchema().getName());
placeholders.put("table", table.getName());
String sourceNoPlaceholders = new PlaceholderReplacer(placeholders, "${", "}").replacePlaceholders(source);
final SqlScript sqlScript = new SqlScript(sourceNoPlaceholders, dbSupport);
sqlScript.execute(jdbcTemplate);
LOG.debug("Metadata table " + table + " created.");
} catch (FlywayException e) {
if (++retries >= 10) {
throw e;
}
try {
LOG.debug("Metadata table creation failed. Retrying in 1 sec ...");
Thread.sleep(1000);
} catch (InterruptedException e1) {
// Ignore
}
}
}
}
use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class PlaceholderReplacer method checkForUnmatchedPlaceholderExpression.
/**
* Check for unmatched placeholder expressions in the input string and throw
* a FlywayException if they do not have corresponding values.
*
* @param input The input string.
* @throws FlywayException An exception listing the unmatched expressions.
*/
private void checkForUnmatchedPlaceholderExpression(String input) {
String regex = Pattern.quote(placeholderPrefix) + "(.+?)" + Pattern.quote(placeholderSuffix);
Matcher matcher = Pattern.compile(regex).matcher(input);
Set<String> unmatchedPlaceHolderExpressions = new TreeSet<String>();
while (matcher.find()) {
unmatchedPlaceHolderExpressions.add(matcher.group());
}
if (!unmatchedPlaceHolderExpressions.isEmpty()) {
throw new FlywayException("No value provided for placeholder expressions: " + StringUtils.collectionToCommaDelimitedString(unmatchedPlaceHolderExpressions) + ". Check your configuration!");
}
}
use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class ClassPathResource method loadAsString.
public String loadAsString(String encoding) {
try {
InputStream inputStream = classLoader.getResourceAsStream(location);
if (inputStream == null) {
throw new FlywayException("Unable to obtain inputstream for resource: " + location);
}
Reader reader = new InputStreamReader(inputStream, Charset.forName(encoding));
return FileCopyUtils.copyToString(reader);
} catch (IOException e) {
throw new FlywayException("Unable to load resource: " + location + " (encoding: " + encoding + ")", e);
}
}
use of org.flywaydb.core.api.FlywayException in project flyway by flyway.
the class ClassPathScanner method scanForClasses.
@Override
public Class<?>[] scanForClasses(Location location, Class<?> implementedInterface) throws Exception {
LOG.debug("Scanning for classes at '" + location + "' (Implementing: '" + implementedInterface.getName() + "')");
List<Class<?>> classes = new ArrayList<Class<?>>();
Set<String> resourceNames = findResourceNames(location, "", ".class");
for (String resourceName : resourceNames) {
String className = toClassName(resourceName);
Class<?> clazz;
try {
clazz = classLoader.loadClass(className);
if (!implementedInterface.isAssignableFrom(clazz)) {
continue;
}
if (Modifier.isAbstract(clazz.getModifiers()) || clazz.isEnum() || clazz.isAnonymousClass()) {
LOG.debug("Skipping non-instantiable class: " + className);
continue;
}
ClassUtils.instantiate(className, classLoader);
} catch (InternalError e) {
LOG.debug("Skipping invalid class: " + className);
continue;
} catch (IncompatibleClassChangeError e) {
LOG.debug("Skipping incompatibly changed class: " + className);
continue;
} catch (NoClassDefFoundError e) {
LOG.debug("Skipping non-loadable class: " + className);
continue;
} catch (Exception e) {
throw new FlywayException("Unable to instantiate class: " + className, e);
}
classes.add(clazz);
LOG.debug("Found class: " + className);
}
return classes.toArray(new Class<?>[classes.size()]);
}
Aggregations