From 7fb33226379a40f374fcb7a983e9ad19dba31bf2 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 20 May 2024 11:21:13 +0300 Subject: [PATCH] Allow the of @Blocking on @ClientExceptionMapper Relates to: https://github.com/quarkusio/quarkus/issues/38275#issuecomment-2115117993 (cherry picked from commit 9b72af5df6fda215850422df4737a6cc8b8369a5) --- .../RestClientReactiveProcessor.java | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java index 9aad6b9433586..815f76c7a8471 100644 --- a/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java +++ b/extensions/resteasy-reactive/rest-client-reactive/deployment/src/main/java/io/quarkus/rest/client/reactive/deployment/RestClientReactiveProcessor.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Predicate; import java.util.stream.Collectors; import jakarta.enterprise.context.SessionScoped; @@ -90,6 +91,7 @@ import io.quarkus.deployment.builditem.GeneratedClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; +import io.quarkus.deployment.execannotations.ExecutionModelAnnotationsAllowedBuildItem; import io.quarkus.gizmo.ClassCreator; import io.quarkus.gizmo.MethodCreator; import io.quarkus.gizmo.MethodDescriptor; @@ -254,19 +256,16 @@ public void registerProvidersInstances(CombinedIndexBuildItem indexBuildItem, *
  • registers all the provider implementations annotated with @Provider using * {@link AnnotationRegisteredProviders#addGlobalProvider(Class, int)}
  • * - * - * - * @param indexBuildItem index - * @param generatedBeans build producer for generated beans */ @BuildStep void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem, List registerProviderAnnotationInstances, List annotationsToRegisterIntoClientContext, - BuildProducer generatedBeans, - BuildProducer generatedClasses, - BuildProducer unremovableBeans, - BuildProducer reflectiveClasses, + BuildProducer generatedBeansProducer, + BuildProducer generatedClassesProducer, + BuildProducer unremovableBeansProducer, + BuildProducer reflectiveClassesProducer, + BuildProducer executionModelAnnotationsAllowedProducer, RestClientReactiveConfig clientConfig) { String annotationRegisteredProvidersImpl = AnnotationRegisteredProviders.class.getName() + "Implementation"; IndexView index = indexBuildItem.getIndex(); @@ -279,7 +278,7 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem, try (ClassCreator classCreator = ClassCreator.builder() .className(annotationRegisteredProvidersImpl) - .classOutput(new GeneratedBeanGizmoAdaptor(generatedBeans)) + .classOutput(new GeneratedBeanGizmoAdaptor(generatedBeansProducer)) .superClass(AnnotationRegisteredProviders.class) .build()) { @@ -319,12 +318,13 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem, } MultivaluedMap generatedProviders = new QuarkusMultivaluedHashMap<>(); - populateClientExceptionMapperFromAnnotations(generatedClasses, reflectiveClasses, index) + populateClientExceptionMapperFromAnnotations(index, generatedClassesProducer, reflectiveClassesProducer, + executionModelAnnotationsAllowedProducer) .forEach(generatedProviders::add); - populateClientRedirectHandlerFromAnnotations(generatedClasses, reflectiveClasses, index) + populateClientRedirectHandlerFromAnnotations(generatedClassesProducer, reflectiveClassesProducer, index) .forEach(generatedProviders::add); for (AnnotationToRegisterIntoClientContextBuildItem annotation : annotationsToRegisterIntoClientContext) { - populateClientProviderFromAnnotations(annotation, generatedClasses, reflectiveClasses, index) + populateClientProviderFromAnnotations(annotation, generatedClassesProducer, reflectiveClassesProducer, index) .forEach(generatedProviders::add); } @@ -334,7 +334,7 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem, constructor.returnValue(null); } - unremovableBeans.produce(UnremovableBeanBuildItem.beanClassNames(annotationRegisteredProvidersImpl)); + unremovableBeansProducer.produce(UnremovableBeanBuildItem.beanClassNames(annotationRegisteredProvidersImpl)); } @BuildStep @@ -632,12 +632,22 @@ private boolean skipAutoDiscoveredProvider(List providerInterfaceNames) } private Map populateClientExceptionMapperFromAnnotations( - BuildProducer generatedClasses, - BuildProducer reflectiveClasses, IndexView index) { + IndexView index, + BuildProducer generatedClassesProducer, + BuildProducer reflectiveClassesProducer, + BuildProducer executionModelAnnotationsAllowedProducer) { + + executionModelAnnotationsAllowedProducer.produce(new ExecutionModelAnnotationsAllowedBuildItem( + new Predicate<>() { + @Override + public boolean test(MethodInfo methodInfo) { + return methodInfo.hasDeclaredAnnotation(CLIENT_EXCEPTION_MAPPER); + } + })); var result = new HashMap(); ClientExceptionMapperHandler clientExceptionMapperHandler = new ClientExceptionMapperHandler( - new GeneratedClassGizmoAdaptor(generatedClasses, true)); + new GeneratedClassGizmoAdaptor(generatedClassesProducer, true)); for (AnnotationInstance instance : index.getAnnotations(CLIENT_EXCEPTION_MAPPER)) { GeneratedClassResult classResult = clientExceptionMapperHandler.generateResponseExceptionMapper(instance); if (classResult == null) { @@ -648,7 +658,7 @@ private Map populateClientExceptionMapperFromAnnot + "' is allowed per REST Client interface. Offending class is '" + classResult.interfaceName + "'"); } result.put(classResult.interfaceName, classResult); - reflectiveClasses.produce(ReflectiveClassBuildItem.builder(classResult.generatedClassName) + reflectiveClassesProducer.produce(ReflectiveClassBuildItem.builder(classResult.generatedClassName) .serialization(false).build()); } return result;