From d12b81335e8c8f1ed2c997a8e091265ed264958e Mon Sep 17 00:00:00 2001 From: George Gastaldi Date: Tue, 26 Nov 2024 14:43:12 -0300 Subject: [PATCH 1/2] Bump DB2 Driver to 12.1.0.0 It also uses the jakarta.transaction packages, so no need to transform it --- bom/application/pom.xml | 2 +- build-parent/pom.xml | 2 +- extensions/jdbc/jdbc-db2/deployment/pom.xml | 5 -- .../jdbc/db2/deployment/JDBCDB2Processor.java | 9 ++ .../db2/deployment/JakartaEnablement.java | 88 ------------------- 5 files changed, 11 insertions(+), 95 deletions(-) delete mode 100644 extensions/jdbc/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JakartaEnablement.java diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 5f4dcdca4494a..a891b90de9c40 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -125,7 +125,7 @@ 1.6.7 23.5.0.24.07 10.16.1.1 - 11.5.8.0 + 12.1.0.0 1.2.6 2.2 5.10.5 diff --git a/build-parent/pom.xml b/build-parent/pom.xml index ae51c3180b574..3d67bd4676693 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -85,7 +85,7 @@ docker.io/postgres:17 docker.io/mariadb:10.11 - icr.io/db2_community/db2:11.5.9.0 + icr.io/db2_community/db2:12.1.0.0 mcr.microsoft.com/mssql/server:2022-latest docker.io/mysql:8.4 docker.io/gvenzl/oracle-free:23-slim-faststart diff --git a/extensions/jdbc/jdbc-db2/deployment/pom.xml b/extensions/jdbc/jdbc-db2/deployment/pom.xml index 505fc714932be..6d0fb20af7436 100644 --- a/extensions/jdbc/jdbc-db2/deployment/pom.xml +++ b/extensions/jdbc/jdbc-db2/deployment/pom.xml @@ -52,11 +52,6 @@ assertj-core test - - org.eclipse.transformer - org.eclipse.transformer - 0.5.0 - 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 8515935d56682..fd73cf836f3b1 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 @@ -25,6 +25,7 @@ import io.quarkus.deployment.builditem.NativeImageEnableAllCharsetsBuildItem; import io.quarkus.deployment.builditem.SslNativeConfigBuildItem; import io.quarkus.deployment.builditem.nativeimage.JPMSExportBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageAllowIncompleteClasspathBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageConfigBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; @@ -117,6 +118,14 @@ void registerServiceBinding(Capabilities capabilities, dbKind.produce(new DefaultDataSourceDbKindBuildItem(DatabaseKind.DB2)); } + @BuildStep + NativeImageAllowIncompleteClasspathBuildItem allowIncompleteClasspath() { + // The DB2 JDBC driver uses reflection to load classes that are not present in the classpath + // Without it, the following error is thrown: + // Discovered unresolved type during parsing: com.ibm.db2.jcc.licenses.ConParam. This error is reported at image build time because class com.ibm.db2.jcc.am.Connection is registered for linking at image build time by command line and command line. + return new NativeImageAllowIncompleteClasspathBuildItem(Feature.JDBC_DB2.getName()); + } + @BuildStep void addExportsToNativeImage(BuildProducer jpmsExports) { // com.ibm.db2:jcc:11.5.6.0 accesses sun.security.action.GetPropertyAction diff --git a/extensions/jdbc/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JakartaEnablement.java b/extensions/jdbc/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JakartaEnablement.java deleted file mode 100644 index ce8ec45c8ad26..0000000000000 --- a/extensions/jdbc/jdbc-db2/deployment/src/main/java/io/quarkus/jdbc/db2/deployment/JakartaEnablement.java +++ /dev/null @@ -1,88 +0,0 @@ -package io.quarkus.jdbc.db2.deployment; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.eclipse.transformer.action.ActionContext; -import org.eclipse.transformer.action.ByteData; -import org.eclipse.transformer.action.impl.ActionContextImpl; -import org.eclipse.transformer.action.impl.ByteDataImpl; -import org.eclipse.transformer.action.impl.ClassActionImpl; -import org.eclipse.transformer.action.impl.SelectionRuleImpl; -import org.eclipse.transformer.action.impl.SignatureRuleImpl; -import org.eclipse.transformer.util.FileUtils; -import org.objectweb.asm.ClassReader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.quarkus.bootstrap.classloading.QuarkusClassLoader; -import io.quarkus.deployment.annotations.BuildProducer; -import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.builditem.BytecodeTransformerBuildItem; - -/** - * The DB2 driver is compiled using references to classes in the jakarta.transaction - * package; we need to transform these to fix compatibility with jakarta.transaction. - * We do this by leveraging the Eclipse Transformer project during Augmentation, so - * that end users don't need to bother. - */ -public class JakartaEnablement { - - private static final List CLASSES_NEEDING_TRANSFORMATION = List.of( - "com.ibm.db2.jcc.t2zos.ab", - "com.ibm.db2.jcc.t2zos.T2zosConnection", - "com.ibm.db2.jcc.t2zos.T2zosConfiguration"); - - @BuildStep - void transformToJakarta(BuildProducer transformers) { - if (QuarkusClassLoader.isClassPresentAtRuntime("jakarta.transaction.Transaction")) { - JakartaTransformer tr = new JakartaTransformer(); - for (String classname : CLASSES_NEEDING_TRANSFORMATION) { - final BytecodeTransformerBuildItem item = new BytecodeTransformerBuildItem.Builder() - .setCacheable(true) - .setContinueOnFailure(false) - .setClassToTransform(classname) - .setClassReaderOptions(ClassReader.SKIP_DEBUG) - .setInputTransformer(tr::transform) - .build(); - transformers.produce(item); - } - } - } - - private static class JakartaTransformer { - - private final Logger logger; - private final ActionContext ctx; - private static final Map renames = Collections.singletonMap(forbiddenName(), "jakarta.transaction"); - - JakartaTransformer() { - logger = LoggerFactory.getLogger("JakartaTransformer"); - //N.B. we enable only this single transformation of package renames, not the full set of capabilities of Eclipse Transformer; - //this might need tailoring if the same idea gets applied to a different context. - ctx = new ActionContextImpl(logger, - new SelectionRuleImpl(logger, Collections.emptyMap(), Collections.emptyMap()), - new SignatureRuleImpl(logger, renames, null, null, null, null, null, Collections.emptyMap())); - } - - //Need to prevent the Eclipse Transformer - which is run on this whole code base - to actually replace this name: - private static String forbiddenName() { - StringBuilder sb = new StringBuilder("java") - .append("x.") - .append("transaction"); - return sb.toString(); - } - - byte[] transform(final String name, final byte[] bytes) { - logger.info("Jakarta EE compatibility enhancer for Quarkus: transforming " + name); - final ClassActionImpl classTransformer = new ClassActionImpl(ctx); - final ByteBuffer input = ByteBuffer.wrap(bytes); - final ByteData inputData = new ByteDataImpl(name, input, FileUtils.DEFAULT_CHARSET); - final ByteData outputData = classTransformer.apply(inputData); - return outputData.buffer().array(); - } - } - -} From a23633aba9a6609cadbe2d452032aadf07fcaa12 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 8 Jan 2025 16:50:13 +0200 Subject: [PATCH 2/2] Reinitialize `sun.nio.ch.NioSocketImpl` Workaround till https://github.com/oracle/graal/pull/10431 gets merged and backported to all supported versions --- .../quarkus/deployment/NioSocketImplProcessor.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 core/deployment/src/main/java/io/quarkus/deployment/NioSocketImplProcessor.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/NioSocketImplProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/NioSocketImplProcessor.java new file mode 100644 index 0000000000000..9f8d7098bcf7b --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/NioSocketImplProcessor.java @@ -0,0 +1,14 @@ +package io.quarkus.deployment; + +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem; + +public class NioSocketImplProcessor { + + // Workaround till https://github.com/oracle/graal/pull/10431 gets merged and backported to all supported versions + @BuildStep + RuntimeInitializedClassBuildItem reinitializeClass() { + return new RuntimeInitializedClassBuildItem("sun.nio.ch.NioSocketImpl"); + } + +}