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

Fix spring-web test failure #20291

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3275,6 +3275,11 @@
<artifactId>quarkus-security-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxrs-spi-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<!-- NOTE: this dependency is here to cause relocations to work; DO NOT MODIFY -->
<groupId>io.smallrye</groupId>
Expand Down
4 changes: 4 additions & 0 deletions extensions/hibernate-validator/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxrs-spi-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-common-spi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<DotName, Set<SimpleMethodSignatureKey>> jaxRsMethods = gatherJaxRsMethods(additionalJaxRsResourceMethodAnnotations,
Set<DotName> additional = new HashSet<>();
additionalJaxRsResourceMethodAnnotations.forEach((s) -> additional.addAll(s.getAnnotationClasses()));
yrodiere marked this conversation as resolved.
Show resolved Hide resolved
Map<DotName, Set<SimpleMethodSignatureKey>> jaxRsMethods = gatherJaxRsMethods(additional,
indexView);

// Add the annotations transformer to add @MethodValidated annotations on the methods requiring validation
Expand Down Expand Up @@ -432,16 +434,14 @@ private static void contributeMethodsWithInheritedValidation(
}

private static Map<DotName, Set<SimpleMethodSignatureKey>> gatherJaxRsMethods(
List<AdditionalJaxRsResourceMethodAnnotationsBuildItem> additionalJaxRsResourceMethodAnnotations,
Set<DotName> additionalJaxRsResourceMethodAnnotations,
IndexView indexView) {
Map<DotName, Set<SimpleMethodSignatureKey>> jaxRsMethods = new HashMap<>();

Collection<DotName> 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<AnnotationInstance> annotationInstances = indexView.getAnnotations(jaxRsAnnotation);
Expand Down
24 changes: 24 additions & 0 deletions extensions/jaxrs-spi/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxrs-spi-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>

<artifactId>quarkus-jaxrs-spi-deployment</artifactId>
<name>Quarkus - JAX-RS - SPI - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.resteasy.server.common.spi;
package io.quarkus.jaxrs.spi.deployment;

import java.util.List;

Expand Down
20 changes: 20 additions & 0 deletions extensions/jaxrs-spi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-extensions-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-jaxrs-spi-parent</artifactId>
<name>Quarkus - JAX-RS SPI - Parent</name>
<packaging>pom</packaging>
<modules>
<module>deployment</module>
</modules>

</project>
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<module>resteasy-reactive</module>
<module>reactive-routes</module>
<module>apache-httpclient</module>
<module>jaxrs-spi</module>

<!-- Monitoring -->
<module>smallrye-health</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxrs-spi-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-server-spi-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxrs-spi-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-security-spi</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions extensions/spring-web/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-server-common-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ReflectiveHierarchyIgnoreWarningBuildItem> ignore) {
ignore.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(
Expand Down Expand Up @@ -145,14 +156,7 @@ public void registerAdditionalResourceClasses(CombinedIndexBuildItem index,
}

@BuildStep
public void methodAnnotationsTransformer(BuildProducer<AnnotationsTransformerBuildItem> producer,
BuildProducer<AdditionalJaxRsResourceMethodAnnotationsBuildItem> 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<AnnotationsTransformerBuildItem> producer) {

producer.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

Expand Down