Skip to content

Commit

Permalink
Merge pull request #31649 from geoand/reflect-bi
Browse files Browse the repository at this point in the history
Replace some uses of the deprecated ReflectiveClassBuildItem constructors
  • Loading branch information
geoand authored Mar 8, 2023
2 parents 885291b + 7cc3d18 commit 781736a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ void register(
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethod,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
reflectiveClass.produce(
new ReflectiveClassBuildItem(true, false,
"com.fasterxml.jackson.databind.ser.std.SqlDateSerializer",
ReflectiveClassBuildItem.builder("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"));
"com.fasterxml.jackson.annotation.SimpleObjectIdResolver").methods(true).build());

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"));
ReflectiveClassBuildItem.builder("com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector")
.methods(true).build());
}

IndexView index = combinedIndexBuildItem.getIndex();
Expand Down Expand Up @@ -163,18 +163,18 @@ void register(
AnnotationValue usingValue = deserializeInstance.value("using");
if (usingValue != null) {
// the Deserializers are constructed internally by Jackson using a no-args constructor
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, usingValue.asClass().name().toString()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(usingValue.asClass().name().toString()).build());
}
AnnotationValue keyUsingValue = deserializeInstance.value("keyUsing");
if (keyUsingValue != null) {
// the Deserializers are constructed internally by Jackson using a no-args constructor
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, keyUsingValue.asClass().name().toString()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(keyUsingValue.asClass().name().toString()).build());
}
AnnotationValue contentUsingValue = deserializeInstance.value("contentUsing");
if (contentUsingValue != null) {
// the Deserializers are constructed internally by Jackson using a no-args constructor
reflectiveClass
.produce(new ReflectiveClassBuildItem(false, false, contentUsingValue.asClass().name().toString()));
.produce(ReflectiveClassBuildItem.builder(contentUsingValue.asClass().name().toString()).build());
}
}

Expand All @@ -183,32 +183,31 @@ void register(
AnnotationValue usingValue = serializeInstance.value("using");
if (usingValue != null) {
// the Serializers are constructed internally by Jackson using a no-args constructor
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, usingValue.asClass().name().toString()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(usingValue.asClass().name().toString()).build());
}
AnnotationValue keyUsingValue = serializeInstance.value("keyUsing");
if (keyUsingValue != null) {
// the Deserializers are constructed internally by Jackson using a no-args constructor
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, keyUsingValue.asClass().name().toString()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(keyUsingValue.asClass().name().toString()).build());
}
AnnotationValue contentUsingValue = serializeInstance.value("contentUsing");
if (contentUsingValue != null) {
// the Deserializers are constructed internally by Jackson using a no-args constructor
reflectiveClass
.produce(new ReflectiveClassBuildItem(false, false, contentUsingValue.asClass().name().toString()));
.produce(ReflectiveClassBuildItem.builder(contentUsingValue.asClass().name().toString()).build());
}
AnnotationValue nullsUsingValue = serializeInstance.value("nullsUsing");
if (nullsUsingValue != null) {
// the Deserializers are constructed internally by Jackson using a no-args constructor
reflectiveClass
.produce(new ReflectiveClassBuildItem(false, false, nullsUsingValue.asClass().name().toString()));
.produce(ReflectiveClassBuildItem.builder(nullsUsingValue.asClass().name().toString()).build());
}
}

for (AnnotationInstance creatorInstance : index.getAnnotations(JSON_AUTO_DETECT)) {
if (creatorInstance.target().kind() == CLASS) {
reflectiveClass
.produce(
new ReflectiveClassBuildItem(true, true, creatorInstance.target().asClass().name().toString()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(creatorInstance.target().asClass().name().toString())
.methods(true).fields(true).build());
}
}

Expand All @@ -221,7 +220,9 @@ void register(
AnnotationValue value = resolverInstance.value("value");
if (value != null) {
// Add the type-id-resolver class
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, value.asClass().name().toString()));
reflectiveClass
.produce(ReflectiveClassBuildItem.builder(value.asClass().name().toString()).methods(true).fields(true)
.build());
if (resolverInstance.target().kind() == CLASS) {
// Add the whole hierarchy of the annotated class
addReflectiveHierarchyClass(resolverInstance.target().asClass().name(), reflectiveHierarchyClass);
Expand All @@ -240,7 +241,8 @@ void register(
for (AnnotationInstance jsonNamingInstance : index.getAnnotations(JSON_NAMING)) {
AnnotationValue strategyValue = jsonNamingInstance.value("value");
if (strategyValue != null) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, strategyValue.asClass().name().toString()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(strategyValue.asClass().name().toString())
.methods(true).fields(true).build());
}
}

Expand All @@ -249,13 +251,16 @@ void register(
AnnotationValue generatorValue = jsonIdentityInfoInstance.value("generator");
AnnotationValue resolverValue = jsonIdentityInfoInstance.value("resolver");
if (generatorValue != null) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, generatorValue.asClass().name().toString()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(generatorValue.asClass().name().toString())
.methods(true).fields(true).build());
}
if (resolverValue != null) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, resolverValue.asClass().name().toString()));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(resolverValue.asClass().name().toString())
.methods(true).fields(true).build());
} else {
// Registering since SimpleObjectIdResolver is the default value of @JsonIdentityInfo.resolver
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, SimpleObjectIdResolver.class));
reflectiveClass.produce(
ReflectiveClassBuildItem.builder(SimpleObjectIdResolver.class).methods(true).fields(true).build());
}
}

Expand Down Expand Up @@ -389,7 +394,7 @@ public void supportMixins(MixinsRecorder recorder,
}
ClassInfo mixinClassInfo = instance.target().asClass();
String mixinClassName = mixinClassInfo.name().toString();
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, mixinClassName));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(mixinClassName).methods(true).fields(true).build());
try {
Type[] targetTypes = instance.value().asClassArray();
if ((targetTypes == null) || targetTypes.length == 0) {
Expand All @@ -398,7 +403,8 @@ public void supportMixins(MixinsRecorder recorder,
Class<?> mixinClass = Thread.currentThread().getContextClassLoader().loadClass(mixinClassName);
for (Type targetType : targetTypes) {
String targetClassName = targetType.name().toString();
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, targetClassName));
reflectiveClass
.produce(ReflectiveClassBuildItem.builder(targetClassName).methods(true).fields(true).build());
mixinsMap.put(Thread.currentThread().getContextClassLoader().loadClass(targetClassName),
mixinClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,36 +190,27 @@ public void process(ApplicationIndexBuildItem applicationIndex, CombinedIndexBui
.map(c -> c.name().toString())
.filter(s -> s.startsWith("io.fabric8.kubernetes"))
.toArray(String[]::new);
reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false, deserializerClasses));
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(deserializerClasses).methods(true).build());

final String[] serializerClasses = combinedIndexBuildItem.getIndex()
.getAllKnownSubclasses(DotName.createSimple("com.fasterxml.jackson.databind.JsonSerializer"))
.stream()
.map(c -> c.name().toString())
.filter(s -> s.startsWith("io.fabric8.kubernetes"))
.toArray(String[]::new);
reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false, serializerClasses));
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(serializerClasses).methods(true).build());

reflectiveClasses
.produce(new ReflectiveClassBuildItem(true, true, KubernetesClientImpl.class.getName()));
reflectiveClasses
.produce(new ReflectiveClassBuildItem(true, true, DefaultKubernetesClient.class.getName()));
reflectiveClasses
.produce(new ReflectiveClassBuildItem(true, false, AnyType.class.getName()));
reflectiveClasses
.produce(new ReflectiveClassBuildItem(true, false, IntOrString.class.getName()));

reflectiveClasses
.produce(new ReflectiveClassBuildItem(true, false, KubernetesDeserializer.class.getName()));
reflectiveClasses
.produce(new ReflectiveClassBuildItem(true, true, VersionInfo.class.getName()));
reflectiveClasses.produce(
ReflectiveClassBuildItem.builder(KubernetesClientImpl.class, DefaultKubernetesClient.class, VersionInfo.class)
.methods(true).fields(true).build());
reflectiveClasses.produce(ReflectiveClassBuildItem
.builder(AnyType.class, IntOrString.class, KubernetesDeserializer.class).methods(true).build());

// exec credentials support - we need to use Strings as the classes are private
reflectiveClasses
.produce(new ReflectiveClassBuildItem(true, true,
"io.fabric8.kubernetes.client.Config$ExecCredential",
.produce(ReflectiveClassBuildItem.builder("io.fabric8.kubernetes.client.Config$ExecCredential",
"io.fabric8.kubernetes.client.Config$ExecCredentialSpec",
"io.fabric8.kubernetes.client.Config$ExecCredentialStatus"));
"io.fabric8.kubernetes.client.Config$ExecCredentialStatus").methods(true).fields(true).build());

if (log.isDebugEnabled()) {
final String watchedClassNames = watchedClasses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public void enableSsl(BuildProducer<ExtensionSslNativeSupportBuildItem> extensio

@BuildStep
public void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, false, Response.class));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, false, Response.PropertySource.class));
reflectiveClass.produce(ReflectiveClassBuildItem.builder(Response.class, Response.PropertySource.class).build());
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ quarkus.class-loading.removed-resources."io.quarkus\:quarkus-integration-test-ma
quarkus.test.enable-callbacks-for-integration-tests=true

# @RolesAllowed value is configuration expression
tester-config-exp=tester
tester-config-exp=tester

0 comments on commit 781736a

Please sign in to comment.