use of org.apache.camel.quarkus.core.deployment.util.PathFilter in project camel-quarkus by apache.
the class CamelProcessor method discoverRoutesBuilderClassNames.
@BuildStep(onlyIf = { CamelConfigFlags.RoutesDiscoveryEnabled.class })
public List<CamelRoutesBuilderClassBuildItem> discoverRoutesBuilderClassNames(CombinedIndexBuildItem combinedIndex, CamelConfig config, List<RoutesBuilderClassExcludeBuildItem> routesBuilderClassExcludes) {
final IndexView index = combinedIndex.getIndex();
Set<ClassInfo> allKnownImplementors = new HashSet<>();
allKnownImplementors.addAll(index.getAllKnownImplementors(ROUTES_BUILDER_TYPE));
allKnownImplementors.addAll(index.getAllKnownSubclasses(ROUTE_BUILDER_TYPE));
allKnownImplementors.addAll(index.getAllKnownSubclasses(ADVICE_WITH_ROUTE_BUILDER_TYPE));
final Predicate<DotName> pathFilter = new PathFilter.Builder().exclude(routesBuilderClassExcludes.stream().map(RoutesBuilderClassExcludeBuildItem::getPattern).collect(Collectors.toList())).exclude(config.routesDiscovery.excludePatterns).include(config.routesDiscovery.includePatterns).build().asDotNamePredicate();
return allKnownImplementors.stream().filter(ci -> ((ci.flags() & (Modifier.ABSTRACT | Modifier.PUBLIC)) == Modifier.PUBLIC)).map(ClassInfo::name).filter(pathFilter).map(CamelRoutesBuilderClassBuildItem::new).collect(Collectors.toList());
}
use of org.apache.camel.quarkus.core.deployment.util.PathFilter in project camel-quarkus by apache.
the class CamelRegistryProcessor method bindBeansToRegistry.
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
public void bindBeansToRegistry(CamelRecorder recorder, CamelConfig camelConfig, ApplicationArchivesBuildItem applicationArchives, ContainerBeansBuildItem containerBeans, CamelRegistryBuildItem registry, // CamelContextBuildItem placeholder ensures this build step runs after the CamelContext is created
CamelContextBuildItem camelContextBuildItem, List<CamelBeanBuildItem> registryItems, List<CamelServiceFilterBuildItem> serviceFilters, List<CamelServicePatternBuildItem> servicePatterns) {
final ClassLoader TCCL = Thread.currentThread().getContextClassLoader();
final PathFilter pathFilter = servicePatterns.stream().filter(patterns -> patterns.getDestination() == CamelServiceDestination.REGISTRY).collect(PathFilter.Builder::new, (builder, patterns) -> builder.patterns(patterns.isInclude(), patterns.getPatterns()), PathFilter.Builder::combine).include(camelConfig.service.registry.includePatterns).exclude(camelConfig.service.registry.excludePatterns).build();
CamelSupport.services(applicationArchives, pathFilter).filter(si -> !containerBeans.getBeans().contains(si)).filter(si -> {
//
// by default all the service found in META-INF/service/org/apache/camel are
// bound to the registry but some of the services are then replaced or set
// to the camel context directly by extension so it does not make sense to
// instantiate them in this phase.
//
boolean blacklisted = serviceFilters.stream().anyMatch(filter -> filter.getPredicate().test(si));
if (blacklisted) {
LOGGER.debug("Ignore service: {}", si);
}
return !blacklisted;
}).forEach(si -> {
LOGGER.debug("Binding bean with name: {}, type {}", si.name, si.type);
recorder.bind(registry.getRegistry(), si.name, CamelSupport.loadClass(si.type, TCCL));
});
registryItems.stream().filter(item -> !containerBeans.getBeans().contains(item)).forEach(item -> {
LOGGER.debug("Binding bean with name: {}, type {}", item.getName(), item.getType());
if (item.getValue().isPresent()) {
recorder.bind(registry.getRegistry(), item.getName(), CamelSupport.loadClass(item.getType(), TCCL), item.getValue().get());
} else {
// the instance of the service will be instantiated by the recorder, this avoid
// creating a recorder for trivial services.
recorder.bind(registry.getRegistry(), item.getName(), CamelSupport.loadClass(item.getType(), TCCL));
}
});
}
use of org.apache.camel.quarkus.core.deployment.util.PathFilter in project camel-quarkus by apache.
the class CamelNativeImageProcessor method reflection.
@BuildStep
void reflection(CamelConfig config, ApplicationArchivesBuildItem archives, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
final ReflectionConfig reflectionConfig = config.native_.reflection;
if (!reflectionConfig.includePatterns.isPresent()) {
LOGGER.debug("No classes registered for reflection via quarkus.camel.native.reflection.include-patterns");
return;
}
LOGGER.debug("Scanning resources for native inclusion from include-patterns {}", reflectionConfig.includePatterns.get());
final PathFilter.Builder builder = new PathFilter.Builder();
reflectionConfig.includePatterns.map(Collection::stream).orElseGet(Stream::empty).map(className -> className.replace('.', '/')).forEach(builder::include);
reflectionConfig.excludePatterns.map(Collection::stream).orElseGet(Stream::empty).map(className -> className.replace('.', '/')).forEach(builder::exclude);
final PathFilter pathFilter = builder.build();
Stream<Path> archiveRootDirs = archives.getAllApplicationArchives().stream().peek(archive -> LOGGER.debug("Scanning resources for native inclusion from archive at {}", archive.getResolvedPaths())).flatMap(archive -> archive.getRootDirectories().stream());
String[] selectedClassNames = pathFilter.scanClassNames(archiveRootDirs);
if (selectedClassNames.length > 0) {
reflectiveClasses.produce(new ReflectiveClassBuildItem(true, true, selectedClassNames));
}
}
use of org.apache.camel.quarkus.core.deployment.util.PathFilter in project camel-quarkus by apache.
the class CamelNativeImageProcessor method camelRuntimeCatalog.
/*
* Add camel catalog files to the native image.
*/
@BuildStep(onlyIf = CamelConfigFlags.RuntimeCatalogEnabled.class)
List<NativeImageResourceBuildItem> camelRuntimeCatalog(CamelConfig config, ApplicationArchivesBuildItem archives, List<CamelServicePatternBuildItem> servicePatterns) {
List<NativeImageResourceBuildItem> resources = new ArrayList<>();
final PathFilter pathFilter = servicePatterns.stream().collect(PathFilter.Builder::new, (builder, patterns) -> builder.patterns(patterns.isInclude(), patterns.getPatterns()), PathFilter.Builder::combine).build();
CamelSupport.services(archives, pathFilter).filter(service -> service.name != null && service.type != null && service.path != null).forEach(service -> {
String packageName = getPackageName(service.type);
String jsonPath = String.format("%s/%s.json", packageName.replace('.', '/'), service.name);
if (config.runtimeCatalog.components && service.path.startsWith(DefaultComponentResolver.RESOURCE_PATH)) {
resources.add(new NativeImageResourceBuildItem(jsonPath));
}
if (config.runtimeCatalog.dataformats && service.path.startsWith(DefaultDataFormatResolver.DATAFORMAT_RESOURCE_PATH)) {
resources.add(new NativeImageResourceBuildItem(jsonPath));
}
if (config.runtimeCatalog.languages && service.path.startsWith(DefaultLanguageResolver.LANGUAGE_RESOURCE_PATH)) {
resources.add(new NativeImageResourceBuildItem(jsonPath));
}
});
if (config.runtimeCatalog.models) {
for (ApplicationArchive archive : archives.getAllApplicationArchives()) {
for (Path root : archive.getRootDirectories()) {
final Path resourcePath = root.resolve(CamelContextHelper.MODEL_DOCUMENTATION_PREFIX);
if (!Files.isDirectory(resourcePath)) {
continue;
}
List<String> items = CamelSupport.safeWalk(resourcePath).filter(Files::isRegularFile).map(root::relativize).map(Path::toString).collect(Collectors.toList());
LOGGER.debug("Register catalog json: {}", items);
resources.add(new NativeImageResourceBuildItem(items));
}
}
}
return resources;
}
use of org.apache.camel.quarkus.core.deployment.util.PathFilter in project camel-quarkus by apache.
the class CamelProcessor method camelServices.
@BuildStep
void camelServices(ApplicationArchivesBuildItem applicationArchives, List<CamelServicePatternBuildItem> servicePatterns, BuildProducer<CamelServiceBuildItem> camelServices) {
final PathFilter pathFilter = servicePatterns.stream().filter(patterns -> patterns.getDestination() == CamelServiceDestination.DISCOVERY).collect(PathFilter.Builder::new, (builder, patterns) -> builder.patterns(patterns.isInclude(), patterns.getPatterns()), PathFilter.Builder::combine).build();
CamelSupport.services(applicationArchives, pathFilter).forEach(camelServices::produce);
}
Aggregations