Skip to content

Commit

Permalink
Merge pull request #44052 from radcortez/resteasy-warnings
Browse files Browse the repository at this point in the history
Avoid double registration of providers
  • Loading branch information
gsmet authored Nov 26, 2024
2 parents 0ad3119 + 0af8ae9 commit e77760f
Showing 1 changed file with 34 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ void disableDefaultExceptionMapper(BuildProducer<SystemPropertyBuildItem> system
systemProperties.produce(new SystemPropertyBuildItem("dev.resteasy.exception.mapper", "false"));
}

@BuildStep
void setupRestEasyManualProviders(BuildProducer<ResteasyJaxrsProviderBuildItem> providers) {
// this one is added manually in RESTEasy's ResteasyDeploymentImpl
// https://github.com/quarkusio/quarkus/issues/13667
providers.produce(new ResteasyJaxrsProviderBuildItem(ServerFormUrlEncodedProvider.class.getName()));
}

@BuildStep
void setupGzipProviders(BuildProducer<ResteasyJaxrsProviderBuildItem> providers) {
// If GZIP support is enabled, enable it
Expand Down Expand Up @@ -164,22 +171,8 @@ JaxrsProvidersToRegisterBuildItem setupProviders(BuildProducer<ReflectiveClassBu
ResteasyConfigBuildItem resteasyConfig,
Capabilities capabilities) throws Exception {

Set<String> contributedProviders = new HashSet<>();
for (ResteasyJaxrsProviderBuildItem contributedProviderBuildItem : contributedProviderBuildItems) {
contributedProviders.add(contributedProviderBuildItem.getName());
}

Set<String> annotatedProviders = new HashSet<>();
for (AnnotationInstance i : indexBuildItem.getIndex().getAnnotations(ResteasyDotNames.PROVIDER)) {
if (i.target().kind() == AnnotationTarget.Kind.CLASS) {
annotatedProviders.add(i.target().asClass().name().toString());
}
}
contributedProviders.addAll(annotatedProviders);
Set<String> availableProviders = new HashSet<>(ServiceUtil.classNamesNamedIn(getClass().getClassLoader(),
"META-INF/services/" + Providers.class.getName()));
// this one is added manually in RESTEasy's ResteasyDeploymentImpl
availableProviders.add(ServerFormUrlEncodedProvider.class.getName());

MediaTypeMap<String> categorizedReaders = new MediaTypeMap<>();
MediaTypeMap<String> categorizedWriters = new MediaTypeMap<>();
Expand All @@ -189,9 +182,6 @@ JaxrsProvidersToRegisterBuildItem setupProviders(BuildProducer<ReflectiveClassBu
categorizeProviders(availableProviders, categorizedReaders, categorizedWriters, categorizedContextResolvers,
otherProviders);

// add the other providers detected
Set<String> providersToRegister = new HashSet<>(otherProviders);

if (!capabilities.isPresent(Capability.VERTX)
&& !capabilities.isCapabilityWithPrefixPresent(Capability.RESTEASY_JSON)) {

Expand Down Expand Up @@ -219,6 +209,8 @@ JaxrsProvidersToRegisterBuildItem setupProviders(BuildProducer<ReflectiveClassBu

}

// add the other providers detected
Set<String> providersToRegister = new HashSet<>(otherProviders);
// we add a couple of default providers
providersToRegister.add(StringTextStar.class.getName());
providersToRegister.addAll(categorizedWriters.getPossible(MediaType.APPLICATION_JSON_TYPE));
Expand All @@ -231,11 +223,32 @@ JaxrsProvidersToRegisterBuildItem setupProviders(BuildProducer<ReflectiveClassBu
providersToRegister, categorizedReaders, categorizedWriters, categorizedContextResolvers,
index, beansIndex);

Set<String> contributedProviders = new HashSet<>();
for (ResteasyJaxrsProviderBuildItem contributedProviderBuildItem : contributedProviderBuildItems) {
// If we use built-in providers, we can ignore duplicate entries
if (!useBuiltinProviders || !availableProviders.contains(contributedProviderBuildItem.getName())) {
contributedProviders.add(contributedProviderBuildItem.getName());
}
}

Set<String> annotatedProviders = new HashSet<>();
for (AnnotationInstance i : indexBuildItem.getIndex().getAnnotations(ResteasyDotNames.PROVIDER)) {
if (i.target().kind() == AnnotationTarget.Kind.CLASS) {
String annotatedProvider = i.target().asClass().name().toString();
// If we use build-in providers, we can ignore duplicate entries
if (!useBuiltinProviders || !availableProviders.contains(annotatedProvider)) {
annotatedProviders.add(annotatedProvider);
}
}
}
contributedProviders.addAll(annotatedProviders);

providersToRegister.addAll(contributedProviders);
if (useBuiltinProviders) {
providersToRegister = new HashSet<>(contributedProviders);
providersToRegister.addAll(availableProviders);
} else {
providersToRegister.addAll(contributedProviders);
// If we use built-in providers, we need to register all available providers
for (String availableProvider : availableProviders) {
reflectiveClass.produce(ReflectiveClassBuildItem.builder(availableProvider).fields().build());
}
}

if (providersToRegister.contains("org.jboss.resteasy.plugins.providers.jsonb.JsonBindingProvider")) {
Expand Down

0 comments on commit e77760f

Please sign in to comment.