Skip to content

Commit

Permalink
apacheGH-40878: [JAVA] Fix flight-sql-jdbc-driver shading issues (apa…
Browse files Browse the repository at this point in the history
…che#40879)

### Rationale for this change

The `flight-sql-jdbc-driver` jar is not shaded properly:
* a reduced pom.xml file is not generated. The published pom.xml file declares dependencies which are actually present in the jar and should not be fetched externally
* several classes/files are not relocated properly

### What changes are included in this PR?

Fix pom.xml and relocations. Also removes annotations dependencies and include a integration test to prevent future breakage.

### Are these changes tested?

Yes. A new integration test check the jar content

### Are there any user-facing changes?

Yes. The published pom.xml file on Maven will be cleaned of any dependency
* GitHub Issue: apache#40878

Authored-by: Laurent Goujon <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
laurentgo authored and rok committed May 8, 2024
1 parent f87d4e4 commit 8b1444e
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 119 deletions.
347 changes: 229 additions & 118 deletions java/flight/flight-sql-jdbc-driver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,122 +44,233 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<phase>package</phase>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<minimizeJar>false</minimizeJar>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
<excludes>
<!-- Source annotations -->
<exclude>org.checkerframework:checker-qual</exclude>
<exclude>org.codehaus.mojo:animal-sniffer-annotations</exclude>
<exclude>javax.annotation:javax.annotation-api</exclude>
<exclude>com.google.android:annotations</exclude>
<exclude>com.google.errorprone:error_prone_annotations</exclude>
<exclude>com.google.code.findbugs:jsr305</exclude>
<exclude>com.google.j2objc:j2objc-annotations</exclude>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.</pattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.com.</shadedPattern>
<excludes>
<exclude>com.sun.**</exclude>
</excludes>
</relocation>
<relocation>
<pattern>org.</pattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.org.</shadedPattern>
<excludes>
<exclude>org.apache.arrow.driver.jdbc.**</exclude>
<!-- Avoid shading Flight JDBC Properties -->
<exclude>org.apache.arrow.flight.name</exclude>
<exclude>org.apache.arrow.flight.version</exclude>
<exclude>org.apache.arrow.flight.jdbc-driver.name</exclude>
<exclude>org.apache.arrow.flight.jdbc-driver.version</exclude>
</excludes>
</relocation>
<relocation>
<pattern>io.</pattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.io.</shadedPattern>
</relocation>
<relocation>
<pattern>net.</pattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.net.</shadedPattern>
</relocation>
<relocation>
<pattern>mozilla.</pattern>
<shadedPattern>org.apache.arrow.driver.jdbc.shaded.mozilla.</shadedPattern>
</relocation>
<!-- Entries to relocate netty native libraries -->
<relocation>
<pattern>META-INF.native.libnetty_</pattern>
<shadedPattern>META-INF.native.liboaadj_netty_</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.netty_</pattern>
<shadedPattern>META-INF.native.oaadj_netty_</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"></transformer>
</transformers>
<filters>
<filter>
<artifact>org.apache.arrow:arrow-vector</artifact>
<excludes>
<exclude>codegen/**</exclude>
</excludes>
</filter>
<filter>
<artifact>org.apache.calcite.avatica:*</artifact>
<excludes>
<exclude>META-INF/services/java.sql.Driver</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/*.SF</exclude>
<exclude>**/*.RSA</exclude>
<exclude>**/*.DSA</exclude>
<exclude>META-INF/native/libio_grpc_netty*</exclude>
<exclude>META-INF/native/io_grpc_netty_shaded*</exclude>
<exclude>**/*.proto</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.70</version>
<scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory-core -->
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory-core</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>flight-sql</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.core.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.inline.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>flight-core</artifactId>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.12.6</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.apache.calcite.avatica</groupId>
<artifactId>avatica</artifactId>
<version>1.24.0</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-vector</artifactId>
<classifier>${arrow.vector.classifier}</classifier>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.15.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<minimizeJar>false</minimizeJar>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
<excludes>
<!-- Source annotations -->
<exclude>org.checkerframework:checker-qual</exclude>
<exclude>org.codehaus.mojo:animal-sniffer-annotations</exclude>
<exclude>javax.annotation:javax.annotation-api</exclude>
<exclude>com.google.android:annotations</exclude>
<exclude>com.google.errorprone:error_prone_annotations</exclude>
<exclude>com.google.code.findbugs:jsr305</exclude>
<exclude>com.google.j2objc:j2objc-annotations</exclude>
</excludes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.</pattern>
<shadedPattern>cfjd.com.</shadedPattern>
<excludes>
<exclude>com.sun.**</exclude>
</excludes>
</relocation>
<relocation>
<pattern>org.</pattern>
<shadedPattern>cfjd.org.</shadedPattern>
<excludes>
<exclude>org.apache.arrow.driver.jdbc.**</exclude>
<exclude>org.slf4j.**</exclude>
<!-- Avoid shading Flight JDBC Properties -->
<exclude>org.apache.arrow.flight.name</exclude>
<exclude>org.apache.arrow.flight.version</exclude>
<exclude>org.apache.arrow.flight.jdbc-driver.name</exclude>
<exclude>org.apache.arrow.flight.jdbc-driver.version</exclude>
</excludes>
</relocation>
<relocation>
<pattern>io.</pattern>
<shadedPattern>cfjd.io.</shadedPattern>
</relocation>
<relocation>
<pattern>net.</pattern>
<shadedPattern>cfjd.net.</shadedPattern>
</relocation>
<relocation>
<pattern>mozilla.</pattern>
<shadedPattern>cfjd.mozilla.</shadedPattern>
</relocation>
<!-- Entries to relocate netty native libraries -->
<relocation>
<pattern>META-INF.native.libnetty_</pattern>
<shadedPattern>META-INF.native.libcfjd_netty_</shadedPattern>
</relocation>
<relocation>
<pattern>META-INF.native.netty_</pattern>
<shadedPattern>META-INF.native.cfjd_netty_</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<filters>
<filter>
<artifact>org.apache.arrow:arrow-vector</artifact>
<excludes>
<exclude>codegen/**</exclude>
</excludes>
</filter>
<filter>
<artifact>org.apache.calcite.avatica:*</artifact>
<excludes>
<exclude>META-INF/services/java.sql.Driver</exclude>
</excludes>
</filter>
<filter>
<artifact>org.eclipse.collections:*</artifact>
<excludes>
<exclude>about.html</exclude>
<exclude>LICENSE-*-1.0.txt</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/*.SF</exclude>
<exclude>**/*.RSA</exclude>
<exclude>**/*.DSA</exclude>
<exclude>META-INF/native/libio_grpc_netty*</exclude>
<exclude>META-INF/native/io_grpc_netty_shaded*</exclude>
<exclude>**/*.proto</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
/**
* Check the content of the JDBC driver jar
*
* After shading everything should be either under org.apache.arrow.driver.jdbc. package
* After shading everything should be either under org.apache.arrow.driver.jdbc.,
* org.slf4j., or cfjd. packages
*/
public class ITDriverJarValidation {
/**
Expand All @@ -56,6 +57,8 @@ public class ITDriverJarValidation {
*/
public static final Set<String> ALLOWED_PREFIXES = ImmutableSet.of(
"org/apache/arrow/driver/jdbc/",
"cfjd/",
"org/slf4j/",
"META-INF/");

/**
Expand Down

0 comments on commit 8b1444e

Please sign in to comment.