Skip to content
Permalink
Browse files
Fix #3553 make beans of InterceptStrategy unremovable (#3593)
  • Loading branch information
zhfeng committed Mar 8, 2022
1 parent b51f682 commit fec2c11ef3f71e9fa9fea7c40b42aa3ecd97dde4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
@@ -30,11 +30,13 @@
import org.apache.camel.quarkus.core.deployment.catalog.BuildTimeJsonSchemaResolver;
import org.apache.camel.quarkus.core.deployment.catalog.SchemaResource;
import org.apache.camel.quarkus.core.deployment.spi.BuildTimeCamelCatalogBuildItem;
import org.apache.camel.spi.InterceptStrategy;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.spi.annotations.Dataformat;
import org.apache.camel.spi.annotations.Language;
import org.apache.camel.tooling.model.BaseOptionModel;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.slf4j.Logger;
@@ -50,6 +52,10 @@ public class CamelUnremovableBeansProcessor {
DotName.createSimple(Language.class.getName())
};

private static final DotName[] OPTIONAL_SERVICE_TYPES = {
DotName.createSimple(InterceptStrategy.class.getName())
};

@BuildStep
BuildTimeCamelCatalogBuildItem buildTimeCamelCatalog(CombinedIndexBuildItem combinedIndex) {
Set<SchemaResource> resources = new HashSet<>();
@@ -91,4 +97,23 @@ UnremovableBeanBuildItem unremovableCamelBeans(BuildTimeCamelCatalogBuildItem ca

return UnremovableBeanBuildItem.beanTypes(unremovableClasses);
}

@BuildStep
UnremovableBeanBuildItem unremovableOptionalServices(CombinedIndexBuildItem combinedIndex) {
IndexView index = combinedIndex.getIndex();

Set<DotName> unremovableClasses = Stream.of(OPTIONAL_SERVICE_TYPES)
.map(index::getAllKnownImplementors)
.flatMap(Collection::stream)
.map(ClassInfo::name)
.collect(Collectors.toSet());

if (LOGGER.isDebugEnabled()) {
unremovableClasses.stream().forEach(
unremovableClass -> LOGGER.debug("Registering optional service unremovable bean class: {}",
unremovableClass));
}

return UnremovableBeanBuildItem.beanTypes(unremovableClasses);
}
}
@@ -25,6 +25,9 @@

import io.quarkus.test.QuarkusUnitTest;
import org.apache.camel.CamelContext;
import org.apache.camel.NamedNode;
import org.apache.camel.Processor;
import org.apache.camel.spi.InterceptStrategy;
import org.apache.camel.spi.Registry;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.spi.annotations.Dataformat;
@@ -75,6 +78,14 @@ public void testLanguageBeansUnremovable() {
Assertions.assertEquals(1, unremovableLanguageBeans.size());
}

@Test
public void testInterceptStrategyUnremovable() {
Registry registry = context.getRegistry();
Set<UnremovableInterceptStrategy> unremovableInterceptStrategies = registry
.findByType(UnremovableInterceptStrategy.class);
Assertions.assertEquals(1, unremovableInterceptStrategies.size());
}

@Test
public void testNonUnremovableBeansRemoved() {
Registry registry = context.getRegistry();
@@ -94,6 +105,14 @@ static final class UnremovableDataFormatBean {
static final class UnremovableLanguageBean {
}

static final class UnremovableInterceptStrategy implements InterceptStrategy {
@Override
public Processor wrapProcessorInInterceptors(CamelContext context, NamedNode definition, Processor target,
Processor nextTarget) throws Exception {
return target;
}
}

@ApplicationScoped
static final class BeanProducers {

@@ -121,6 +140,12 @@ public UnremovableLanguageBean unremovableLanguageBean() {
return new UnremovableLanguageBean();
}

@Singleton
@Produces
public UnremovableInterceptStrategy unremovableInterceptStrategy() {
return new UnremovableInterceptStrategy();
}

@Singleton
@Produces
public Exception removableBean() {

0 comments on commit fec2c11

Please sign in to comment.