From 1991537d50b9100a3d25cd669af2a892409c1c95 Mon Sep 17 00:00:00 2001 From: Henry Hughes Date: Wed, 1 Nov 2023 12:50:18 -0700 Subject: [PATCH] Mark spotbugs-annotation and jcip-annotations as provided dependencies patch by Henry Hughes; reviewed by Mick Semb Wever for CASSANDRA-18969 --- core-shaded/pom.xml | 2 + core/pom.xml | 2 + distribution-tests/pom.xml | 122 ++++++++++++++++++ .../driver/api/core/DriverDependencyTest.java | 84 ++++++++++++ .../api/core/OptionalDependencyTest.java | 54 ++++++++ .../api/core/ProvidedDependencyTest.java | 45 +++++++ examples/pom.xml | 5 + integration-tests/pom.xml | 5 + manual/core/integration/README.md | 31 ++--- mapper-processor/pom.xml | 2 + mapper-runtime/pom.xml | 2 + metrics/micrometer/pom.xml | 10 ++ metrics/microprofile/pom.xml | 10 ++ osgi-tests/pom.xml | 6 + pom.xml | 1 + query-builder/pom.xml | 2 + test-infra/pom.xml | 2 +- 17 files changed, 367 insertions(+), 18 deletions(-) create mode 100644 distribution-tests/pom.xml create mode 100644 distribution-tests/src/test/java/com/datastax/oss/driver/api/core/DriverDependencyTest.java create mode 100644 distribution-tests/src/test/java/com/datastax/oss/driver/api/core/OptionalDependencyTest.java create mode 100644 distribution-tests/src/test/java/com/datastax/oss/driver/api/core/ProvidedDependencyTest.java diff --git a/core-shaded/pom.xml b/core-shaded/pom.xml index 16c7ff4eea7..fa321503e02 100644 --- a/core-shaded/pom.xml +++ b/core-shaded/pom.xml @@ -112,10 +112,12 @@ com.github.stephenc.jcip jcip-annotations + provided com.github.spotbugs spotbugs-annotations + provided + + 4.0.0 + + com.datastax.oss + java-driver-parent + 4.17.1-SNAPSHOT + + java-driver-distribution-tests + Apache Cassandra Java Driver - distribution tests + + + + ${project.groupId} + java-driver-bom + ${project.version} + pom + import + + + + + + com.datastax.oss + java-driver-test-infra + test + + + com.datastax.oss + java-driver-query-builder + test + + + com.datastax.oss + java-driver-mapper-processor + test + + + com.datastax.oss + java-driver-mapper-runtime + test + + + com.datastax.oss + java-driver-core + test + + + com.datastax.oss + java-driver-metrics-micrometer + test + + + com.datastax.oss + java-driver-metrics-microprofile + test + + + junit + junit + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + ${testing.jvm}/bin/java + ${mockitoopens.argline} + 1 + + + + org.revapi + revapi-maven-plugin + + true + + + + maven-install-plugin + + true + + + + maven-deploy-plugin + + true + + + + org.sonatype.plugins + nexus-staging-maven-plugin + + true + + + + + diff --git a/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/DriverDependencyTest.java b/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/DriverDependencyTest.java new file mode 100644 index 00000000000..16952e3d771 --- /dev/null +++ b/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/DriverDependencyTest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package com.datastax.oss.driver.api.core; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.datastax.oss.driver.api.core.session.Session; +import com.datastax.oss.driver.api.mapper.MapperBuilder; +import com.datastax.oss.driver.api.querybuilder.QueryBuilder; +import com.datastax.oss.driver.api.testinfra.CassandraResourceRule; +import com.datastax.oss.driver.internal.core.util.Reflection; +import com.datastax.oss.driver.internal.mapper.processor.MapperProcessor; +import com.datastax.oss.driver.internal.metrics.micrometer.MicrometerMetricsFactory; +import com.datastax.oss.driver.internal.metrics.microprofile.MicroProfileMetricsFactory; +import org.junit.Test; + +public class DriverDependencyTest { + @Test + public void should_include_core_jar() { + assertThat(Reflection.loadClass(null, "com.datastax.oss.driver.api.core.session.Session")) + .isEqualTo(Session.class); + } + + @Test + public void should_include_query_builder_jar() { + assertThat(Reflection.loadClass(null, "com.datastax.oss.driver.api.querybuilder.QueryBuilder")) + .isEqualTo(QueryBuilder.class); + } + + @Test + public void should_include_mapper_processor_jar() { + assertThat( + Reflection.loadClass( + null, "com.datastax.oss.driver.internal.mapper.processor.MapperProcessor")) + .isEqualTo(MapperProcessor.class); + } + + @Test + public void should_include_mapper_runtime_jar() { + assertThat(Reflection.loadClass(null, "com.datastax.oss.driver.api.mapper.MapperBuilder")) + .isEqualTo(MapperBuilder.class); + } + + @Test + public void should_include_metrics_micrometer_jar() { + assertThat( + Reflection.loadClass( + null, + "com.datastax.oss.driver.internal.metrics.micrometer.MicrometerMetricsFactory")) + .isEqualTo(MicrometerMetricsFactory.class); + } + + @Test + public void should_include_metrics_microprofile_jar() { + assertThat( + Reflection.loadClass( + null, + "com.datastax.oss.driver.internal.metrics.microprofile.MicroProfileMetricsFactory")) + .isEqualTo(MicroProfileMetricsFactory.class); + } + + @Test + public void should_include_test_infra_jar() { + assertThat( + Reflection.loadClass( + null, "com.datastax.oss.driver.api.testinfra.CassandraResourceRule")) + .isEqualTo(CassandraResourceRule.class); + } +} diff --git a/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/OptionalDependencyTest.java b/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/OptionalDependencyTest.java new file mode 100644 index 00000000000..28626413487 --- /dev/null +++ b/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/OptionalDependencyTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package com.datastax.oss.driver.api.core; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.datastax.oss.driver.internal.core.util.Dependency; +import com.datastax.oss.driver.internal.core.util.Reflection; +import org.junit.Test; + +public class OptionalDependencyTest { + @Test + public void should_not_include_snappy_jar() { + Dependency.SNAPPY + .classes() + .forEach(clazz -> assertThat(Reflection.loadClass(null, clazz)).isNull()); + } + + @Test + public void should_not_include_l4z_jar() { + Dependency.LZ4 + .classes() + .forEach(clazz -> assertThat(Reflection.loadClass(null, clazz)).isNull()); + } + + @Test + public void should_not_include_esri_jar() { + Dependency.ESRI + .classes() + .forEach(clazz -> assertThat(Reflection.loadClass(null, clazz)).isNull()); + } + + @Test + public void should_not_include_tinkerpop_jar() { + Dependency.TINKERPOP + .classes() + .forEach(clazz -> assertThat(Reflection.loadClass(null, clazz)).isNull()); + } +} diff --git a/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/ProvidedDependencyTest.java b/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/ProvidedDependencyTest.java new file mode 100644 index 00000000000..1070bbc2fb1 --- /dev/null +++ b/distribution-tests/src/test/java/com/datastax/oss/driver/api/core/ProvidedDependencyTest.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package com.datastax.oss.driver.api.core; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.datastax.oss.driver.internal.core.util.Reflection; +import org.junit.Test; + +public class ProvidedDependencyTest { + @Test + public void should_not_include_graal_sdk_jar() { + assertThat(Reflection.loadClass(null, "org.graalvm.nativeimage.VMRuntime")).isNull(); + } + + @Test + public void should_not_include_spotbugs_annotations_jar() { + assertThat(Reflection.loadClass(null, "edu.umd.cs.findbugs.annotations.NonNull")).isNull(); + } + + @Test + public void should_not_include_jicp_annotations_jar() { + assertThat(Reflection.loadClass(null, "net.jcip.annotations.ThreadSafe")).isNull(); + } + + @Test + public void should_not_include_blockhound_jar() { + assertThat(Reflection.loadClass(null, "reactor.blockhound.BlockHoundRuntime")).isNull(); + } +} diff --git a/examples/pom.xml b/examples/pom.xml index ec87d205ad8..a597f634d9a 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -142,6 +142,11 @@ io.projectreactor reactor-core + + com.github.spotbugs + spotbugs-annotations + provided + diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 73c7e77b2c4..db77efb5166 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -83,6 +83,11 @@ java-driver-metrics-microprofile test + + com.github.stephenc.jcip + jcip-annotations + test + com.github.spotbugs spotbugs-annotations diff --git a/manual/core/integration/README.md b/manual/core/integration/README.md index 37e04b230a2..16ed68f9e9b 100644 --- a/manual/core/integration/README.md +++ b/manual/core/integration/README.md @@ -610,25 +610,22 @@ The driver team uses annotations to document certain aspects of the code: * nullability with [SpotBugs](https://spotbugs.github.io/) annotations `@Nullable` and `@NonNull`. This is mostly used during development; while these annotations are retained in class files, they -serve no purpose at runtime. If you want to minimize the number of JARs in your classpath, you can -exclude them: +serve no purpose at runtime. This class is an optional dependency of the driver. If you wish to +make use of these annotations in your own code you have to explicitly depend on these jars: ```xml - - com.datastax.oss - java-driver-core - ${driver.version} - - - com.github.stephenc.jcip - jcip-annotations - - - com.github.spotbugs - spotbugs-annotations - - - + + + com.github.stephenc.jcip + jcip-annotations + 1.0-1 + + + com.github.spotbugs + spotbugs-annotations + 3.1.12 + + ``` However, there is one case when excluding those dependencies won't work: if you use [annotation diff --git a/mapper-processor/pom.xml b/mapper-processor/pom.xml index 9f6c2572554..f9814b3dea4 100644 --- a/mapper-processor/pom.xml +++ b/mapper-processor/pom.xml @@ -54,10 +54,12 @@ com.github.stephenc.jcip jcip-annotations + provided com.github.spotbugs spotbugs-annotations + provided com.google.testing.compile diff --git a/mapper-runtime/pom.xml b/mapper-runtime/pom.xml index 0b9bf61928f..3957bbe1505 100644 --- a/mapper-runtime/pom.xml +++ b/mapper-runtime/pom.xml @@ -51,10 +51,12 @@ com.github.stephenc.jcip jcip-annotations + provided com.github.spotbugs spotbugs-annotations + provided junit diff --git a/metrics/micrometer/pom.xml b/metrics/micrometer/pom.xml index e7751bafa61..1c28b636b86 100644 --- a/metrics/micrometer/pom.xml +++ b/metrics/micrometer/pom.xml @@ -59,6 +59,16 @@ + + com.github.stephenc.jcip + jcip-annotations + provided + + + com.github.spotbugs + spotbugs-annotations + provided + ch.qos.logback logback-classic diff --git a/metrics/microprofile/pom.xml b/metrics/microprofile/pom.xml index 15b2818141d..0d2d5873330 100644 --- a/metrics/microprofile/pom.xml +++ b/metrics/microprofile/pom.xml @@ -59,6 +59,16 @@ + + com.github.stephenc.jcip + jcip-annotations + provided + + + com.github.spotbugs + spotbugs-annotations + provided + io.smallrye smallrye-metrics diff --git a/osgi-tests/pom.xml b/osgi-tests/pom.xml index 366555fd995..a5085050930 100644 --- a/osgi-tests/pom.xml +++ b/osgi-tests/pom.xml @@ -56,9 +56,15 @@ com.datastax.oss java-driver-mapper-runtime + + com.github.stephenc.jcip + jcip-annotations + provided + com.github.spotbugs spotbugs-annotations + provided ch.qos.logback diff --git a/pom.xml b/pom.xml index 2d366502f3e..71ecd2a7915 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ integration-tests osgi-tests distribution + distribution-tests examples bom diff --git a/query-builder/pom.xml b/query-builder/pom.xml index 504596140d6..5ecbebf367b 100644 --- a/query-builder/pom.xml +++ b/query-builder/pom.xml @@ -51,10 +51,12 @@ com.github.stephenc.jcip jcip-annotations + provided com.github.spotbugs spotbugs-annotations + provided junit diff --git a/test-infra/pom.xml b/test-infra/pom.xml index 21f8605a441..cf1da84f7dd 100644 --- a/test-infra/pom.xml +++ b/test-infra/pom.xml @@ -48,7 +48,7 @@ com.github.spotbugs spotbugs-annotations - true + provided junit