From b7428267b7f648be8597269d53aa9c1caa199e23 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Tue, 21 Sep 2021 14:11:42 +1000 Subject: [PATCH] Fix spring-web test failure --- bom/application/pom.xml | 5 ++++ .../hibernate-validator/deployment/pom.xml | 4 ++++ .../HibernateValidatorProcessor.java | 12 +++++----- extensions/jaxrs-spi/deployment/pom.xml | 24 +++++++++++++++++++ ...xRsResourceMethodAnnotationsBuildItem.java | 2 +- extensions/jaxrs-spi/pom.xml | 20 ++++++++++++++++ extensions/pom.xml | 1 + .../resteasy-server-common/deployment/pom.xml | 4 ++++ .../ResteasyServerCommonProcessor.java | 2 +- .../deployment/pom.xml | 4 ++++ extensions/spring-web/deployment/pom.xml | 4 ---- .../web/deployment/SpringWebProcessor.java | 22 ++++++++++------- 12 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 extensions/jaxrs-spi/deployment/pom.xml rename extensions/{resteasy-classic/resteasy-server-common/spi/src/main/java/io/quarkus/resteasy/server/common/spi => jaxrs-spi/deployment/src/main/java/io/quarkus/jaxrs/spi/deployment}/AdditionalJaxRsResourceMethodAnnotationsBuildItem.java (91%) create mode 100644 extensions/jaxrs-spi/pom.xml diff --git a/bom/application/pom.xml b/bom/application/pom.xml index d361d5eac87fd..7752a4fad6c98 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -3275,6 +3275,11 @@ quarkus-security-spi ${project.version} + + io.quarkus + quarkus-jaxrs-spi-deployment + ${project.version} + io.smallrye diff --git a/extensions/hibernate-validator/deployment/pom.xml b/extensions/hibernate-validator/deployment/pom.xml index c70a8da754726..94411d298d7b3 100644 --- a/extensions/hibernate-validator/deployment/pom.xml +++ b/extensions/hibernate-validator/deployment/pom.xml @@ -21,6 +21,10 @@ io.quarkus quarkus-arc-deployment + + io.quarkus + quarkus-jaxrs-spi-deployment + io.quarkus quarkus-resteasy-common-spi diff --git a/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java b/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java index aea65fd304db8..2be5f831516fb 100644 --- a/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java +++ b/extensions/hibernate-validator/deployment/src/main/java/io/quarkus/hibernate/validator/deployment/HibernateValidatorProcessor.java @@ -79,10 +79,10 @@ import io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyConfigSupport; import io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyReactiveViolationExceptionMapper; import io.quarkus.hibernate.validator.spi.BeanValidationAnnotationsBuildItem; +import io.quarkus.jaxrs.spi.deployment.AdditionalJaxRsResourceMethodAnnotationsBuildItem; import io.quarkus.resteasy.common.spi.ResteasyConfigBuildItem; import io.quarkus.resteasy.common.spi.ResteasyDotNames; import io.quarkus.resteasy.reactive.spi.ExceptionMapperBuildItem; -import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodAnnotationsBuildItem; import io.quarkus.runtime.LocalesBuildTimeConfig; class HibernateValidatorProcessor { @@ -314,7 +314,9 @@ public void build(HibernateValidatorRecorder recorder, RecorderContext recorderC // JAX-RS methods are handled differently by the transformer so those need to be gathered here. // Note: The focus only on methods is basically an incomplete solution, since there could also be // class-level JAX-RS annotations but currently the transformer only looks at methods. - Map> jaxRsMethods = gatherJaxRsMethods(additionalJaxRsResourceMethodAnnotations, + Set additional = new HashSet<>(); + additionalJaxRsResourceMethodAnnotations.forEach((s) -> additional.addAll(s.getAnnotationClasses())); + Map> jaxRsMethods = gatherJaxRsMethods(additional, indexView); // Add the annotations transformer to add @MethodValidated annotations on the methods requiring validation @@ -432,16 +434,14 @@ private static void contributeMethodsWithInheritedValidation( } private static Map> gatherJaxRsMethods( - List additionalJaxRsResourceMethodAnnotations, + Set additionalJaxRsResourceMethodAnnotations, IndexView indexView) { Map> jaxRsMethods = new HashMap<>(); Collection jaxRsMethodDefiningAnnotations = new ArrayList<>( ResteasyDotNames.JAXRS_METHOD_ANNOTATIONS.size() + additionalJaxRsResourceMethodAnnotations.size()); jaxRsMethodDefiningAnnotations.addAll(ResteasyDotNames.JAXRS_METHOD_ANNOTATIONS); - for (AdditionalJaxRsResourceMethodAnnotationsBuildItem additionalJaxRsResourceMethodAnnotation : additionalJaxRsResourceMethodAnnotations) { - jaxRsMethodDefiningAnnotations.addAll(additionalJaxRsResourceMethodAnnotation.getAnnotationClasses()); - } + jaxRsMethodDefiningAnnotations.addAll(additionalJaxRsResourceMethodAnnotations); for (DotName jaxRsAnnotation : jaxRsMethodDefiningAnnotations) { Collection annotationInstances = indexView.getAnnotations(jaxRsAnnotation); diff --git a/extensions/jaxrs-spi/deployment/pom.xml b/extensions/jaxrs-spi/deployment/pom.xml new file mode 100644 index 0000000000000..73136c9abbe98 --- /dev/null +++ b/extensions/jaxrs-spi/deployment/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + + io.quarkus + quarkus-jaxrs-spi-parent + 999-SNAPSHOT + + + quarkus-jaxrs-spi-deployment + Quarkus - JAX-RS - SPI - Deployment + + + + io.quarkus + quarkus-core-deployment + + + + + diff --git a/extensions/resteasy-classic/resteasy-server-common/spi/src/main/java/io/quarkus/resteasy/server/common/spi/AdditionalJaxRsResourceMethodAnnotationsBuildItem.java b/extensions/jaxrs-spi/deployment/src/main/java/io/quarkus/jaxrs/spi/deployment/AdditionalJaxRsResourceMethodAnnotationsBuildItem.java similarity index 91% rename from extensions/resteasy-classic/resteasy-server-common/spi/src/main/java/io/quarkus/resteasy/server/common/spi/AdditionalJaxRsResourceMethodAnnotationsBuildItem.java rename to extensions/jaxrs-spi/deployment/src/main/java/io/quarkus/jaxrs/spi/deployment/AdditionalJaxRsResourceMethodAnnotationsBuildItem.java index 76875299bc4f5..d1b3c3ea881f9 100644 --- a/extensions/resteasy-classic/resteasy-server-common/spi/src/main/java/io/quarkus/resteasy/server/common/spi/AdditionalJaxRsResourceMethodAnnotationsBuildItem.java +++ b/extensions/jaxrs-spi/deployment/src/main/java/io/quarkus/jaxrs/spi/deployment/AdditionalJaxRsResourceMethodAnnotationsBuildItem.java @@ -1,4 +1,4 @@ -package io.quarkus.resteasy.server.common.spi; +package io.quarkus.jaxrs.spi.deployment; import java.util.List; diff --git a/extensions/jaxrs-spi/pom.xml b/extensions/jaxrs-spi/pom.xml new file mode 100644 index 0000000000000..0ef4340587af4 --- /dev/null +++ b/extensions/jaxrs-spi/pom.xml @@ -0,0 +1,20 @@ + + + + quarkus-extensions-parent + io.quarkus + 999-SNAPSHOT + ../pom.xml + + 4.0.0 + + quarkus-jaxrs-spi-parent + Quarkus - JAX-RS SPI - Parent + pom + + deployment + + + diff --git a/extensions/pom.xml b/extensions/pom.xml index 86697504fe80d..253bae74b7e1d 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -37,6 +37,7 @@ resteasy-reactive reactive-routes apache-httpclient + jaxrs-spi smallrye-health diff --git a/extensions/resteasy-classic/resteasy-server-common/deployment/pom.xml b/extensions/resteasy-classic/resteasy-server-common/deployment/pom.xml index b1940b0c73202..a7c8e7ab08a47 100644 --- a/extensions/resteasy-classic/resteasy-server-common/deployment/pom.xml +++ b/extensions/resteasy-classic/resteasy-server-common/deployment/pom.xml @@ -21,6 +21,10 @@ io.quarkus quarkus-resteasy-common-deployment + + io.quarkus + quarkus-jaxrs-spi-deployment + io.quarkus quarkus-arc-deployment diff --git a/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java b/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java index a263fc9c34da7..d65a5a58c027e 100755 --- a/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java +++ b/extensions/resteasy-classic/resteasy-server-common/deployment/src/main/java/io/quarkus/resteasy/server/common/deployment/ResteasyServerCommonProcessor.java @@ -66,13 +66,13 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem; import io.quarkus.deployment.util.JandexUtil; import io.quarkus.gizmo.Gizmo; +import io.quarkus.jaxrs.spi.deployment.AdditionalJaxRsResourceMethodAnnotationsBuildItem; import io.quarkus.resteasy.common.deployment.JaxrsProvidersToRegisterBuildItem; import io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor.ResteasyCommonConfig; import io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory; import io.quarkus.resteasy.common.spi.ResteasyDotNames; import io.quarkus.resteasy.server.common.runtime.QuarkusResteasyDeployment; import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceDefiningAnnotationBuildItem; -import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodAnnotationsBuildItem; import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodParamAnnotations; import io.quarkus.resteasy.server.common.spi.AllowedJaxRsAnnotationPrefixBuildItem; import io.quarkus.runtime.annotations.ConfigItem; diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/pom.xml b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/pom.xml index ca7ef6c858652..bac406ccdbc1c 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/pom.xml +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/pom.xml @@ -38,6 +38,10 @@ io.quarkus quarkus-resteasy-reactive-server-spi-deployment + + io.quarkus + quarkus-jaxrs-spi-deployment + io.quarkus quarkus-security-spi diff --git a/extensions/spring-web/deployment/pom.xml b/extensions/spring-web/deployment/pom.xml index 56a19ee38c842..9b976c5ce45cc 100644 --- a/extensions/spring-web/deployment/pom.xml +++ b/extensions/spring-web/deployment/pom.xml @@ -26,10 +26,6 @@ io.quarkus quarkus-resteasy-reactive-jackson-deployment - - io.quarkus - quarkus-resteasy-server-common-spi - io.quarkus quarkus-junit5-internal diff --git a/extensions/spring-web/deployment/src/main/java/io/quarkus/spring/web/deployment/SpringWebProcessor.java b/extensions/spring-web/deployment/src/main/java/io/quarkus/spring/web/deployment/SpringWebProcessor.java index 250a12dde084f..d35f3c43c9cbc 100644 --- a/extensions/spring-web/deployment/src/main/java/io/quarkus/spring/web/deployment/SpringWebProcessor.java +++ b/extensions/spring-web/deployment/src/main/java/io/quarkus/spring/web/deployment/SpringWebProcessor.java @@ -52,11 +52,11 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyIgnoreWarningBuildItem; import io.quarkus.gizmo.ClassOutput; +import io.quarkus.jaxrs.spi.deployment.AdditionalJaxRsResourceMethodAnnotationsBuildItem; import io.quarkus.resteasy.reactive.server.spi.AnnotationsTransformerBuildItem; import io.quarkus.resteasy.reactive.server.spi.MethodScannerBuildItem; import io.quarkus.resteasy.reactive.spi.AdditionalResourceClassBuildItem; import io.quarkus.resteasy.reactive.spi.ExceptionMapperBuildItem; -import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodAnnotationsBuildItem; import io.quarkus.spring.web.runtime.ResponseEntityHandler; import io.quarkus.spring.web.runtime.ResponseStatusExceptionMapper; import io.quarkus.spring.web.runtime.ResponseStatusHandler; @@ -110,6 +110,17 @@ FeatureBuildItem registerFeature() { return new FeatureBuildItem(Feature.SPRING_WEB); } + @BuildStep + public AdditionalJaxRsResourceMethodAnnotationsBuildItem additionalJaxRsResourceMethodAnnotationsBuildItem() { + + // This is useful mainly to let Hibernate Validator know that methods annotated with these annotations + // are to be validated differently, + // e.g. by yielding HTTP status 400 instead of 500 on constraint violation for a method parameter. + // The effect on RestEasy itself is negligible: it will only register the annotated methods for reflection, + // which we already do. + return new AdditionalJaxRsResourceMethodAnnotationsBuildItem(MAPPING_ANNOTATIONS); + } + @BuildStep public void ignoreReflectionHierarchy(BuildProducer ignore) { ignore.produce(new ReflectiveHierarchyIgnoreWarningBuildItem( @@ -145,14 +156,7 @@ public void registerAdditionalResourceClasses(CombinedIndexBuildItem index, } @BuildStep - public void methodAnnotationsTransformer(BuildProducer producer, - BuildProducer additionalJaxRsMethodProducer) { - // This is useful mainly to let Hibernate Validator know that methods annotated with these annotations - // are to be validated differently, - // e.g. by yielding HTTP status 400 instead of 500 on constraint violation for a method parameter. - // The effect on RestEasy itself is negligible: it will only register the annotated methods for reflection, - // which we already do. - additionalJaxRsMethodProducer.produce(new AdditionalJaxRsResourceMethodAnnotationsBuildItem(MAPPING_ANNOTATIONS)); + public void methodAnnotationsTransformer(BuildProducer producer) { producer.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {