Skip to content

Commit

Permalink
Fix MailboxServiceShadedIT for shaded dropwizard deps (#1724)
Browse files Browse the repository at this point in the history
* Don't load dropwizard dependency for shaded osgi tests

* Remove com.codahale.metrics import from shaded jar manifest and add javax.management (required by dropwizard)

* Separate osgi tests into shaded and non-shaded to each compile with respective version of driver-code

* Move common osgi test harness to separate subproject, osgi-unshaded and osgi-shaded depend on osgi-common sources which they recompile with the respective version of the driver-core jar

---------

Co-authored-by: Bret McGuire <bret.mcguire@datastax.com>
  • Loading branch information
hhughes and absurdfarce authored Aug 31, 2023
1 parent e96d148 commit 4af251a
Show file tree
Hide file tree
Showing 28 changed files with 493 additions and 47 deletions.
5 changes: 4 additions & 1 deletion driver-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@
JNR does not provide OSGi bundles, so exclude it; the driver can live without it
Explicitly import javax.security.cert because it's required by Netty, but Netty has been explicitly excluded
-->
<Import-Package><![CDATA[com.google.common.*;version="16.0.1",!jnr.*,!io.netty.*,javax.security.cert,*]]></Import-Package>
<Import-Package><![CDATA[com.google.common.*;version="16.0.1",!jnr.*,!io.netty.*,!com.codahale.metrics,javax.security.cert,javax.management,*]]></Import-Package>
<Private-Package>com.datastax.shaded.*</Private-Package>
<Export-Package>com.datastax.shaded.metrics;*</Export-Package>
</instructions>
</configuration>
</execution>
Expand Down Expand Up @@ -302,6 +303,8 @@
<resource>META-INF/maven/io.netty/netty-handler/pom.xml</resource>
<resource>META-INF/maven/io.netty/netty-transport/pom.properties</resource>
<resource>META-INF/maven/io.netty/netty-transport/pom.xml</resource>
<resource>META-INF/maven/io.dropwizard.metrics/metrics-core/pom.properties</resource>
<resource>META-INF/maven/io.dropwizard.metrics/metrics-core/pom.xml</resource>
</resources>
</transformer>
<!-- Pick up the alternate manifest that was generated by the alternate execution of the bundle plugin -->
Expand Down
44 changes: 44 additions & 0 deletions driver-tests/osgi/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--
Copyright DataStax, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-tests-osgi</artifactId>
<version>3.11.5-SNAPSHOT</version>
</parent>

<packaging>jar</packaging>
<artifactId>cassandra-driver-tests-osgi-common</artifactId>
<name>DataStax Java Driver for Apache Cassandra Tests - OSGi - Shaded</name>
<description>Common classes for testing DataStax Java Driver in an OSGi container.</description>

<!--
This submodule holds the common test classes for the shaded and unshaded osgi tests.
Since each testing submodule uses a different version of driver-core, each copies
these common classes into it's build-dir and recompiles them with the correct driver
artifact. This is required because MailboxImpl uses dropwizard classes that may or
may not be shaded. In order for the shaded/unshaded classes on the classpath to match
those referenced in the compiled .class files we need the correct driver-core
dependency loaded at compile-time, hence why each submodule must recompile the common
test code.
-->

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.datastax.driver.osgi;

import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackage;
import static org.ops4j.pax.exam.CoreOptions.bootDelegationPackages;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static UrlProvisionOption driverBundle(boolean useShaded) {
return bundle(
"reference:file:"
+ PathUtils.getBaseDir()
+ "/../../driver-core/target/cassandra-driver-core-"
+ "/../../../driver-core/target/cassandra-driver-core-"
+ Cluster.getDriverVersion()
+ classifier
+ ".jar");
Expand All @@ -70,7 +70,7 @@ public static UrlProvisionOption mappingBundle() {
return bundle(
"reference:file:"
+ PathUtils.getBaseDir()
+ "/../../driver-mapping/target/cassandra-driver-mapping-"
+ "/../../../driver-mapping/target/cassandra-driver-mapping-"
+ Cluster.getDriverVersion()
+ ".jar");
}
Expand All @@ -79,7 +79,7 @@ public static UrlProvisionOption extrasBundle() {
return bundle(
"reference:file:"
+ PathUtils.getBaseDir()
+ "/../../driver-extras/target/cassandra-driver-extras-"
+ "/../../../driver-extras/target/cassandra-driver-extras-"
+ Cluster.getDriverVersion()
+ ".jar");
}
Expand Down Expand Up @@ -143,6 +143,17 @@ public Option[] getOptions() {
};
}

public static CompositeOption dropwizardMetricsBundle() {
return new CompositeOption() {

@Override
public Option[] getOptions() {
return options(
mavenBundle("io.dropwizard.metrics", "metrics-core", getVersion("metrics.version")));
}
};
}

public static UrlProvisionOption mailboxBundle() {
return bundle("reference:file:" + PathUtils.getBaseDir() + "/target/classes");
}
Expand All @@ -157,7 +168,7 @@ public Option[] getOptions() {
// Delegate javax.security.cert to the parent classloader.
// javax.security.cert.X509Certificate is used in
// io.netty.util.internal.EmptyArrays, but not directly by the driver.
bootDelegationPackage("javax.security.cert"),
bootDelegationPackages("javax.security.cert", "javax.management"),
systemProperty("cassandra.version")
.value(CCMBridge.getGlobalCassandraVersion().toString()),
systemProperty("cassandra.contactpoints").value(TestUtils.IP_PREFIX + 1),
Expand All @@ -166,7 +177,6 @@ public Option[] getOptions() {
mavenBundle("org.slf4j", "slf4j-api", getVersion("slf4j.version")),
mavenBundle("ch.qos.logback", "logback-classic", getVersion("logback.version")),
mavenBundle("ch.qos.logback", "logback-core", getVersion("logback.version")),
mavenBundle("io.dropwizard.metrics", "metrics-core", getVersion("metrics.version")),
mavenBundle(
"com.fasterxml.jackson.core",
"jackson-databind",
Expand Down
50 changes: 11 additions & 39 deletions driver-tests/osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,18 @@
<version>3.11.5-SNAPSHOT</version>
</parent>

<packaging>pom</packaging>
<artifactId>cassandra-driver-tests-osgi</artifactId>
<name>DataStax Java Driver for Apache Cassandra Tests - OSGi</name>
<description>A test for the DataStax Java Driver in an OSGi container.</description>

<dependencies>

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<exclusions>
<exclusion>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-ffi</artifactId>
</exclusion>
<exclusion>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
</exclusion>
</exclusions>
</dependency>
<modules>
<module>common</module>
<module>shaded</module>
<module>unshaded</module>
</modules>

<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
Expand All @@ -61,11 +52,6 @@
<artifactId>org.apache.felix.framework</artifactId>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -163,7 +149,7 @@
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>${test.osgi.skip}</skip>
<skip>true</skip>
<systemPropertyVariables>
<cassandra.version>${cassandra.version}</cassandra.version>
<!-- pull in declared version properties, this ensures we test with the same versions used by the driver -->
Expand All @@ -188,25 +174,11 @@
</plugin>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<configuration>
<instructions>
<Bundle-SymbolicName>com.datastax.driver.osgi</Bundle-SymbolicName>
<Export-Package>com.datastax.driver.osgi.api,!com.datastax.driver.osgi.impl</Export-Package>
<Bundle-Activator>com.datastax.driver.osgi.impl.Activator</Bundle-Activator>
<_include>-osgi.bnd</_include>
</instructions>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
Expand Down
161 changes: 161 additions & 0 deletions driver-tests/osgi/shaded/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<!--
Copyright DataStax, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-tests-osgi</artifactId>
<version>3.11.5-SNAPSHOT</version>
</parent>

<artifactId>cassandra-driver-tests-osgi-shaded</artifactId>
<name>DataStax Java Driver for Apache Cassandra Tests - OSGi - Shaded</name>
<description>A test for the shaded DataStax Java Driver in an OSGi container.</description>

<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<!-- note we're depending on the *shaded* driver-core jar -->
<classifier>shaded</classifier>
<exclusions>
<exclusion>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-ffi</artifactId>
</exclusion>
<exclusion>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<!-- copy over common submodule classes as we need to recompile them with the correct driver-core dependency -->
<executions>
<execution>
<id>copy-common-sources</id>
<phase>process-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-sources/cassandra-driver-tests-osgi-common</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>../common/src/main/java/</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-common-test-sources</id>
<phase>process-test-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency-test-sources/cassandra-driver-tests-osgi-common</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>../common/src/test/java/</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/dependency-sources/cassandra-driver-tests-osgi-common</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/dependency-test-sources/cassandra-driver-tests-osgi-common</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>${test.osgi.skip}</skip>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<manifestLocation>${project.build.outputDirectory}/META-INF</manifestLocation>
<instructions>
<Bundle-SymbolicName>com.datastax.driver.osgi</Bundle-SymbolicName>
<Export-Package>com.datastax.driver.osgi.api,!com.datastax.driver.osgi.impl</Export-Package>
<Bundle-Activator>com.datastax.driver.osgi.impl.Activator</Bundle-Activator>
<_include>-osgi.bnd</_include>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
#

pax.exam.system=test
pax.exam.logging=none
pax.exam.logging=none
Loading

0 comments on commit 4af251a

Please sign in to comment.