in extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelQuarkusPackageScanResourceResolver.java [68:127]
public Collection<Resource> findResources(String location) throws Exception {
Collection<Resource> resources = super.findResources(location);
// If no matches were found for the location pattern in native mode, try to use the resource scheme filesystem
if (resources.isEmpty() && ImageMode.current().isNativeImage()) {
String scheme = ResourceHelper.getScheme(location);
if (isClassPathPattern(location, scheme)) {
FileSystem fileSystem = getNativeImageResourceFileSystem();
ResourceLoader resourceLoader = PluginHelper.getResourceLoader(getCamelContext());
String root = AntPathMatcher.INSTANCE.determineRootDir(location);
String rootWithoutScheme = scheme != null ? root.substring(scheme.length()) : root;
String subPattern = location.substring(root.length());
Path startPath = fileSystem.getPath(rootWithoutScheme);
if (!Files.exists(startPath)) {
LOG.tracef("Failed to find resources for location: %s as path %s does not exist", location, startPath);
return resources;
}
LOG.tracef("Finding native resources for location: %s, sub pattern %s, under path %s", location, subPattern,
rootWithoutScheme);
// Iterate classpath resources in the native application and try to find matches
Files.walkFileTree(startPath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Path pathToMatch = file.getNameCount() > 1 ? file.subpath(1, file.getNameCount()) : file.getFileName();
LOG.tracef("Checking for native resource match for: %s", pathToMatch);
if (AntPathMatcher.INSTANCE.match(subPattern, pathToMatch.toString())) {
LOG.tracef("Matched native resource: %s with pattern: %s", file, subPattern);
resources.add(resourceLoader.resolveResource(file.toString()));
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
LOG.tracef(exc, "Failed to process resource: %s", file);
return FileVisitResult.CONTINUE;
}
});
// Fallback on matching files explicitly in the resolved directory path
if (resources.isEmpty() && Files.isDirectory(startPath)) {
try (Stream<Path> files = Files.list(startPath)) {
files.map(Path::getFileName)
.map(Path::toString)
.filter(path -> AntPathMatcher.INSTANCE.match(subPattern, path))
.map(path -> startPath.resolve(path).toString())
.peek(path -> LOG.tracef("Matched native resource: %s with pattern: %s", path, subPattern))
.map(resourceLoader::resolveResource)
.forEach(resources::add);
}
}
}
}
return resources;
}