From e7021796e367d6ec2f07625b5a4ae7f8afca2646 Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Tue, 2 Apr 2024 00:53:56 -0700 Subject: [PATCH] GH-40907: [Java][FlightSQL] Shade slf4j-api in JDBC driver (#40908) ### Rationale for this change FlightSQL JDBC Driver does not shade slfj4 api which may come into conflict into the version used by an application. If the application uses slf4j 1.x, it may cause the application slf4j backend to not be loaded properly. The change configured maven-shade-plugin to also shade slf4j-api. To make sure log messages are still visible, slf4j-jdk14 is included as well so that all messages will be redirected to `java.util.logging` framework. The application can use jul-to-slf4j adapter to redirect log messages back to slf4j. ### What changes are included in this PR? Overrides `Driver#getParentLogger()` to return the root logger for the JDBC driver (which is `org.apache.arrow.driver.jdbc`). To make sure shaded dependencies loggers are included as well, change relocation from `cfjd.` to `org.apache.arrow.driver.jdbc.shaded. `(or `oaadj` for native libraries) ### Are these changes tested? Verifying that slf4j-api is shaded along with the other relocation changes are covered by `ITDriverJarValidation` ### Are there any user-facing changes? Yes. Driver will not expose directly slf4j api and the logger names for the shaded dependencies have been updated. For applications which were relying on configuring directly a slf4j logging backend for the driver, they may need to include `org.slf4j:slf4-api` and `org.slf4j:jul-to-slf4j` for logging configuration to work. * GitHub Issue: #40907 Authored-by: Laurent Goujon Signed-off-by: David Li --- java/flight/flight-sql-jdbc-driver/pom.xml | 20 +++++++++++-------- .../driver/jdbc/ITDriverJarValidation.java | 5 +---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/java/flight/flight-sql-jdbc-driver/pom.xml b/java/flight/flight-sql-jdbc-driver/pom.xml index 94890606a4920..048dde577a516 100644 --- a/java/flight/flight-sql-jdbc-driver/pom.xml +++ b/java/flight/flight-sql-jdbc-driver/pom.xml @@ -99,6 +99,11 @@ slf4j-api runtime + + org.slf4j + slf4j-jdk14 + runtime + io.netty @@ -192,17 +197,16 @@ com. - cfjd.com. + org.apache.arrow.driver.jdbc.shaded.com. com.sun.** org. - cfjd.org. + org.apache.arrow.driver.jdbc.shaded.org. org.apache.arrow.driver.jdbc.** - org.slf4j.** org.apache.arrow.flight.name org.apache.arrow.flight.version @@ -212,24 +216,24 @@ io. - cfjd.io. + org.apache.arrow.driver.jdbc.shaded.io. net. - cfjd.net. + org.apache.arrow.driver.jdbc.shaded.net. mozilla. - cfjd.mozilla. + org.apache.arrow.driver.jdbc.shaded.mozilla. META-INF.native.libnetty_ - META-INF.native.libcfjd_netty_ + META-INF.native.liboaadj_netty_ META-INF.native.netty_ - META-INF.native.cfjd_netty_ + META-INF.native.oaadj_netty_ diff --git a/java/flight/flight-sql-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/ITDriverJarValidation.java b/java/flight/flight-sql-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/ITDriverJarValidation.java index fdb580d493abf..0cae2fd5f5cb8 100644 --- a/java/flight/flight-sql-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/ITDriverJarValidation.java +++ b/java/flight/flight-sql-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/ITDriverJarValidation.java @@ -42,8 +42,7 @@ /** * Check the content of the JDBC driver jar * - * After shading everything should be either under org.apache.arrow.driver.jdbc., - * org.slf4j., or cfjd. packages + * After shading everything should be either under org.apache.arrow.driver.jdbc. package */ public class ITDriverJarValidation { /** @@ -57,8 +56,6 @@ public class ITDriverJarValidation { */ public static final Set ALLOWED_PREFIXES = ImmutableSet.of( "org/apache/arrow/driver/jdbc/", - "cfjd/", - "org/slf4j/", "META-INF/"); /**