use of org.flywaydb.core.internal.sqlscript.SqlScriptMetadata 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;
}
Aggregations