Improve bean discovery filtering
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 37851b5..421ae89 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
@@ -31,8 +31,6 @@
import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.arc.deployment.UnremovableBeanBuildItem.BeanClassNamesExclusion;
-import io.quarkus.arc.processor.BeanInfo;
-import io.quarkus.arc.processor.BeanRegistrar;
import io.quarkus.arc.processor.BuildExtension;
import io.quarkus.deployment.ApplicationArchive;
import io.quarkus.deployment.Capabilities;
@@ -79,6 +77,10 @@
* Build steps related to camel core.
*/
public static class Core {
+ @BuildStep
+ ContainerBeansBuildItem containerBeans(BeanRegistrationPhaseBuildItem beanRegistrationPhase) {
+ return new ContainerBeansBuildItem(beanRegistrationPhase.getContext().get(BuildExtension.Key.BEANS));
+ }
@BuildStep
void beans(BuildProducer<AdditionalBeanBuildItem> beanProducer) {
@@ -151,15 +153,14 @@
CamelRecorder recorder,
RecorderContext recorderContext,
ApplicationArchivesBuildItem applicationArchives,
- BeanRegistrationPhaseBuildItem beanRegistrationPhase,
+ ContainerBeansBuildItem containerBeans,
List<CamelBeanBuildItem> registryItems,
List<CamelServiceFilterBuildItem> serviceFilters) {
final RuntimeValue<Registry> registry = recorder.createRegistry();
- final List<BeanInfo> beans = beanRegistrationPhase.getContext().get(BuildExtension.Key.BEANS);
CamelSupport.services(applicationArchives)
- .filter(si -> !CamelSupport.isContainerBean(beans, si))
+ .filter(si -> !containerBeans.getBeans().contains(si))
.filter(si -> {
//
// by default all the service found in META-INF/service/org/apache/camel are
@@ -184,7 +185,7 @@
});
registryItems.stream()
- .filter(item -> !CamelSupport.isContainerBean(beans, item))
+ .filter(item -> !containerBeans.getBeans().contains(item))
.forEach(item -> {
LOGGER.debug("Binding bean with name: {}, type {}", item.getName(), item.getType());
recorder.bind(
@@ -245,14 +246,12 @@
CamelRuntimeRegistryBuildItem bindRuntimeBeansToRegistry(
CamelRecorder recorder,
RecorderContext recorderContext,
- BeanRegistrationPhaseBuildItem beanRegistrationPhase,
+ ContainerBeansBuildItem containerBeans,
CamelRegistryBuildItem registry,
List<CamelRuntimeBeanBuildItem> registryItems) {
- final List<BeanInfo> beans = beanRegistrationPhase.getContext().get(BuildExtension.Key.BEANS);
-
registryItems.stream()
- .filter(item -> !CamelSupport.isContainerBean(beans, item))
+ .filter(item -> !containerBeans.getBeans().contains(item))
.forEach(item -> {
LOGGER.debug("Binding runtime bean with name: {}, type {}", item.getName(), item.getType());
@@ -301,7 +300,7 @@
* @param camelRoutesBuilderClasses list of {@link CamelRoutesBuilderClassBuildItem} holding {@link RoutesBuilder}
* classes discovered by classpath scanning.
* @param recorder the recorder.
- * @param beanRegistrationPhase holder for {@link BeanRegistrar.RegistrationContext}.
+ * @param containerBeans list of beans known to the ArC container.
* @param recorderContext the recorder context.
* @param config the built time camel configuration.
* @return a curated list of {@link CamelBeanBuildItem} holding {@link RoutesBuilder}.
@@ -311,19 +310,13 @@
public List<CamelBeanBuildItem> collectRoutes(
List<CamelRoutesBuilderClassBuildItem> camelRoutesBuilderClasses,
CamelMainRecorder recorder,
- BeanRegistrationPhaseBuildItem beanRegistrationPhase,
+ ContainerBeansBuildItem containerBeans,
RecorderContext recorderContext,
CamelConfig config) {
- final Set<DotName> arcBeanClasses = beanRegistrationPhase.getContext().get(BuildExtension.Key.BEANS)
- .stream()
- .map(BeanInfo::getImplClazz)
- .map(ClassInfo::name)
- .collect(Collectors.toSet());
-
return camelRoutesBuilderClasses.stream()
.map(CamelRoutesBuilderClassBuildItem::getDotName)
- .filter(dotName -> !arcBeanClasses.contains(dotName))
+ .filter(dotName -> !containerBeans.getClasses().contains(dotName))
.filter(dotName -> CamelSupport.isPathIncluded(
dotName.toString('/'),
config.main.routesDiscovery.excludePatterns,
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 fd4a367..64ba7de 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
@@ -54,4 +54,22 @@
public RuntimeValue<?> getValue() {
return value;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof CamelBeanInfo)) {
+ return false;
+ }
+ CamelBeanInfo info = (CamelBeanInfo) o;
+ return Objects.equals(getName(), info.getName()) &&
+ Objects.equals(getType(), info.getType());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), getType());
+ }
}
diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java
index fff9bb9..ab8b11a 100644
--- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelRuntimeBeanBuildItem.java
@@ -54,4 +54,22 @@
public RuntimeValue<?> getValue() {
return value;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof CamelBeanInfo)) {
+ return false;
+ }
+ CamelBeanInfo info = (CamelBeanInfo) o;
+ return Objects.equals(getName(), info.getName()) &&
+ Objects.equals(getType(), info.getType());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), getType());
+ }
}
diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelServiceInfo.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelServiceInfo.java
index f0b2de2..8c46e13 100644
--- a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelServiceInfo.java
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelServiceInfo.java
@@ -17,6 +17,7 @@
package org.apache.camel.quarkus.core.deployment;
import java.nio.file.Path;
+import java.util.Objects;
/**
* Utility class to describe a camel service which is a result of reading
@@ -61,6 +62,24 @@
}
@Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof CamelBeanInfo)) {
+ return false;
+ }
+ CamelBeanInfo info = (CamelBeanInfo) o;
+ return Objects.equals(getName(), info.getName()) &&
+ Objects.equals(getType(), info.getType());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), getType());
+ }
+
+ @Override
public String toString() {
return "ServiceInfo{"
+ "path='" + path.toString() + '\''
diff --git a/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/ContainerBeansBuildItem.java b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/ContainerBeansBuildItem.java
new file mode 100644
index 0000000..abef5d3
--- /dev/null
+++ b/extensions/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/ContainerBeansBuildItem.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.core.deployment;
+
+import java.util.Collection;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import io.quarkus.arc.processor.BeanInfo;
+import io.quarkus.builder.item.SimpleBuildItem;
+import org.jboss.jandex.ClassInfo;
+import org.jboss.jandex.DotName;
+
+/**
+ * Hold a set of beans known to the ArC container.
+ */
+public final class ContainerBeansBuildItem extends SimpleBuildItem {
+ private final Set<CamelBeanInfo> beans;
+ private final Set<DotName> classes;
+
+ public ContainerBeansBuildItem(Collection<BeanInfo> beans) {
+ this.beans = beans.stream().map(SimpleCamelBeanInfo::new).collect(Collectors.toSet());
+ this.classes = beans.stream().map(BeanInfo::getImplClazz).map(ClassInfo::name).collect(Collectors.toSet());
+ }
+
+ public Set<CamelBeanInfo> getBeans() {
+ return beans;
+ }
+
+ public Set<DotName> getClasses() {
+ return classes;
+ }
+
+ private static class SimpleCamelBeanInfo implements CamelBeanInfo {
+ private final String name;
+ private final String type;
+
+ public SimpleCamelBeanInfo(BeanInfo beanInfo) {
+ this.name = beanInfo.getName();
+ this.type = beanInfo.getImplClazz().toString();
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof CamelBeanInfo)) {
+ return false;
+ }
+ CamelBeanInfo info = (CamelBeanInfo) o;
+ return Objects.equals(getName(), info.getName()) &&
+ Objects.equals(getType(), info.getType());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), getType());
+ }
+ }
+}