Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the use of @Blocking on @ClientExceptionMapper #40721

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -251,19 +253,16 @@ public void registerProvidersInstances(CombinedIndexBuildItem indexBuildItem,
* <li>registers all the provider implementations annotated with @Provider using
* {@link AnnotationRegisteredProviders#addGlobalProvider(Class, int)}</li>
* </ul>
*
*
* @param indexBuildItem index
* @param generatedBeans build producer for generated beans
*/
@BuildStep
void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem,
List<RegisterProviderAnnotationInstanceBuildItem> registerProviderAnnotationInstances,
List<AnnotationToRegisterIntoClientContextBuildItem> annotationsToRegisterIntoClientContext,
BuildProducer<GeneratedBeanBuildItem> generatedBeans,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<UnremovableBeanBuildItem> unremovableBeans,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<GeneratedBeanBuildItem> generatedBeansProducer,
BuildProducer<GeneratedClassBuildItem> generatedClassesProducer,
BuildProducer<UnremovableBeanBuildItem> unremovableBeansProducer,
BuildProducer<ReflectiveClassBuildItem> reflectiveClassesProducer,
BuildProducer<ExecutionModelAnnotationsAllowedBuildItem> executionModelAnnotationsAllowedProducer,
RestClientReactiveConfig clientConfig) {
String annotationRegisteredProvidersImpl = AnnotationRegisteredProviders.class.getName() + "Implementation";
IndexView index = indexBuildItem.getIndex();
Expand All @@ -276,7 +275,7 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem,

try (ClassCreator classCreator = ClassCreator.builder()
.className(annotationRegisteredProvidersImpl)
.classOutput(new GeneratedBeanGizmoAdaptor(generatedBeans))
.classOutput(new GeneratedBeanGizmoAdaptor(generatedBeansProducer))
.superClass(AnnotationRegisteredProviders.class)
.build()) {

Expand Down Expand Up @@ -316,12 +315,13 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem,
}

MultivaluedMap<String, GeneratedClassResult> 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);

}
Expand All @@ -331,7 +331,7 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem,
constructor.returnValue(null);
}

unremovableBeans.produce(UnremovableBeanBuildItem.beanClassNames(annotationRegisteredProvidersImpl));
unremovableBeansProducer.produce(UnremovableBeanBuildItem.beanClassNames(annotationRegisteredProvidersImpl));
}

@BuildStep
Expand Down Expand Up @@ -629,12 +629,22 @@ private boolean skipAutoDiscoveredProvider(List<DotName> providerInterfaceNames)
}

private Map<String, GeneratedClassResult> populateClientExceptionMapperFromAnnotations(
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses, IndexView index) {
IndexView index,
BuildProducer<GeneratedClassBuildItem> generatedClassesProducer,
BuildProducer<ReflectiveClassBuildItem> reflectiveClassesProducer,
BuildProducer<ExecutionModelAnnotationsAllowedBuildItem> executionModelAnnotationsAllowedProducer) {

executionModelAnnotationsAllowedProducer.produce(new ExecutionModelAnnotationsAllowedBuildItem(
new Predicate<>() {
@Override
public boolean test(MethodInfo methodInfo) {
return methodInfo.hasDeclaredAnnotation(CLIENT_EXCEPTION_MAPPER);
}
}));

var result = new HashMap<String, GeneratedClassResult>();
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) {
Expand All @@ -645,7 +655,7 @@ private Map<String, GeneratedClassResult> 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;
Expand Down
Loading