|
43 | 43 | import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem; |
44 | 44 | import io.quarkus.deployment.builditem.CombinedIndexBuildItem; |
45 | 45 | import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; |
| 46 | +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; |
| 47 | +import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; |
46 | 48 | import io.quarkus.maven.dependency.ArtifactKey; |
47 | 49 | import io.quarkus.runtime.RuntimeValue; |
48 | 50 | import io.smallrye.common.annotation.Identifier; |
@@ -108,6 +110,8 @@ class CamelProcessor { |
108 | 110 | "org.apache.camel.Predicate"); |
109 | 111 | private static final DotName CONVERTER_TYPE = DotName.createSimple( |
110 | 112 | "org.apache.camel.Converter"); |
| 113 | + private static final DotName TRANSFORMER_TYPE = DotName.createSimple( |
| 114 | + "org.apache.camel.spi.Transformer"); |
111 | 115 |
|
112 | 116 | private static final Set<DotName> UNREMOVABLE_BEANS_TYPES = CamelSupport.setOf( |
113 | 117 | ROUTES_BUILDER_TYPE, |
@@ -431,6 +435,49 @@ CamelComponentNameResolverBuildItem componentNameResolver( |
431 | 435 | return new CamelComponentNameResolverBuildItem(recorder.createComponentNameResolver(componentNames)); |
432 | 436 | } |
433 | 437 |
|
| 438 | + /** |
| 439 | + * Discovers all Transformer implementations for package scanning and reflection. |
| 440 | + * This enables transformer.scan() to work in native mode. |
| 441 | + */ |
| 442 | + @BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) |
| 443 | + void discoverTransformers( |
| 444 | + ApplicationArchivesBuildItem applicationArchives, |
| 445 | + CombinedIndexBuildItem combinedIndex, |
| 446 | + BuildProducer<CamelPackageScanClassBuildItem> packageScanClass, |
| 447 | + BuildProducer<ReflectiveClassBuildItem> reflectiveClass) { |
| 448 | + |
| 449 | + IndexView index = combinedIndex.getIndex(); |
| 450 | + |
| 451 | + Set<String> internalTransformers = new HashSet<>(); |
| 452 | + // Ignore all Transformer implementations from org.apache.camel:camel-* dependencies |
| 453 | + for (ApplicationArchive archive : applicationArchives.getAllApplicationArchives()) { |
| 454 | + ArtifactKey artifactKey = archive.getKey(); |
| 455 | + if (artifactKey != null && "org.apache.camel".equals(artifactKey.getGroupId()) |
| 456 | + && artifactKey.getArtifactId().startsWith("camel-")) { |
| 457 | + internalTransformers.addAll(archive.getIndex().getAllKnownSubclasses(TRANSFORMER_TYPE) |
| 458 | + .stream() |
| 459 | + .map(classInfo -> classInfo.name().toString()) |
| 460 | + .collect(Collectors.toSet())); |
| 461 | + } |
| 462 | + } |
| 463 | + |
| 464 | + Set<String> transformerClasses = index.getAllKnownSubclasses(TRANSFORMER_TYPE) |
| 465 | + .stream() |
| 466 | + .map(classInfo -> classInfo.name().toString()) |
| 467 | + .filter(className -> !internalTransformers.contains(className)) |
| 468 | + .collect(Collectors.toSet()); |
| 469 | + |
| 470 | + if (!transformerClasses.isEmpty()) { |
| 471 | + LOGGER.debug("Found Transformer classes: {}", transformerClasses); |
| 472 | + packageScanClass.produce(new CamelPackageScanClassBuildItem(transformerClasses)); |
| 473 | + |
| 474 | + // Register transformer classes for reflection so they can be instantiated at runtime |
| 475 | + transformerClasses.forEach(className -> reflectiveClass.produce( |
| 476 | + ReflectiveClassBuildItem.builder(className) |
| 477 | + .build())); |
| 478 | + } |
| 479 | + } |
| 480 | + |
434 | 481 | @Record(ExecutionTime.STATIC_INIT) |
435 | 482 | @BuildStep |
436 | 483 | CamelPackageScanClassResolverBuildItem packageScanClassResolver( |
|
0 commit comments