Skip to content

Commit

Permalink
Fix #3553 make beans of InterceptStrategy unremovable (#3593)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhfeng authored Mar 8, 2022
1 parent b51f682 commit fec2c11
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<>();
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 {

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

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

@Singleton
@Produces
public Exception removableBean() {
Expand Down

0 comments on commit fec2c11

Please sign in to comment.