You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/10/05 15:27:19 UTC

[camel-quarkus] 05/05: chore: simplify bean registration and document contraints

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 092d855d942dcf99ab8edf224cc14181da23b84b
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Sat Oct 5 15:32:35 2019 +0200

    chore: simplify bean registration and document contraints
---
 .../camel/quarkus/core/deployment/BuildProcessor.java   | 17 ++++++-----------
 .../quarkus/core/deployment/CamelBeanBuildItem.java     |  5 ++---
 .../camel/quarkus/core/deployment/CamelSupport.java     |  9 +++------
 3 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
index afda882..1f268a6 100644
--- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/BuildProcessor.java
@@ -17,7 +17,6 @@
 package org.apache.camel.quarkus.core.deployment;
 
 import java.util.List;
-import java.util.Objects;
 
 import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
 import io.quarkus.arc.deployment.BeanContainerBuildItem;
@@ -61,29 +60,25 @@ class BuildProcessor {
         @BuildStep
         CamelRegistryBuildItem registry(
             CamelRecorder recorder,
+            RecorderContext recorderContext,
             ApplicationArchivesBuildItem applicationArchives,
             List<CamelBeanBuildItem> registryItems) {
 
             RuntimeValue<Registry> registry = recorder.createRegistry();
 
-            CamelSupport.services(applicationArchives).filter(
-                si -> registryItems.stream().noneMatch(
-                    c -> Objects.equals(si.name, c.getName()) && c.getType().isAssignableFrom(si.type)
-                )
-            ).forEach(
-                si -> {
-                    LOGGER.debug("Binding camel service {} with type {}", si.name, si.type);
+            CamelSupport.services(applicationArchives).forEach(si -> {
+                    LOGGER.debug("Binding bean with name: {}, type {}", si.name, si.type);
 
                     recorder.bind(
                         registry,
                         si.name,
-                        si.type
+                        recorderContext.classProxy(si.type)
                     );
                 }
             );
 
             for (CamelBeanBuildItem item : registryItems) {
-                LOGGER.debug("Binding item with name: {}, type {}", item.getName(), item.getType());
+                LOGGER.debug("Binding bean with name: {}, type {}", item.getName(), item.getType());
 
                 recorder.bind(
                     registry,
@@ -126,11 +121,11 @@ class BuildProcessor {
         CamelMainBuildItem main(
             CombinedIndexBuildItem combinedIndex,
             CamelMainRecorder recorder,
+            RecorderContext recorderContext,
             CamelContextBuildItem context,
             List<CamelMainListenerBuildItem> listeners,
             List<CamelRoutesBuilderBuildItem> routesBuilders,
             BeanContainerBuildItem beanContainer,
-            RecorderContext recorderContext,
             CamelConfig.BuildTime buildTimeConfig) {
 
             RuntimeValue<CamelMain> main = recorder.createCamelMain(context.getCamelContext(), beanContainer.getValue());
diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java
index 9e38756..84a578a 100644
--- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelBeanBuildItem.java
@@ -22,9 +22,8 @@ import io.quarkus.builder.item.MultiBuildItem;
 
 /**
  * A {@link MultiBuildItem} holding beans to add to {@link org.apache.camel.spi.Registry} during
- * static initialization phase.
- * Can be produced only by methods that do not depend on {@link org.apache.camel.quarkus.core.runtime.CamelRuntime}
- * because otherwise there is a circular dependency.
+ * static initialization phase. Note that the field type should refer to the most specialized
+ * class to avoid the issue described in https://issues.apache.org/jira/browse/CAMEL-13948.
  */
 public final class CamelBeanBuildItem extends MultiBuildItem {
     private final String name;
diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSupport.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSupport.java
index e2f6807..418c442 100644
--- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSupport.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelSupport.java
@@ -102,10 +102,7 @@ public final class CamelSupport {
             for (Map.Entry<Object, Object> entry : props.entrySet()) {
                 String k = entry.getKey().toString();
                 if (k.equals("class")) {
-                    String clazz = entry.getValue().toString();
-                    Class<?> cl = Class.forName(clazz);
-
-                    answer.add(new ServiceInfo(name, cl));
+                    answer.add(new ServiceInfo(name, entry.getValue().toString()));
                 }
             }
         } catch (Exception e) {
@@ -121,9 +118,9 @@ public final class CamelSupport {
      */
     public static class ServiceInfo {
         public final String name;
-        public final Class<?> type;
+        public final String type;
 
-        public ServiceInfo(String name, Class<?> type) {
+        public ServiceInfo(String name, String type) {
             this.name = name;
             this.type = type;
         }