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

Automatically lookup Providers based on the presence of standard Jakarta file #33267

Merged
merged 1 commit into from
May 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@
import io.quarkus.hibernate.validator.runtime.interceptor.MethodValidationInterceptor;
import io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyConfigSupport;
import io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyReactiveViolationExceptionMapper;
import io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyViolationExceptionMapper;
import io.quarkus.hibernate.validator.runtime.jaxrs.ViolationReport;
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.common.spi.ResteasyJaxrsProviderBuildItem;
import io.quarkus.resteasy.reactive.spi.ExceptionMapperBuildItem;
import io.quarkus.runtime.LocalesBuildTimeConfig;
import io.quarkus.runtime.configuration.ConfigBuilder;
Expand Down Expand Up @@ -331,6 +333,7 @@ void registerAdditionalBeans(HibernateValidatorRecorder hibernateValidatorRecord
BuildProducer<UnremovableBeanBuildItem> unremovableBean,
BuildProducer<AutoAddScopeBuildItem> autoScopes,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItems,
BuildProducer<ResteasyJaxrsProviderBuildItem> resteasyJaxrsProvider,
Capabilities capabilities) {
// The bean encapsulating the Validator and ValidatorFactory
additionalBeans.produce(new AdditionalBeanBuildItem(ValidatorProvider.class));
Expand All @@ -353,6 +356,8 @@ void registerAdditionalBeans(HibernateValidatorRecorder hibernateValidatorRecord
.supplier(hibernateValidatorRecorder.resteasyConfigSupportSupplier(
resteasyConfigBuildItem.isPresent() ? resteasyConfigBuildItem.get().isJsonDefault() : false))
.done());
resteasyJaxrsProvider.produce(new ResteasyJaxrsProviderBuildItem(ResteasyViolationExceptionMapper.class.getName()));

} else if (capabilities.isPresent(Capability.RESTEASY_REACTIVE)) {
// The CDI interceptor which will validate the methods annotated with @JaxrsEndPointValidated
additionalBeans.produce(new AdditionalBeanBuildItem(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.stream.Collectors;

import jakarta.ws.rs.Priorities;
import jakarta.ws.rs.ext.Providers;
import jakarta.ws.rs.ext.RuntimeDelegate;

import org.jboss.jandex.AnnotationTarget;
Expand Down Expand Up @@ -45,8 +46,11 @@
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BuildTimeConditionBuildItem;
import io.quarkus.arc.deployment.GeneratedBeanBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
Expand All @@ -70,6 +74,19 @@ public class ResteasyReactiveCommonProcessor {
private static final int LEGACY_READER_PRIORITY = Priorities.USER * 2; // readers are compared by decreased priority
private static final int LEGACY_WRITER_PRIORITY = Priorities.USER / 2; // writers are compared by increased priority

private static final String PROVIDERS_SERVICE_FILE = "META-INF/services/" + Providers.class.getName();

@BuildStep
void searchForProviders(Capabilities capabilities,
BuildProducer<AdditionalApplicationArchiveMarkerBuildItem> producer) {
if (capabilities.isPresent(Capability.RESTEASY) || capabilities.isPresent(Capability.REST_CLIENT)) {
// in this weird case we don't want the providers to be registered automatically as this would lead to multiple bean definitions
return;
}
// TODO: should we also be looking for the specific provider files?
producer.produce(new AdditionalApplicationArchiveMarkerBuildItem(PROVIDERS_SERVICE_FILE));
}

@BuildStep
void setUpDenyAllJaxRs(
CombinedIndexBuildItem index,
Expand Down