Skip to content

Commit

Permalink
Move log4j-api and add-condition for jaxb-annotations registrations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zakkak committed Dec 23, 2022
1 parent 65c3f7d commit 690eeaf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -14,10 +13,4 @@ public void build(BuildProducer<ExtensionSslNativeSupportBuildItem> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,18 +114,26 @@ void unremovable(Capabilities capabilities, BuildProducer<UnremovableBeanBuildIt

@BuildStep
void register(
CurateOutcomeBuildItem curateOutcomeBuildItem,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchyClass,
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethod,
BuildProducer<AdditionalBeanBuildItem> 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
Expand Down

0 comments on commit 690eeaf

Please sign in to comment.