From 0525f0fbfd26c11cbb9abfe93ad8b61571cfe26b Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 26 Feb 2025 10:16:03 +0200 Subject: [PATCH] fixup! Register Db2 resource bundle classes for reflection --- .../jdbc/db2/deployment/JDBCDB2Processor.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/extensions/jdbc/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JDBCDB2Processor.java b/extensions/jdbc/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JDBCDB2Processor.java index 66dc5571da6e0..d3e7605db2044 100644 --- a/extensions/jdbc/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JDBCDB2Processor.java +++ b/extensions/jdbc/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JDBCDB2Processor.java @@ -2,9 +2,6 @@ import java.util.ListResourceBundle; import java.util.ResourceBundle; -import java.util.Set; -import java.util.TreeSet; -import java.util.stream.Collectors; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; @@ -40,6 +37,7 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageAllowIncompleteClasspathBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.jdbc.db2.runtime.DB2AgroalConnectionConfigurer; @@ -90,8 +88,7 @@ void configureAgroalConnection(BuildProducer additional } @BuildStep - void registerForReflection(CombinedIndexBuildItem index, - BuildProducer reflectiveClass) { + void registerForReflection(BuildProducer reflectiveClass) { //Not strictly necessary when using Agroal, as it also registers //any JDBC driver being configured explicitly through its configuration. //We register it for the sake of people not using Agroal, @@ -117,25 +114,25 @@ void registerForReflection(CombinedIndexBuildItem index, reflectiveClass.produce(ReflectiveClassBuildItem.builder("com.ibm.pdq.cmx.client.DataSourceFactory") .reason(getClass().getName() + " accessed reflectively by Db2 JDBC driver") .build()); + } + + @BuildStep + void registerResources(CombinedIndexBuildItem index, + BuildProducer resource, + BuildProducer resourceBundle) { + resource.produce(new NativeImageResourceBuildItem("pdq.properties")); + resource.produce(new NativeImageResourceBuildItem("com/ibm/db2/cmx/runtime/internal/resources/messages.properties")); // we need to register for reflection all the classes of the driver that are ResourceBundles - for (ClassInfo resourceBundle : index.getIndex().getAllKnownSubclasses(RESOURCE_BUNDLE_DOT_NAME)) { - if (!resourceBundle.name().toString().startsWith(DB2_DRIVER_ROOT_PACKAGE)) { + for (ClassInfo bundle : index.getIndex().getAllKnownSubclasses(RESOURCE_BUNDLE_DOT_NAME)) { + if (!bundle.name().toString().startsWith(DB2_DRIVER_ROOT_PACKAGE)) { continue; } - reflectiveClass.produce(ReflectiveClassBuildItem.builder(resourceBundle.name().toString()) - .reason("ResourceBundle accessed reflectively by Db2 JDBC driver") - .constructors().fields().methods().build()); + resourceBundle.produce(new NativeImageResourceBundleBuildItem(bundle.name().toString())); } } - @BuildStep - void registerResources(BuildProducer resource) { - resource.produce(new NativeImageResourceBuildItem("pdq.properties")); - resource.produce(new NativeImageResourceBuildItem("com/ibm/db2/cmx/runtime/internal/resources/messages.properties")); - } - @BuildStep NativeImageConfigBuildItem build() { // The DB2 JDBC driver has been updated with conditional checks for the