use of io.quarkus.maven.dependency.ArtifactKey in project camel-quarkus by apache.
the class CamelProcessor method typeConverterRegistry.
/*
* Discover {@link TypeConverterLoader}.
*/
@SuppressWarnings("unchecked")
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelTypeConverterRegistryBuildItem typeConverterRegistry(CamelRecorder recorder, ApplicationArchivesBuildItem applicationArchives, List<CamelTypeConverterLoaderBuildItem> additionalLoaders, CombinedIndexBuildItem combinedIndex, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
IndexView index = combinedIndex.getIndex();
RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder.createTypeConverterRegistry();
//
// This should be simplified by searching for classes implementing TypeConverterLoader but that
// would lead to have org.apache.camel.impl.converter.AnnotationTypeConverterLoader taken into
// account even if it should not.
//
final ClassLoader TCCL = Thread.currentThread().getContextClassLoader();
for (ApplicationArchive archive : applicationArchives.getAllApplicationArchives()) {
for (Path root : archive.getRootDirs()) {
Path path = root.resolve(BaseTypeConverterRegistry.META_INF_SERVICES_TYPE_CONVERTER_LOADER);
if (!Files.isRegularFile(path)) {
continue;
}
try {
Files.readAllLines(path, StandardCharsets.UTF_8).stream().map(String::trim).filter(l -> !l.isEmpty()).filter(l -> !l.startsWith("#")).map(l -> (Class<? extends TypeConverterLoader>) CamelSupport.loadClass(l, TCCL)).forEach(loader -> recorder.addTypeConverterLoader(typeConverterRegistry, loader));
} catch (IOException e) {
throw new RuntimeException("Error discovering TypeConverterLoader", e);
}
}
}
Set<String> internalConverters = new HashSet<>();
// ignore all @converters from org.apache.camel:camel-* dependencies
for (ApplicationArchive archive : applicationArchives.getAllApplicationArchives()) {
ArtifactKey artifactKey = archive.getKey();
if (artifactKey != null && "org.apache.camel".equals(artifactKey.getGroupId()) && artifactKey.getArtifactId().startsWith("camel-")) {
internalConverters.addAll(archive.getIndex().getAnnotations(DotName.createSimple(Converter.class.getName())).stream().filter(a -> a.target().kind() == AnnotationTarget.Kind.CLASS).map(a -> a.target().asClass().name().toString()).collect(Collectors.toSet()));
}
}
Set<Class> convertersClasses = index.getAnnotations(DotName.createSimple(Converter.class.getName())).stream().filter(a -> a.target().kind() == AnnotationTarget.Kind.CLASS && (a.value("generateBulkLoader") == null || !a.value("generateBulkLoader").asBoolean()) && (a.value("generateLoader") == null || !a.value("generateLoader").asBoolean())).map(a -> a.target().asClass().name().toString()).filter(s -> !internalConverters.contains(s)).map(s -> CamelSupport.loadClass(s, TCCL)).collect(Collectors.toSet());
recorder.loadAnnotatedConverters(typeConverterRegistry, convertersClasses);
//
for (CamelTypeConverterLoaderBuildItem item : additionalLoaders) {
recorder.addTypeConverterLoader(typeConverterRegistry, item.getValue());
}
return new CamelTypeConverterRegistryBuildItem(typeConverterRegistry);
}
Aggregations