use of org.flywaydb.core.api.resource.LoadableResource in project flyway by flyway.
the class SqlMigrationResolver method addMigrations.
private void addMigrations(List<ResolvedMigration> migrations, String prefix, String[] suffixes, boolean repeatable) {
ResourceNameParser resourceNameParser = new ResourceNameParser(configuration);
for (LoadableResource resource : resourceProvider.getResources(prefix, suffixes)) {
String filename = resource.getFilename();
ResourceName result = resourceNameParser.parse(filename);
if (!result.isValid() || isSqlCallback(result) || !prefix.equals(result.getPrefix())) {
continue;
}
SqlScript sqlScript = sqlScriptFactory.createSqlScript(resource, configuration.isMixed(), resourceProvider);
List<LoadableResource> resources = new ArrayList<>();
resources.add(resource);
Integer checksum = getChecksumForLoadableResource(repeatable, resources);
Integer equivalentChecksum = getEquivalentChecksumForLoadableResource(repeatable, resources);
migrations.add(new ResolvedMigrationImpl(result.getVersion(), result.getDescription(), resource.getRelativePath(), checksum, equivalentChecksum, MigrationType.SQL, resource.getAbsolutePathOnDisk(), new SqlMigrationExecutor(sqlScriptExecutorFactory, sqlScript, false, false)) {
@Override
public void validate() {
}
});
}
}
use of org.flywaydb.core.api.resource.LoadableResource in project flyway by flyway.
the class ClasspathClassScanner method scanForType.
public List<String> scanForType(String location, Class<?> classType, boolean errorOnNotFound) {
ClassPathScanner<?> s = new ClassPathScanner<>(classType, classLoader, Charset.defaultCharset(), new Location("classpath:" + location), resourceNameCache, locationScannerCache, errorOnNotFound);
List<String> discoveredTypes = new ArrayList<>();
for (LoadableResource resource : s.scanForResources()) {
if (resource.getAbsolutePath().endsWith(".class")) {
discoveredTypes.add(toClassName(resource.getAbsolutePath()));
}
}
return discoveredTypes;
}
use of org.flywaydb.core.api.resource.LoadableResource in project flyway by flyway.
the class ClassPathScanner method scanForClasses.
@Override
public Collection<Class<? extends I>> scanForClasses() {
LOG.debug("Scanning for classes at " + location);
List<Class<? extends I>> classes = new ArrayList<>();
for (LoadableResource resource : resources) {
if (resource.getAbsolutePath().endsWith(".class")) {
Class<? extends I> clazz;
try {
clazz = ClassUtils.loadClass(implementedInterface, toClassName(resource.getAbsolutePath()), classLoader);
} catch (Throwable e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
LOG.warn("Skipping " + Callback.class + ": " + ClassUtils.formatThrowable(e) + (rootCause == e ? "" : " caused by " + ClassUtils.formatThrowable(rootCause) + " at " + ExceptionUtils.getThrowLocation(rootCause)));
clazz = null;
}
if (clazz != null) {
classes.add(clazz);
}
}
}
return classes;
}
use of org.flywaydb.core.api.resource.LoadableResource 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.
* @return The resources that were found.
*/
public Collection<LoadableResource> scanForResources(Location location) {
String path = location.getRootPath();
LOG.debug("Scanning for filesystem resources at '" + path + "'");
File dir = new File(path);
if (!dir.exists()) {
if (throwOnMissingLocations) {
throw new FlywayException("Failed to find filesystem location:" + path + ".");
}
LOG.error("Skipping filesystem location:" + path + " (not found).");
return Collections.emptyList();
}
if (!dir.canRead()) {
if (throwOnMissingLocations) {
throw new FlywayException("Failed to find filesystem location:" + path + " (not readable).");
}
LOG.error("Skipping filesystem location:" + path + " (not readable).");
return Collections.emptyList();
}
if (!dir.isDirectory()) {
if (throwOnMissingLocations) {
throw new FlywayException("Failed to find filesystem location:" + path + " (not a directory).");
}
LOG.error("Skipping filesystem location:" + path + " (not a directory).");
return Collections.emptyList();
}
Set<LoadableResource> resources = new TreeSet<>();
for (String resourceName : findResourceNamesFromFileSystem(path, new File(path))) {
boolean detectEncodingForThisResource = detectEncoding;
if (location.matchesPath(resourceName)) {
Charset encoding = defaultEncoding;
String encodingBlurb = "";
if (new File(resourceName + ".conf").exists()) {
LoadableResource metadataResource = new FileSystemResource(location, resourceName + ".conf", defaultEncoding, false);
SqlScriptMetadata metadata = SqlScriptMetadata.fromResource(metadataResource, null);
if (metadata.encoding() != null) {
encoding = Charset.forName(metadata.encoding());
detectEncodingForThisResource = false;
encodingBlurb = " (with overriding encoding " + encoding + ")";
}
}
resources.add(new FileSystemResource(location, resourceName, encoding, detectEncodingForThisResource, stream));
LOG.debug("Found filesystem resource: " + resourceName + encodingBlurb);
}
}
return resources;
}
use of org.flywaydb.core.api.resource.LoadableResource in project flyway by flyway.
the class AwsS3Scanner method getLoadableResources.
private Collection<LoadableResource> getLoadableResources(String bucketName, final ListObjectsV2Response listObjectResult) {
List<S3Object> objectSummaries = listObjectResult.contents();
Set<LoadableResource> resources = new TreeSet<>();
for (S3Object objectSummary : objectSummaries) {
LOG.debug("Found Amazon S3 resource: " + bucketName.concat("/").concat(objectSummary.key()));
resources.add(new AwsS3Resource(bucketName, objectSummary, encoding));
}
return resources;
}
Aggregations