From 690eeaf410ce78482d0533c98847567d28cd631e Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Mon, 19 Dec 2022 17:22:41 +0200 Subject: [PATCH] Move log4j-api and add-condition for jaxb-annotations registrations log4j-api is a dependency of elasticsearch-rest-high-level-client `log4j-api` is not always present when using the elasticsearch-rest-client-common extension as it's not a dependency of it. Instead, it is a dependency of elasticsearch-rest-high-level-client: ``` +- io.quarkus:quarkus-elasticsearch-rest-high-level-client:jar:999-SNAPSHOT:compile | +- ... | +- org.jboss.logmanager:log4j2-jboss-logmanager:jar:1.1.1.Final:compile | | \- org.apache.logging.log4j:log4j-api:jar:2.19.0:compile ``` `com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector` is not always present when using the quarkus-jackson extension as it's not a dependency of it. Instead, it is a dependency of quarkus-resteasy-jackson: ``` +- io.quarkus:quarkus-resteasy-jackson:jar:999-SNAPSHOT:compile | +- ... | +- org.jboss.resteasy:resteasy-jackson2-provider:jar:4.7.7.Final:compile | | +- ... | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.14.1:compile | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.14.1:compile | | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.14.1:compile ``` This results in failed attempts to register the class for reflection when using the `quarkus-jackson` extension without `jackson-module-jaxb-annotations` in the classpath. Since we expect users to manually include the artifact in their dependencies even when not using `quarkus-resteasy-jackson` we maintain the registration in the `quarkus-jackson` extension but only perform it when the artifact is present in the classpath. --- .../deployment/ElasticsearchRestClientProcessor.java | 7 ------- .../ElasticsearchHighLevelClientProcessor.java | 8 ++++++++ .../quarkus/jackson/deployment/JacksonProcessor.java | 11 ++++++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/ElasticsearchRestClientProcessor.java b/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/ElasticsearchRestClientProcessor.java index ff0bf4f57690c..a83ec89f278c8 100644 --- a/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/ElasticsearchRestClientProcessor.java +++ b/extensions/elasticsearch-rest-client-common/deployment/src/main/java/io/quarkus/elasticsearch/restclient/common/deployment/ElasticsearchRestClientProcessor.java @@ -4,7 +4,6 @@ import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem; -import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; class ElasticsearchRestClientProcessor { @@ -14,10 +13,4 @@ public void build(BuildProducer extensionSsl extensionSslNativeSupport.produce(new ExtensionSslNativeSupportBuildItem(Feature.ELASTICSEARCH_REST_CLIENT_COMMON)); } - @BuildStep - public ReflectiveClassBuildItem registerForReflection() { - return new ReflectiveClassBuildItem(true, true, - "org.apache.logging.log4j.message.ReusableMessageFactory", - "org.apache.logging.log4j.message.DefaultFlowMessageFactory"); - } } diff --git a/extensions/elasticsearch-rest-high-level-client/deployment/src/main/java/io/quarkus/elasticsearch/restclient/highlevel/deployment/ElasticsearchHighLevelClientProcessor.java b/extensions/elasticsearch-rest-high-level-client/deployment/src/main/java/io/quarkus/elasticsearch/restclient/highlevel/deployment/ElasticsearchHighLevelClientProcessor.java index c78c74997b975..4d1877d2c65d9 100644 --- a/extensions/elasticsearch-rest-high-level-client/deployment/src/main/java/io/quarkus/elasticsearch/restclient/highlevel/deployment/ElasticsearchHighLevelClientProcessor.java +++ b/extensions/elasticsearch-rest-high-level-client/deployment/src/main/java/io/quarkus/elasticsearch/restclient/highlevel/deployment/ElasticsearchHighLevelClientProcessor.java @@ -4,6 +4,7 @@ import io.quarkus.deployment.Feature; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.elasticsearch.restclient.highlevel.runtime.ElasticsearchRestHighLevelClientProducer; class ElasticsearchHighLevelClientProcessor { @@ -18,4 +19,11 @@ AdditionalBeanBuildItem build() { return AdditionalBeanBuildItem.unremovableOf(ElasticsearchRestHighLevelClientProducer.class); } + @BuildStep + public ReflectiveClassBuildItem registerForReflection() { + return new ReflectiveClassBuildItem(true, false, + "org.apache.logging.log4j.message.ReusableMessageFactory", + "org.apache.logging.log4j.message.DefaultFlowMessageFactory"); + } + } diff --git a/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java b/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java index b340c93f349e2..065b5e6efcc5b 100644 --- a/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java +++ b/extensions/jackson/deployment/src/main/java/io/quarkus/jackson/deployment/JacksonProcessor.java @@ -54,6 +54,7 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem; +import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.gizmo.ClassCreator; import io.quarkus.gizmo.ClassOutput; import io.quarkus.gizmo.MethodCreator; @@ -113,18 +114,26 @@ void unremovable(Capabilities capabilities, BuildProducer reflectiveClass, BuildProducer reflectiveHierarchyClass, BuildProducer reflectiveMethod, BuildProducer additionalBeans) { reflectiveClass.produce( - new ReflectiveClassBuildItem(true, false, "com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector", + new ReflectiveClassBuildItem(true, false, "com.fasterxml.jackson.databind.ser.std.SqlDateSerializer", "com.fasterxml.jackson.databind.ser.std.SqlTimeSerializer", "com.fasterxml.jackson.databind.deser.std.DateDeserializers$SqlDateDeserializer", "com.fasterxml.jackson.databind.deser.std.DateDeserializers$TimestampDeserializer", "com.fasterxml.jackson.annotation.SimpleObjectIdResolver")); + if (curateOutcomeBuildItem.getApplicationModel().getDependencies().stream().anyMatch( + x -> x.getGroupId().equals("com.fasterxml.jackson.module") + && x.getArtifactId().equals("jackson-module-jaxb-annotations"))) { + reflectiveClass.produce( + new ReflectiveClassBuildItem(true, false, "com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector")); + } + IndexView index = combinedIndexBuildItem.getIndex(); // TODO: @JsonDeserialize is only supported as a class annotation - we should support the others as well