From f9b4d08b7ae11a8400095d8a172b0361f824306c Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Mon, 20 Jan 2025 09:50:15 +0000 Subject: [PATCH 1/6] NCLSUP-1188 Improve constraint handling --- .../OpenTelemetryFunctionalTest.java | 2 +- .../gm/analyzer/alignment/AlignmentTask.java | 82 ++++++++++++++++++- .../AlignmentTaskEmptyVersionTest.java | 6 +- .../jboss/gm/common/ManipulationCache.java | 8 ++ 4 files changed, 92 insertions(+), 6 deletions(-) diff --git a/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java b/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java index 41c8f479..672e26b9 100644 --- a/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java +++ b/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java @@ -139,7 +139,7 @@ public void verifyOpenTelemetryKotlin() throws IOException, URISyntaxException, assertThat(root.getAlignedDependencies()).isEmpty(); }); - assertThat(am.findCorrespondingChild("dependencyManagement")).satisfies(root -> { + assertThat(am.findCorrespondingChild(":api:all")).satisfies(root -> { assertThat(root.getVersion()).isEqualTo("0.17.0.redhat-00001"); final Collection alignedDependencies = root.getAlignedDependencies().values(); assertThat(alignedDependencies) diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java index 4b1f0ef4..452f392b 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java @@ -55,7 +55,6 @@ import org.gradle.api.artifacts.ResolvedDependency; import org.gradle.api.artifacts.UnresolvedDependency; import org.gradle.api.artifacts.repositories.ArtifactRepository; -import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.attributes.Attribute; import org.gradle.api.internal.GradleInternal; import org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult; @@ -250,7 +249,7 @@ public void perform() { .allProjectVersionRefsFromLockfiles(project.getProjectDir()); final Map dependencies = processAnyExistingManipulationFile( project, - getDependencies(project, configuration, lockFileDeps)); + getDependencies(project, cache, configuration, lockFileDeps)); logger.debug("For project {} adding to the cache the dependencies {}", project, dependencies); // TODO: Trace level? cache.addDependencies(project, dependencies); @@ -630,15 +629,68 @@ private static boolean isDefaultProjectDependencyConstraint(Object obj) { return DEPENDENCY_CONSTRAINT_CLASS != null && DEPENDENCY_CONSTRAINT_CLASS.isInstance(obj); } - private Map getDependencies(Project project, Configuration internalConfig, + private Map getDependencies(Project project, ManipulationCache cache, + Configuration internalConfig, Set lockFileDeps) { + // if (!constraint) { + // constraint = project.getConfigurations().stream() + // .anyMatch(config -> // try { + // // || Class.forName( + // // "org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint_Decorated") + // // .isInstance(obj) + // // } catch (ClassNotFoundException e) { + // // throw new RuntimeException(e); + // // } + // config + // .getAllDependencyConstraints().stream() + // .anyMatch(AlignmentTask::isDefaultProjectDependencyConstraint)); + // // .anyMatch(AlignmentTask::isDefaultProjectDependencyConstraint)); + // } + // logger.warn("### In project {} constraint found {} in class {}", project.getName(), constraint , System.identityHashCode()); + final Map depMap = new LinkedHashMap<>(); project.getConfigurations().all(configuration -> { + logger.warn("### project {} configuration {} canbeConsumed {} canberesolved {} visible {} canbedeclared {}", + project.getName(), + configuration.getName(), + configuration.isCanBeConsumed(), + configuration.isCanBeResolved(), + configuration.isVisible()); + // configuration.isCanBeDeclared()); + + // canBeResolved: Indicates that this configuration is intended for resolving a set of dependencies into a dependency graph. A resolvable configuration should not be declarable or consumable. if (configuration.isCanBeResolved()) { + final Boolean anyConstraints = configuration.getAllDependencyConstraints().isEmpty(); + logger.warn( + "###@@@ For project {} examining configuration {} with consume {} and any constraint {} and defaultproject constraint {} ", + project.getName(), + configuration.getName(), configuration.isCanBeConsumed(), anyConstraints, cache.isConstraints()); logger.trace("Examining configuration {}", configuration.getName()); + // https://docs.gradle.org/current/userguide/declaring_configurations.html + + // if (!configuration.isCanBeConsumed() + // && (configuration.getName().toLowerCase().endsWith("compileclasspath") || + // configuration.getName().toLowerCase().endsWith("runtimeclasspath")) + // + // /*&& !configuration.isCanBeDeclared()*/) { + // logger.warn("Not altering configuration for {} under {}", configuration.getName(), project.getName()); + // return; + // + // } + // Boolean classpathConfiguration = false; + // if ( + // //constraint + // /*&& GradleVersion.current().compareTo(GradleVersion.version("8.0")) >= 0*/ + // // && !configuration.isCanBeConsumed() + // (configuration.getName().equalsIgnoreCase("runtimeClasspath") || + // configuration.getName().equalsIgnoreCase("compileClasspath"))) { + // logger.warn("Not altering configuration for {} under {}", configuration.getName(), project.getName()); + // classpathConfiguration = true; + // } + // // using getAllDependencies here instead of getDependencies because the latter // was returning an empty array for the root project of SpringLikeLayoutFunctionalTest final DependencySet allDependencies = configuration.getAllDependencies(); @@ -659,13 +711,36 @@ private Map getDependencies(Project // need to copy the configurations to ensure we resolve all dependencies (See // analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/DynamicWithLocksProjectFunctionalTest.java for // an example) first verify if DefaultProjectDependencyConstraint occurs in the list of constraints. + // + // NCLSUP-1188: to avoid "Dependency constraints can not be declared against the `compileClasspath` configuration" + // we now avoid recursive copying if constraints are active in any configuration in any subproject. + if (!cache.isConstraints()) { + cache.setConstraints(configuration.getAllDependencyConstraints().stream() + .anyMatch(AlignmentTask::isDefaultProjectDependencyConstraint)); + } + logger.warn("### In project {} constraint found {} in class {}", project.getName(), cache.isConstraints(), + System.identityHashCode(AlignmentTask.class)); + LenientConfiguration lenient; org.gradle.api.artifacts.Configuration copy; // Attempt to call copyRecursive for all types (kotlin/gradle). + // if (!cache.isConstraints() if (configuration .getAllDependencyConstraints().stream() .noneMatch(AlignmentTask::isDefaultProjectDependencyConstraint)) { + // if (!constraint) { + // if (!configuration.isCanBeDeclared() && + // !classpathConfiguration && + // configuration + // .getAllDependencyConstraints().stream() + // .noneMatch(AlignmentTask::isDefaultProjectDependencyConstraint)) { + // !configuration.isCanBeDeclared() && + // !classpathConfiguration && + // configuration + // .getAllDependencyConstraints().stream() + // .noneMatch(AlignmentTask::isDefaultProjectDependencyConstraint) + // ) { copy = configuration.copyRecursive(); lenient = copy.getResolvedConfiguration().getLenientConfiguration(); } else { @@ -928,6 +1003,7 @@ private void processAlignmentReport(Project project, Configuration configuration .getDependencies(); final Set>> entrySet = projectDependencies .entrySet(); + logger.info("### all project dependencies for {}", entrySet); for (Map.Entry> entry : entrySet) { final Project name = entry.getKey(); diff --git a/analyzer/src/test/java/org/jboss/gm/analyzer/alignment/AlignmentTaskEmptyVersionTest.java b/analyzer/src/test/java/org/jboss/gm/analyzer/alignment/AlignmentTaskEmptyVersionTest.java index 2968d905..655f23e4 100644 --- a/analyzer/src/test/java/org/jboss/gm/analyzer/alignment/AlignmentTaskEmptyVersionTest.java +++ b/analyzer/src/test/java/org/jboss/gm/analyzer/alignment/AlignmentTaskEmptyVersionTest.java @@ -32,6 +32,7 @@ import org.jboss.byteman.contrib.bmunit.BMUnitRunner; import org.jboss.gm.analyzer.alignment.io.SettingsFileIO; import org.jboss.gm.common.Configuration; +import org.jboss.gm.common.ManipulationCache; import org.jboss.gm.common.rules.LoggingRule; import org.junit.Before; import org.junit.Rule; @@ -117,11 +118,12 @@ public void testProject() throws Exception { Configuration config = ConfigFactory.create(Configuration.class); // As getDependencies is private, use reflection to modify the access control. - Method m = at.getClass().getDeclaredMethod("getDependencies", Project.class, Configuration.class, Set.class); + Method m = at.getClass().getDeclaredMethod("getDependencies", Project.class, ManipulationCache.class, + Configuration.class, Set.class); m.setAccessible(true); @SuppressWarnings("unchecked") Map result = (Map) m.invoke(at, - new Object[] { p, config, new HashSet() }); + new Object[] { p, ManipulationCache.getCache(p), config, new HashSet() }); Collection allDependencies = result.values(); assertEquals(1, allDependencies.size()); diff --git a/common/src/main/java/org/jboss/gm/common/ManipulationCache.java b/common/src/main/java/org/jboss/gm/common/ManipulationCache.java index 7d7691af..7f33d02f 100644 --- a/common/src/main/java/org/jboss/gm/common/ManipulationCache.java +++ b/common/src/main/java/org/jboss/gm/common/ManipulationCache.java @@ -73,6 +73,14 @@ public class ManipulationCache { @Setter private DokkaVersion dokkaVersion = DokkaVersion.NONE; + /** + * OpenTelemetry builds utilise constraints but this can affect the entire project leading to + * "Dependency constraints can not be declared against the `compileClasspath` configuration" + */ + @Getter + @Setter + private boolean constraints; + /** * Retrieves the cache given any project. It will access the root project, check if the * cache exists and create it if required. From 8391676b29784d42e489a61d07583e717ad735fa Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Mon, 20 Jan 2025 10:10:03 +0000 Subject: [PATCH 2/6] Rename opentelemetry-kotlin-2 to opentelemetry-java-instrumentation --- .../alignment/OpenTelemetryFunctionalTest.java | 2 +- .../benchmark-overhead-jmh/build.gradle.kts | 0 .../bom-alpha/build.gradle.kts | 0 .../build.gradle.kts | 0 .../conventions/build.gradle.kts | 0 .../conventions/settings.gradle.kts | 0 ...io.opentelemetry.instrumentation.base.gradle.kts | 0 ...rumentation.javaagent-instrumentation.gradle.kts | 0 ...y.instrumentation.javaagent-shadowing.gradle.kts | 0 ...try.instrumentation.javaagent-testing.gradle.kts | 0 ...strumentation.library-instrumentation.gradle.kts | 0 .../instrumentation/gradle/OtelJavaExtension.kt | 0 .../otel.animalsniffer-conventions.gradle.kts | 0 .../kotlin/otel.errorprone-conventions.gradle.kts | 0 .../main/kotlin/otel.jacoco-conventions.gradle.kts | 0 .../main/kotlin/otel.japicmp-conventions.gradle.kts | 0 .../main/kotlin/otel.java-conventions.gradle.kts | 0 .../main/kotlin/otel.javaagent-bootstrap.gradle.kts | 0 .../otel.javaagent-instrumentation.gradle.kts | 0 .../main/kotlin/otel.javaagent-testing.gradle.kts | 0 .../src/main/kotlin/otel.jmh-conventions.gradle.kts | 0 .../kotlin/otel.library-instrumentation.gradle.kts | 0 .../kotlin/otel.nullaway-conventions.gradle.kts | 0 .../kotlin/otel.protobuf-conventions.gradle.kts | 0 .../main/kotlin/otel.publish-conventions.gradle.kts | 0 .../main/kotlin/otel.scala-conventions.gradle.kts | 0 .../custom-checks/build.gradle.kts | 0 .../dependencyManagement/build.gradle.kts | 0 .../gradle-plugins/build.gradle.kts | 0 .../gradle/wrapper/gradle-wrapper.jar | Bin .../gradle/wrapper/gradle-wrapper.properties | 0 .../gradle-plugins/gradlew | 0 .../gradle-plugins/gradlew.bat | 0 .../gradle-plugins/settings.gradle.kts | 0 ...elemetry.instrumentation.muzzle-check.gradle.kts | 0 ...try.instrumentation.muzzle-generation.gradle.kts | 0 .../javaagent/muzzle/AcceptableVersions.kt | 0 .../javaagent/muzzle/MuzzleDirective.kt | 0 .../javaagent/muzzle/MuzzleExtension.kt | 0 .../muzzle/generation/ClasspathByteBuddyPlugin.kt | 0 .../muzzle/generation/ClasspathTransformation.kt | 0 .../muzzle/matcher/MuzzleGradlePluginUtil.kt | 0 .../instrumentation-api-semconv/build.gradle.kts | 0 .../instrumentation-api/build.gradle.kts | 0 .../settings.gradle.kts | 0 .../smoke-tests/images/quarkus/build.gradle.kts | 0 .../version.gradle.kts | 0 47 files changed, 1 insertion(+), 1 deletion(-) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/benchmark-overhead-jmh/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/bom-alpha/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/settings.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-instrumentation.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-testing.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/io.opentelemetry.instrumentation.library-instrumentation.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.errorprone-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.jacoco-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.japicmp-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.java-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.javaagent-bootstrap.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.javaagent-instrumentation.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.javaagent-testing.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.jmh-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.library-instrumentation.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.nullaway-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.protobuf-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.publish-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/conventions/src/main/kotlin/otel.scala-conventions.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/custom-checks/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/dependencyManagement/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/gradle/wrapper/gradle-wrapper.jar (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/gradle/wrapper/gradle-wrapper.properties (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/gradlew (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/gradlew.bat (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/settings.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-generation.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/AcceptableVersions.kt (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleDirective.kt (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleExtension.kt (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathByteBuddyPlugin.kt (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathTransformation.kt (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/matcher/MuzzleGradlePluginUtil.kt (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/instrumentation-api-semconv/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/instrumentation-api/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/settings.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/smoke-tests/images/quarkus/build.gradle.kts (100%) rename analyzer/src/functTest/resources/{opentelemetry-kotlin-2 => opentelemetry-java-instrumentation}/version.gradle.kts (100%) diff --git a/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java b/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java index 672e26b9..e27a82a3 100644 --- a/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java +++ b/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java @@ -167,7 +167,7 @@ public void verifyOpenTelemetryJavaInstrumentationKotlin() throws Exception { map.put("-DignoreUnresolvableDependencies", "true"); map.put("-DpluginRemoval", "gradle-enterprise,io.github.gradle-nexus.publish-plugin"); - final File projectRoot = tempDir.newFolder("opentelemetry-kotlin-2"); + final File projectRoot = tempDir.newFolder("opentelemetry-java-instrumentation"); final TestManipulationModel alignmentModel = TestUtils.align(projectRoot, projectRoot.getName(), map); assertTrue(new File(projectRoot, AlignmentTask.GME).exists()); diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/benchmark-overhead-jmh/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/benchmark-overhead-jmh/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/benchmark-overhead-jmh/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/benchmark-overhead-jmh/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/bom-alpha/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/bom-alpha/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/settings.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/settings.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/settings.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/settings.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.base.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-instrumentation.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-instrumentation.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-instrumentation.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-instrumentation.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-testing.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-testing.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-testing.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-testing.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.library-instrumentation.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.library-instrumentation.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io.opentelemetry.instrumentation.library-instrumentation.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io.opentelemetry.instrumentation.library-instrumentation.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.errorprone-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.errorprone-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.errorprone-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.errorprone-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.jacoco-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.jacoco-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.jacoco-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.jacoco-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.japicmp-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.japicmp-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.japicmp-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.japicmp-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.java-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.java-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.java-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.java-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.javaagent-bootstrap.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.javaagent-bootstrap.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.javaagent-bootstrap.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.javaagent-bootstrap.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.javaagent-instrumentation.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.javaagent-instrumentation.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.javaagent-instrumentation.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.javaagent-instrumentation.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.javaagent-testing.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.javaagent-testing.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.javaagent-testing.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.javaagent-testing.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.jmh-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.jmh-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.jmh-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.jmh-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.library-instrumentation.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.library-instrumentation.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.library-instrumentation.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.library-instrumentation.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.nullaway-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.nullaway-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.nullaway-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.nullaway-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.protobuf-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.protobuf-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.protobuf-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.protobuf-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.publish-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.publish-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.publish-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.publish-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.scala-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.scala-conventions.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/conventions/src/main/kotlin/otel.scala-conventions.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/conventions/src/main/kotlin/otel.scala-conventions.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/custom-checks/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/custom-checks/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/custom-checks/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/custom-checks/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/dependencyManagement/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/dependencyManagement/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/dependencyManagement/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/dependencyManagement/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/gradle/wrapper/gradle-wrapper.jar b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/gradle/wrapper/gradle-wrapper.jar rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/gradle/wrapper/gradle-wrapper.jar diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/gradle/wrapper/gradle-wrapper.properties b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/gradle/wrapper/gradle-wrapper.properties rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/gradle/wrapper/gradle-wrapper.properties diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/gradlew b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/gradlew similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/gradlew rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/gradlew diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/gradlew.bat b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/gradlew.bat similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/gradlew.bat rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/gradlew.bat diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/settings.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/settings.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/settings.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/settings.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-generation.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-generation.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-generation.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-generation.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/AcceptableVersions.kt b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/AcceptableVersions.kt similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/AcceptableVersions.kt rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/AcceptableVersions.kt diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleDirective.kt b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleDirective.kt similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleDirective.kt rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleDirective.kt diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleExtension.kt b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleExtension.kt similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleExtension.kt rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/MuzzleExtension.kt diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathByteBuddyPlugin.kt b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathByteBuddyPlugin.kt similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathByteBuddyPlugin.kt rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathByteBuddyPlugin.kt diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathTransformation.kt b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathTransformation.kt similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathTransformation.kt rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/generation/ClasspathTransformation.kt diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/matcher/MuzzleGradlePluginUtil.kt b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/matcher/MuzzleGradlePluginUtil.kt similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/matcher/MuzzleGradlePluginUtil.kt rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/matcher/MuzzleGradlePluginUtil.kt diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/instrumentation-api-semconv/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/instrumentation-api-semconv/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/instrumentation-api-semconv/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/instrumentation-api-semconv/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/instrumentation-api/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/instrumentation-api/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/instrumentation-api/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/instrumentation-api/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/settings.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/settings.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/settings.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/settings.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/smoke-tests/images/quarkus/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/smoke-tests/images/quarkus/build.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/smoke-tests/images/quarkus/build.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/smoke-tests/images/quarkus/build.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/version.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-java-instrumentation/version.gradle.kts similarity index 100% rename from analyzer/src/functTest/resources/opentelemetry-kotlin-2/version.gradle.kts rename to analyzer/src/functTest/resources/opentelemetry-java-instrumentation/version.gradle.kts From 72165cfd5727d32ea3ae242279a0874f9e19088b Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Mon, 20 Jan 2025 10:11:50 +0000 Subject: [PATCH 3/6] Add opentelemetry 1.44.1 --- .../all/build.gradle.kts | 105 +++++++ .../animal-sniffer-signature/build.gradle.kts | 52 ++++ .../api/all/build.gradle.kts | 27 ++ .../api/build.gradle.kts | 10 + .../api/incubator/build.gradle.kts | 23 ++ .../api/incubator/gradle.properties | 1 + .../api/testing-internal/build.gradle.kts | 21 ++ .../bom-alpha/build.gradle.kts | 17 ++ .../bom-alpha/gradle.properties | 1 + .../bom/build.gradle.kts | 9 + .../opentelemetry-kotlin-2/build.gradle.kts | 63 ++++ .../buildSrc/build.gradle.kts | 79 ++++++ .../opentelemetry/gradle/OtelBomExtension.kt | 14 + .../opentelemetry/gradle/OtelJavaExtension.kt | 12 + .../gradle/OtelVersionClassPlugin.kt | 70 +++++ .../gradle/ProtoFieldsWireHandler.kt | 228 +++++++++++++++ .../gradle/ProtoFieldsWireHandlerFactory.kt | 17 ++ .../otel.animalsniffer-conventions.gradle.kts | 20 ++ .../kotlin/otel.bom-conventions.gradle.kts | 64 +++++ .../otel.errorprone-conventions.gradle.kts | 118 ++++++++ .../kotlin/otel.jacoco-conventions.gradle.kts | 53 ++++ .../otel.japicmp-conventions.gradle.kts | 197 +++++++++++++ .../kotlin/otel.java-conventions.gradle.kts | 268 ++++++++++++++++++ .../kotlin/otel.jmh-conventions.gradle.kts | 44 +++ .../otel.protobuf-conventions.gradle.kts | 36 +++ .../otel.publish-conventions.gradle.kts | 65 +++++ .../context/build.gradle.kts | 84 ++++++ .../custom-checks/build.gradle.kts | 82 ++++++ .../dependencyManagement/build.gradle.kts | 105 +++++++ .../extensions/build.gradle.kts | 10 + .../extensions/kotlin/build.gradle.kts | 63 ++++ .../trace-propagators/build.gradle.kts | 19 ++ .../opentelemetry-kotlin-2/gradle.properties | 14 + .../settings.gradle.kts | 110 +++++++ .../testing-internal/build.gradle.kts | 11 + .../opentelemetry-kotlin-2/version.gradle.kts | 13 + 36 files changed, 2125 insertions(+) create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/all/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/animal-sniffer-signature/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/all/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/incubator/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/incubator/gradle.properties create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/testing-internal/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/gradle.properties create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelBomExtension.kt create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelVersionClassPlugin.kt create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/ProtoFieldsWireHandler.kt create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/ProtoFieldsWireHandlerFactory.kt create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.bom-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.jacoco-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.jmh-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.protobuf-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.publish-conventions.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/context/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/custom-checks/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/dependencyManagement/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/kotlin/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/trace-propagators/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle.properties create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/settings.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/testing-internal/build.gradle.kts create mode 100644 analyzer/src/functTest/resources/opentelemetry-kotlin-2/version.gradle.kts diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/all/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/all/build.gradle.kts new file mode 100644 index 00000000..2cd16981 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/all/build.gradle.kts @@ -0,0 +1,105 @@ +plugins { + id("otel.java-conventions") +} + +description = "OpenTelemetry All" +otelJava.moduleName.set("io.opentelemetry.all") + +tasks { + // We don't compile much here, just some API boundary tests. This project is mostly for + // aggregating jacoco reports and it doesn't work if this isn't at least as high as the + // highest supported Java version in any of our projects. All of our + // projects target Java 8 except :exporters:http-sender:jdk, which targets + // Java 11 + withType(JavaCompile::class) { + options.release.set(11) + } + + val testJavaVersion: String? by project + if (testJavaVersion == "8") { + test { + enabled = false + } + } +} + +// Skip OWASP dependencyCheck task on test module +dependencyCheck { + skip = true +} + +val testTasks = mutableListOf() + +dependencies { + rootProject.subprojects.forEach { subproject -> + // Generate aggregate coverage report for published modules that enable jacoco. + subproject.plugins.withId("jacoco") { + subproject.plugins.withId("maven-publish") { + implementation(project(subproject.path)) { + isTransitive = false + } + subproject.tasks.withType().configureEach { + testTasks.add(this) + } + } + } + } + + testImplementation("com.tngtech.archunit:archunit-junit5") +} + +// https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html + +val sourcesPath by configurations.creating { + isVisible = false + isCanBeResolved = true + isCanBeConsumed = false + extendsFrom(configurations.implementation.get()) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders")) + } +} + +val coverageDataPath by configurations.creating { + isVisible = false + isCanBeResolved = true + isCanBeConsumed = false + extendsFrom(configurations.implementation.get()) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) + } +} + +tasks.named("jacocoTestReport") { + enabled = true + + dependsOn(testTasks) + + configurations.runtimeClasspath.get().forEach { + additionalClassDirs( + zipTree(it).filter { + // Exclude mrjar (jacoco complains), shaded, and generated code + !it.absolutePath.contains("META-INF/versions/") && + !it.absolutePath.contains("/internal/shaded/") && + !it.absolutePath.contains("io/opentelemetry/sdk/extension/trace/jaeger/proto/") && + !it.absolutePath.contains("AutoValue_") + }, + ) + } + additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files) + executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() }) + + reports { + // xml is usually used to integrate code coverage with + // other tools like SonarQube, Coveralls or Codecov + xml.required.set(true) + + // HTML reports can be used to see code coverage + // without any external tools + html.required.set(true) + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/animal-sniffer-signature/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/animal-sniffer-signature/build.gradle.kts new file mode 100644 index 00000000..f571179e --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/animal-sniffer-signature/build.gradle.kts @@ -0,0 +1,52 @@ +import ru.vyarus.gradle.plugin.animalsniffer.info.SignatureInfoTask +import ru.vyarus.gradle.plugin.animalsniffer.signature.BuildSignatureTask + +plugins { + id("otel.java-conventions") + id("ru.vyarus.animalsniffer") +} + +description = "Build tool to generate the Animal Sniffer Android signature" +otelJava.moduleName.set("io.opentelemetry.internal.animalsniffer") + +val signatureJar = configurations.create("signatureJar") { + isCanBeConsumed = false + isCanBeResolved = false +} +val signatureJarClasspath = configurations.create("signatureJarClasspath") { + isCanBeConsumed = false + isCanBeResolved = true + extendsFrom(signatureJar) +} +val generatedSignature = configurations.create("generatedSignature") { + isCanBeConsumed = true + isCanBeResolved = false +} +configurations.add(signatureJar) +configurations.add(signatureJarClasspath) +configurations.add(generatedSignature) + +dependencies { + signature("com.toasttab.android:gummy-bears-api-21:0.10.0@signature") + signatureJar("com.android.tools:desugar_jdk_libs") +} + +val signatureSimpleName = "android.signature" +val signatureBuilderTask = tasks.register("buildSignature", BuildSignatureTask::class.java) { + files(signatureJarClasspath) // All the jar files here will be added to the signature file. + signatures(configurations.signature) // We'll extend from the existing signatures added to this config. + outputName = signatureSimpleName // Name for the generated signature file. +} + +// Exposing the "generatedSignature" consumable config to be used in other subprojects +artifacts { + add("generatedSignature", project.provider { File(signatureBuilderTask.get().outputs.files.singleFile, signatureSimpleName) }) { + builtBy(signatureBuilderTask) + } +} + +// Utility task to show what's in the signature file +tasks.register("printSignature", SignatureInfoTask::class.java) { + signature = signatureBuilderTask.get().outputFiles + depth = 1 +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/all/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/all/build.gradle.kts new file mode 100644 index 00000000..ad689638 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/all/build.gradle.kts @@ -0,0 +1,27 @@ +plugins { + id("otel.java-conventions") + id("otel.publish-conventions") + + id("otel.jmh-conventions") + id("otel.animalsniffer-conventions") +} + +description = "OpenTelemetry API" +otelJava.moduleName.set("io.opentelemetry.api") +base.archivesName.set("opentelemetry-api") + +dependencies { + api(project(":context")) + + annotationProcessor("com.google.auto.value:auto-value") + + testImplementation(project(":api:testing-internal")) + + testImplementation("edu.berkeley.cs.jqf:jqf-fuzz") + testImplementation("com.google.guava:guava-testlib") +} + +tasks.test { + // Configure environment variable for ConfigUtilTest + environment("CONFIG_KEY", "environment") +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/build.gradle.kts new file mode 100644 index 00000000..facf4cf9 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/build.gradle.kts @@ -0,0 +1,10 @@ +subprojects { + // Workaround https://github.com/gradle/gradle/issues/847 + group = "io.opentelemetry.api" + val proj = this + plugins.withId("java") { + configure { + archivesName.set("opentelemetry-api-${proj.name}") + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/incubator/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/incubator/build.gradle.kts new file mode 100644 index 00000000..ce030485 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/incubator/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + id("otel.java-conventions") + id("otel.publish-conventions") + + id("otel.jmh-conventions") + id("otel.animalsniffer-conventions") +} + +description = "OpenTelemetry API Incubator" +otelJava.moduleName.set("io.opentelemetry.api.incubator") + +dependencies { + api(project(":api:all")) + + annotationProcessor("com.google.auto.value:auto-value") + +// testImplementation(project(":sdk:testing")) + testImplementation(project(":api:testing-internal")) + + testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating") + + testImplementation("com.google.guava:guava") +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/incubator/gradle.properties b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/incubator/gradle.properties new file mode 100644 index 00000000..4476ae57 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/incubator/gradle.properties @@ -0,0 +1 @@ +otel.release=alpha diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/testing-internal/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/testing-internal/build.gradle.kts new file mode 100644 index 00000000..b3e79cf0 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/api/testing-internal/build.gradle.kts @@ -0,0 +1,21 @@ +plugins { + id("otel.java-conventions") +} + +description = "OpenTelemetry API Testing (Internal)" +otelJava.moduleName.set("io.opentelemetry.api.testing.internal") + +dependencies { + api(project(":api:all")) + + implementation(project(":testing-internal")) + + implementation("com.linecorp.armeria:armeria-junit5") + implementation("org.assertj:assertj-core") + implementation("org.mockito:mockito-core") +} + +// Skip OWASP dependencyCheck task on test module +dependencyCheck { + skip = true +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/build.gradle.kts new file mode 100644 index 00000000..df363b28 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + id("otel.bom-conventions") +} + +description = "OpenTelemetry Bill of Materials (Alpha)" +group = "io.opentelemetry" +base.archivesName.set("opentelemetry-bom-alpha") + +otelBom.projectFilter.set { it.findProperty("otel.release") == "alpha" } + +// Required to place dependency on opentelemetry-bom +javaPlatform.allowDependencies() + +dependencies { + // Add dependency on opentelemetry-bom to ensure synchronization between alpha and stable artifacts + api(platform(project(":bom"))) +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/gradle.properties b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/gradle.properties new file mode 100644 index 00000000..4476ae57 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom-alpha/gradle.properties @@ -0,0 +1 @@ +otel.release=alpha diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom/build.gradle.kts new file mode 100644 index 00000000..50d8dc95 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/bom/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + id("otel.bom-conventions") +} + +description = "OpenTelemetry Bill of Materials" +group = "io.opentelemetry" +base.archivesName.set("opentelemetry-bom") + +otelBom.projectFilter.set { !it.hasProperty("otel.release") } diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts new file mode 100644 index 00000000..4ec7fd89 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts @@ -0,0 +1,63 @@ +import java.time.Duration + +plugins { + id("io.github.gradle-nexus.publish-plugin") +} + +apply(from = "version.gradle.kts") + +nexusPublishing { + packageGroup.set("io.opentelemetry") + + repositories { + sonatype { + username.set(System.getenv("SONATYPE_USER")) + password.set(System.getenv("SONATYPE_KEY")) + } + } + + connectTimeout.set(Duration.ofMinutes(5)) + clientTimeout.set(Duration.ofMinutes(5)) + + transitionCheckOptions { + // We have many artifacts so Maven Central takes a long time on its compliance checks. This sets + // the timeout for waiting for the repository to close to a comfortable 50 minutes. + maxRetries.set(300) + delayBetween.set(Duration.ofSeconds(10)) + } +} + +// The BOM projects register dependent tasks that actually do the generating. +tasks.register("generateBuildSubstitutions") { + group = "publishing" + description = "Generate a code snippet that can be copy-pasted for use in composite builds." +} + +subprojects { + group = "io.opentelemetry" +} + +tasks { + register("updateVersionInDocs") { + group = "documentation" + doLast { + val version = findProperty("release.version") + val versionParts = version.toString().split('.') + val minorVersionNumber = Integer.parseInt(versionParts[1]) + val nextSnapshot = "${versionParts[0]}.${minorVersionNumber + 1}.0-SNAPSHOT" + + val readme = file("README.md") + if (readme.exists()) { + val readmeText = readme.readText() + val updatedText = readmeText + .replace("""\d+\.\d+\.\d+""".toRegex(), "$version") + .replace("""\d+\.\d+\.\d+-SNAPSHOT""".toRegex(), "$nextSnapshot") + .replace("""(implementation.*io\.opentelemetry:.*:)(\d+\.\d+\.\d+)(?!-SNAPSHOT)(.*)""".toRegex(), "\$1${version}\$3") + .replace("""(implementation.*io\.opentelemetry:.*:)(\d+\.\d+\.\d+-SNAPSHOT)(.*)""".toRegex(), "\$1${nextSnapshot}\$3") + .replace(""".*""".toRegex(), "$version") + .replace(""".*""".toRegex(), "$version-alpha") + readme.writeText(updatedText) + } + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/build.gradle.kts new file mode 100644 index 00000000..ca9e459c --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/build.gradle.kts @@ -0,0 +1,79 @@ +plugins { + `kotlin-dsl` + + // When updating, update below in dependencies too + id("com.diffplug.spotless") version "6.25.0" +} + +if (!hasLauncherForJavaVersion(11)) { + throw GradleException( + "JDK 17 is required to build and gradle was unable to detect it on the system. " + + "Please install it and see https://docs.gradle.org/current/userguide/toolchains.html#sec:auto_detection " + + "for details on how gradle detects java toolchains." + ) +} + +fun hasLauncherForJavaVersion(version: Int): Boolean { + return try { + javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(version) }.get() + true + } catch (e: Exception) { + false + } +} + +spotless { + kotlinGradle { + ktlint().editorConfigOverride(mapOf( + "indent_size" to "2", + "continuation_indent_size" to "2", + "max_line_length" to "160", + "insert_final_newline" to "true", + "ktlint_standard_no-wildcard-imports" to "disabled", + // ktlint does not break up long lines, it just fails on them + "ktlint_standard_max-line-length" to "disabled", + // ktlint makes it *very* hard to locate where this actually happened + "ktlint_standard_trailing-comma-on-call-site" to "disabled", + // depends on ktlint_standard_wrapping + "ktlint_standard_trailing-comma-on-declaration-site" to "disabled", + // also very hard to find out where this happens + "ktlint_standard_wrapping" to "disabled" + )) + target("**/*.gradle.kts") + } +} + +repositories { + mavenCentral() + gradlePluginPortal() + mavenLocal() +} + +dependencies { + implementation(enforcedPlatform("com.squareup.wire:wire-bom:5.1.0")) + implementation("com.google.auto.value:auto-value-annotations:1.11.0") + // When updating, update above in plugins too + implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0") + // Needed for japicmp but not automatically brought in for some reason. + implementation("com.google.guava:guava:33.3.1-jre") + implementation("com.squareup:javapoet:1.13.0") + implementation("com.squareup.wire:wire-compiler") + implementation("com.squareup.wire:wire-gradle-plugin") + implementation("gradle.plugin.com.google.protobuf:protobuf-gradle-plugin:0.8.18") + implementation("gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.6") + implementation("me.champeau.gradle:japicmp-gradle-plugin:0.4.5") + implementation("me.champeau.jmh:jmh-gradle-plugin:0.7.2") + implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.1.0") + implementation("net.ltgt.gradle:gradle-nullaway-plugin:2.1.0") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21") + implementation("org.owasp:dependency-check-gradle:11.1.0") + implementation("ru.vyarus:gradle-animalsniffer-plugin:1.7.1") +} + +// We can't apply conventions to this build so include important ones such as the Java compilation +// target. +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelBomExtension.kt b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelBomExtension.kt new file mode 100644 index 00000000..5857b998 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelBomExtension.kt @@ -0,0 +1,14 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.gradle + +import org.gradle.api.Project +import org.gradle.api.provider.Property +import java.util.function.Predicate + +abstract class OtelBomExtension { + abstract val projectFilter: Property> +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt new file mode 100644 index 00000000..bf584e71 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt @@ -0,0 +1,12 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.gradle + +import org.gradle.api.provider.Property + +abstract class OtelJavaExtension { + abstract val moduleName: Property +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelVersionClassPlugin.kt b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelVersionClassPlugin.kt new file mode 100644 index 00000000..1eaa042a --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelVersionClassPlugin.kt @@ -0,0 +1,70 @@ +package io.opentelemetry.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.kotlin.dsl.the +import java.io.File + +/** + * This gradle plugin will define a new task called generateOtelVersionClass. + * This task generates a Java source file that contains the project version + * as a string constant. The "compileJava" task is updated to depend on + * generateOtelVersionClass, and the project source set is updated to + * include the new file. + */ +class OtelVersionClassPlugin : Plugin { + override fun apply(project: Project) { + project.plugins.apply(JavaPlugin::class.java) + + project.task("generateOtelVersionClass") { + doLast { + writeFile(project) + } + } + // Add dependency on this task + project.tasks.getByName("compileJava") { + dependsOn("generateOtelVersionClass") + } + // Add new source dir to the "main" source set + val outDir = buildOutDir(project) + val java = project.the() + java.sourceSets.getByName("main").java { + srcDir(outDir) + } + } + + private fun writeFile(project: Project) { + val group = "${project.group}".replace('.', '/') + val projectName = project.name.replace('-', '/') + val outDir = buildOutDir(project) + val filename = "$group/$projectName/internal/OtelVersion.java" + val outFile = File(outDir, filename) + val packageName = "${project.group}.${project.name.replace('-', '.')}.internal" + val classBody = getClassBody("${project.version}", packageName) + + outFile.parentFile.mkdirs() + outFile.writeText(classBody) + } + + private fun getClassBody(version: String, packageName: String): String { + return """ + package $packageName; + + import javax.annotation.Generated; + + /** Autogenerated class do not edit. */ + @Generated("io.opentelemetry.gradle.OtelVersionClassPlugin") + public final class OtelVersion { + public static final String VERSION = "$version"; + + private OtelVersion() {} + } + """.trimIndent() + } + + private fun buildOutDir(project: Project): File { + return File(project.layout.buildDirectory.asFile.get(), "generated/sources/version/java/main") + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/ProtoFieldsWireHandler.kt b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/ProtoFieldsWireHandler.kt new file mode 100644 index 00000000..c24e9031 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/ProtoFieldsWireHandler.kt @@ -0,0 +1,228 @@ +package io.opentelemetry.gradle + +import com.squareup.javapoet.ClassName +import com.squareup.javapoet.FieldSpec +import com.squareup.javapoet.JavaFile +import com.squareup.javapoet.TypeName +import com.squareup.javapoet.TypeSpec +import com.squareup.wire.WireCompiler +import com.squareup.wire.WireLogger +import com.squareup.wire.schema.EnumType +import com.squareup.wire.schema.Extend +import com.squareup.wire.schema.Field +import com.squareup.wire.schema.MessageType +import com.squareup.wire.schema.ProfileLoader +import com.squareup.wire.schema.ProtoFile +import com.squareup.wire.schema.ProtoType +import com.squareup.wire.schema.Schema +import com.squareup.wire.schema.SchemaHandler +import com.squareup.wire.schema.Service +import com.squareup.wire.schema.Target +import com.squareup.wire.schema.Type +import okio.IOException +import okio.FileSystem +import okio.Path +import okio.Path.Companion.toPath +import javax.lang.model.element.Modifier.FINAL +import javax.lang.model.element.Modifier.PUBLIC +import javax.lang.model.element.Modifier.STATIC + +// Wire proto compiler provides this convenient interface for customizing the output of proto +// compilation. We use it to generate classes that only contain field numbers and enum values, which +// we use in our custom Marshaler from SDK types to OTLP types, skipping the otherwise hefty +// generated protoc code. +// +// Inspired by https://github.com/square/wire/blob/5fac94f86879fdd7e412cddbeb51e09a708b2b64/wire-library/wire-compiler/src/main/java/com/squareup/wire/schema/Target.kt#L152 +class ProtoFieldsWireHandler : SchemaHandler() { + + private var schema: Schema?= null + private var javaGenerator: JavaGenerator?= null + + override fun handle(schema: Schema, context: Context) { + if (this.schema != null && this.schema != schema) { + throw IllegalStateException("Cannot use same handler with multiple schemas") + } + if (this.schema == null) { + this.schema = schema + this.javaGenerator = JavaGenerator.get(schema) + } + super.handle(schema, context) + } + + override fun handle(service: Service, context: Context): List = emptyList() + + override fun handle(extend: Extend, field: Field, context: Context): Path? = null + + override fun handle(type: Type, context: Context): Path? { + val fs = context.fileSystem + val outDirectory = context.outDirectory + + val typeSpec = javaGenerator!!.generateType(type, false) + val javaTypeName = javaGenerator!!.generatedTypeName(type) + + if (typeSpec == null) { + return null + } + + val javaFile = JavaFile.builder(javaTypeName.packageName(), typeSpec) + .addFileComment("\$L", WireCompiler.CODE_GENERATED_BY_WIRE) + .addFileComment("\nSource: \$L in \$L", type.type, type.location.withPathOnly()) + .build() + val generatedFilePath = outDirectory / javaFile.packageName / "${javaFile.typeSpec.name}.java" + + val filePath = outDirectory / + javaFile.packageName.replace(".", "/") / + "${javaTypeName.simpleName()}.java" + + try { + fs.createDirectories(filePath.parent!!) + fs.write(filePath) { + writeUtf8(javaFile.toString()) + } + } catch (e: IOException) { + throw IOException("Error emitting ${javaFile.packageName}.${javaFile.typeSpec.name} " + + "to $outDirectory", e) + } + return generatedFilePath + } + + private class JavaGenerator(private val schema: Schema, private val typeToJavaName: Map) { + + companion object { + private val PROTO_FIELD_INFO = ClassName.get("io.opentelemetry.exporter.internal.marshal", "ProtoFieldInfo") + private val PROTO_ENUM_INFO = ClassName.get("io.opentelemetry.exporter.internal.marshal", "ProtoEnumInfo") + private val WIRETYPE_VARINT = 0 + private val WIRETYPE_FIXED64 = 1 + private val WIRETYPE_LENGTH_DELIMITED = 2 + private val WIRETYPE_FIXED32 = 5 + + fun get(schema: Schema): JavaGenerator { + val nameToJavaName = linkedMapOf() + for (protoFile in schema.protoFiles) { + if (protoFile.location.path == "wire/extensions.proto") { + continue + } + val javaPackage = javaPackage(protoFile) + putAll(nameToJavaName, javaPackage, null, protoFile.types) + } + + return JavaGenerator(schema, nameToJavaName) + } + + private fun putAll( + wireToJava: MutableMap, + javaPackage: String, + enclosingClassName: ClassName?, + types: List) { + for (type in types) { + val className = enclosingClassName?.let { + it.nestedClass(type.type.simpleName) + } ?: ClassName.get(javaPackage, type.type.simpleName) + wireToJava[type.type] = className + putAll(wireToJava, javaPackage, className, type.nestedTypes) + } + } + + private fun javaPackage(protoFile: ProtoFile): String { + val javaPackage = protoFile.javaPackage() + if (javaPackage == null) { + throw IOException("Attempting to generate Java for proto without java_package") + } + // Just append .internal to the defined package to hold our trimmed ones. + return "${javaPackage}.internal" + } + } + + fun generateType(type: Type, nested: Boolean): TypeSpec? { + if (type is MessageType) { + return generateMessage(type, nested) + } + if (type is EnumType) { + return generateEnum(type, nested) + } + return null + } + + fun generatedTypeName(type: Type): ClassName { + return typeToJavaName[type.type] as ClassName + } + + private fun generateMessage(type: MessageType, nested: Boolean): TypeSpec { + val javaType = typeToJavaName[type.type] as ClassName + + val builder = TypeSpec.classBuilder(javaType.simpleName()) + .addModifiers(PUBLIC, FINAL) + if (nested) { + builder.addModifiers(STATIC) + } + + for (field in type.fieldsAndOneOfFields) { + builder.addField( + FieldSpec.builder(PROTO_FIELD_INFO, field.name.uppercase(), PUBLIC, STATIC, FINAL) + .initializer("\$T.create(\$L, \$L, \"\$L\")", + PROTO_FIELD_INFO, + field.tag, + makeTag(field.tag, field.type as ProtoType, field.isRepeated), + field.jsonName) + .build()) + } + + for (nestedType in type.nestedTypes) { + builder.addType(generateType(nestedType, true)) + } + + return builder.build() + } + + private fun generateEnum(type: EnumType, nested: Boolean): TypeSpec { + val javaType = typeToJavaName[type.type] as ClassName + + val builder = TypeSpec.classBuilder(javaType.simpleName()) + .addModifiers(PUBLIC, FINAL) + if (nested) { + builder.addModifiers(STATIC) + } + + for (constant in type.constants) { + builder.addField( + FieldSpec.builder(PROTO_ENUM_INFO, constant.name, PUBLIC, STATIC, FINAL) + .initializer("\$T.create(\$L, \"\$L\")", PROTO_ENUM_INFO, constant.tag, constant.name) + .build()) + } + + return builder.build() + } + + private fun fieldEncoding(type: ProtoType, isRepeated: Boolean): Int { + if (isRepeated) { + // Repeated fields are always length delimited in proto3 + return WIRETYPE_LENGTH_DELIMITED + } + + if (schema.getType(type) is EnumType) { + return WIRETYPE_VARINT + } + + if (!type.isScalar) { + // Non-scalar and not enum is a message + return WIRETYPE_LENGTH_DELIMITED + } + + return when(type) { + ProtoType.FIXED32, + ProtoType.SFIXED32, + ProtoType.FLOAT-> WIRETYPE_FIXED32 + ProtoType.FIXED64, + ProtoType.SFIXED64, + ProtoType.DOUBLE -> WIRETYPE_FIXED64 + ProtoType.BYTES, + ProtoType.STRING -> WIRETYPE_LENGTH_DELIMITED + else -> WIRETYPE_VARINT + } + } + + private fun makeTag(fieldNumber: Int, type: ProtoType, isRepeated: Boolean): Int { + return (fieldNumber shl 3) or fieldEncoding(type, isRepeated) + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/ProtoFieldsWireHandlerFactory.kt b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/ProtoFieldsWireHandlerFactory.kt new file mode 100644 index 00000000..cd99a69d --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/io/opentelemetry/gradle/ProtoFieldsWireHandlerFactory.kt @@ -0,0 +1,17 @@ +package io.opentelemetry.gradle + +import com.squareup.wire.schema.SchemaHandler + +class ProtoFieldsWireHandlerFactory : SchemaHandler.Factory{ + + override fun create( + includes: List, + excludes: List, + exclusive: Boolean, + outDirectory: String, + options: Map + ): SchemaHandler { + return ProtoFieldsWireHandler() + } + +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts new file mode 100644 index 00000000..73bbf0dd --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.animalsniffer-conventions.gradle.kts @@ -0,0 +1,20 @@ +import ru.vyarus.gradle.plugin.animalsniffer.AnimalSniffer + +plugins { + `java-library` + + id("ru.vyarus.animalsniffer") +} + +dependencies { + signature(project(path = ":animal-sniffer-signature", configuration = "generatedSignature")) +} + +animalsniffer { + sourceSets = listOf(java.sourceSets.main.get()) +} + +tasks.withType { + // always having declared output makes this task properly participate in tasks up-to-date checks + reports.text.required.set(true) +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.bom-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.bom-conventions.gradle.kts new file mode 100644 index 00000000..43674ccc --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.bom-conventions.gradle.kts @@ -0,0 +1,64 @@ +import io.opentelemetry.gradle.OtelBomExtension +import org.gradle.kotlin.dsl.create + +plugins { + id("otel.publish-conventions") + id("java-platform") +} + +if (!project.name.startsWith("bom")) { + throw IllegalStateException("Name of BOM projects must start with 'bom'.") +} + +rootProject.subprojects.forEach { subproject -> + if (!subproject.name.startsWith("bom")) { + evaluationDependsOn(subproject.path) + } +} +val otelBom = extensions.create("otelBom") + +val generateBuildSubstitutions by tasks.registering { + group = "publishing" + description = "Generate a code snippet that can be copy-pasted for use in composite builds." +} + +tasks.named("publish") { + dependsOn(generateBuildSubstitutions) +} + +rootProject.tasks.named(generateBuildSubstitutions.name) { + dependsOn(generateBuildSubstitutions) +} + +afterEvaluate { + otelBom.projectFilter.finalizeValue() + val bomProjects = rootProject.subprojects + .sortedBy { it.findProperty("archivesName") as String? } + .filter { !it.name.startsWith("bom") } + .filter(otelBom.projectFilter.get()::test) + .filter { it.plugins.hasPlugin("maven-publish") } + + generateBuildSubstitutions { + val outputFile = File(layout.buildDirectory.asFile.get(), "substitutions.gradle.kts") + outputs.file(outputFile) + val substitutionSnippet = bomProjects.joinToString( + separator = "\n", + prefix = "dependencySubstitution {\n", + postfix = "\n}\n", + ) { project -> + val publication = project.publishing.publications.getByName("mavenPublication") as MavenPublication + " substitute(module(\"${publication.groupId}:${publication.artifactId}\")).using(project(\"${project.path}\"))" + } + inputs.property("projectPathsAndArtifactCoordinates", substitutionSnippet) + doFirst { + outputFile.writeText(substitutionSnippet) + } + } + bomProjects.forEach { project -> + dependencies { + constraints { + api(project) + } + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts new file mode 100644 index 00000000..be908aaa --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts @@ -0,0 +1,118 @@ +import net.ltgt.gradle.errorprone.CheckSeverity +import net.ltgt.gradle.errorprone.errorprone +import net.ltgt.gradle.nullaway.nullaway + +plugins { + id("net.ltgt.errorprone") + id("net.ltgt.nullaway") +} + +dependencies { + errorprone("com.google.errorprone:error_prone_core") + errorprone("com.uber.nullaway:nullaway") + errorprone(project(":custom-checks")) +} + +val disableErrorProne = properties["disableErrorProne"]?.toString()?.toBoolean() ?: false + +tasks { + withType().configureEach { + with(options) { + errorprone { + if (disableErrorProne) { + logger.warn("Errorprone has been disabled. Build may not result in a valid PR build.") + isEnabled.set(false) + } + + disableWarningsInGeneratedCode.set(true) + allDisabledChecksAsWarnings.set(true) + + // Ignore warnings for generated and vendored classes + excludedPaths.set(".*/build/generated/.*|.*/internal/shaded/.*") + + // Still Java 8 + disable("Varifier") + + // Doesn't currently use Var annotations. + disable("Var") // "-Xep:Var:OFF" + + // ImmutableRefactoring suggests using com.google.errorprone.annotations.Immutable, + // but currently uses javax.annotation.concurrent.Immutable + disable("ImmutableRefactoring") + + // AutoValueImmutableFields suggests returning Guava types from API methods + disable("AutoValueImmutableFields") + // Suggests using Guava types for fields but we don't use Guava + disable("ImmutableMemberCollection") + + // Fully qualified names may be necessary when deprecating a class to avoid + // deprecation warning. + disable("UnnecessarilyFullyQualified") + + // We use animal sniffer + disable("Java7ApiChecker") + disable("Java8ApiChecker") + disable("AndroidJdkLibsChecker") + + // apparently disabling android doesn't disable this + disable("StaticOrDefaultInterfaceMethod") + + // Limits APIs + disable("PreferredInterfaceType") + + // We don't depend on Guava so use normal splitting + disable("StringSplitter") + + // Prevents lazy initialization + disable("InitializeInline") + + // Seems to trigger even when a deprecated method isn't called anywhere. + // We don't get much benefit from it anyways. + disable("InlineMeSuggester") + + // We have nullaway so don't need errorprone nullable checks which have more false positives. + disable("FieldMissingNullable") + disable("ParameterMissingNullable") + disable("ReturnMissingNullable") + disable("VoidMissingNullable") + + // Only used in comments, but couldn't SuppressWarnings for some reason + disable("UnicodeEscape") + + // We make liberal use of builders returning "this" which can be safely ignored. Annotating + // every one of these methods is too noisy. + disable("CanIgnoreReturnValueSuggester") + + // YodaConditions may improve safety in some cases. The argument of increased + // cognitive load is dubious. + disable("YodaCondition") + + if ((name.contains("Jmh") || name.contains("Test") || project.name.contains("testing-internal")) && !project.name.equals("custom-checks")) { + // Allow underscore in test-type method names + disable("MemberName") + // Internal javadoc not needed for test or jmh classes + disable("OtelInternalJavadoc") + } + + option("NullAway:CustomContractAnnotations", "io.opentelemetry.api.internal.Contract") + } + + with(options) { + errorprone.nullaway { + annotatedPackages.add("io.opentelemetry") + // Disable nullaway by default, we enable for main sources below. + severity.set(CheckSeverity.OFF) + } + } + } + } + + // Enable nullaway on main sources. + named("compileJava") { + with(options) { + errorprone.nullaway { + severity.set(CheckSeverity.ERROR) + } + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.jacoco-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.jacoco-conventions.gradle.kts new file mode 100644 index 00000000..c99788df --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.jacoco-conventions.gradle.kts @@ -0,0 +1,53 @@ +plugins { + `java-library` + + jacoco +} + +jacoco { + toolVersion = "0.8.12" +} + +// https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html + +// Do not generate reports for individual projects +tasks.named("jacocoTestReport") { + enabled = false +} + +configurations { + val implementation by getting + + create("transitiveSourceElements") { + isVisible = false + isCanBeResolved = false + isCanBeConsumed = true + extendsFrom(implementation) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders")) + } + sourceSets.main.get().java.srcDirs.forEach { + outgoing.artifact(it) + } + } + + create("coverageDataElements") { + isVisible = false + isCanBeResolved = false + isCanBeConsumed = true + extendsFrom(implementation) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) + } + // This will cause the test task to run if the coverage data is requested by the aggregation task + // The tasks must be eagerly evaluated (no configureEach) to ensure jacoco is wired up + // correctly. + tasks.withType() { + outgoing.artifact(the().destinationFile!!) + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts new file mode 100644 index 00000000..08dc25cf --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.japicmp-conventions.gradle.kts @@ -0,0 +1,197 @@ +import com.google.auto.value.AutoValue +import japicmp.model.* +import me.champeau.gradle.japicmp.JapicmpTask +import me.champeau.gradle.japicmp.report.Violation +import me.champeau.gradle.japicmp.report.stdrules.* + + +plugins { + base + + id("me.champeau.gradle.japicmp") +} + +/** + * The latest *released* version of the project. Evaluated lazily so the work is only done if necessary. + */ +val latestReleasedVersion: String by lazy { + // hack to find the current released version of the project + val temp: Configuration = configurations.create("tempConfig") + // pick the api, since it's always there. + dependencies.add(temp.name, "io.opentelemetry:opentelemetry-api:latest.release") + val moduleVersion = configurations["tempConfig"].resolvedConfiguration.firstLevelModuleDependencies.elementAt(0).moduleVersion + configurations.remove(temp) + logger.debug("Discovered latest release version: " + moduleVersion) + moduleVersion +} + +class AllowNewAbstractMethodOnAutovalueClasses : AbstractRecordingSeenMembers() { + override fun maybeAddViolation(member: JApiCompatibility): Violation? { + val allowableAutovalueChanges = setOf(JApiCompatibilityChangeType.METHOD_ABSTRACT_ADDED_TO_CLASS, JApiCompatibilityChangeType.METHOD_ADDED_TO_PUBLIC_CLASS) + if (member.compatibilityChanges.filter { !allowableAutovalueChanges.contains(it.type) }.isEmpty() && + member is JApiMethod && isAutoValueClass(member.getjApiClass())) + { + return Violation.accept(member, "Autovalue will automatically add implementation") + } + if (member.compatibilityChanges.isEmpty() && + member is JApiClass && isAutoValueClass(member)) { + return Violation.accept(member, "Autovalue class modification is allowed") + } + return null + } + + fun isAutoValueClass(japiClass: JApiClass): Boolean { + return japiClass.newClass.get().getAnnotation(AutoValue::class.java) != null || + japiClass.newClass.get().getAnnotation(AutoValue.Builder::class.java) != null + } +} + +class SourceIncompatibleRule : AbstractRecordingSeenMembers() { + + fun ignoreAddLogRecordProcessorCustomizerReturnTypeChange(member: JApiCompatibility): Violation? { + if (member is JApiClass && + member.newClass.get().name.equals("io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder") && + member.isChangeCausedByClassElement + ) { + // member.isChangeCausedByClassElement check above + // limits source of changes to fields, methods and constructors + + for (method in member.methods) { + if (!method.isSourceCompatible()) { + // addLogRecordProcessorCustomizer method had a return type change from base to impl class, + // japicmp (correctly) doesn't consider it as a METHOD_RETURN_TYPE_CHANGED + // compatibility issue. But still thinks that something wrong. + // Since it thinks that method did not change, it reports it as class-level violation, + // and we need to suppress it, but keep other checks on. + if (method.name.equals("addLogRecordProcessorCustomizer") && + method.compatibilityChanges.isEmpty() && + method.changeStatus == JApiChangeStatus.UNCHANGED) { + return null; + } + return Violation.error(method, "Method is not source compatible: $method") + } + } + + for (field in member.fields) { + if (!field.isSourceCompatible()) { + return Violation.error(field, "Field is not source compatible: $field") + } + } + + for (constructor in member.constructors) { + if (!constructor.isSourceCompatible()) { + return Violation.error(constructor, "Constructor is not source compatible: $constructor") + } + } + } + + return Violation.error(member, "Not source compatible: $member") + } + + override fun maybeAddViolation(member: JApiCompatibility): Violation? { + if (!member.isSourceCompatible()) { + // TODO: remove after 1.36.0 is released, see https://github.com/open-telemetry/opentelemetry-java/pull/6248 + if (member.compatibilityChanges.isEmpty()) { + return ignoreAddLogRecordProcessorCustomizerReturnTypeChange(member) + } + // end of suppression + + return Violation.error(member, "Not source compatible: $member") + } + return null + } +} + +/** + * Locate the project's artifact of a particular version. + */ +fun findArtifact(version: String): File { + val existingGroup = group + try { + // Temporarily change the group name because we want to fetch an artifact with the same + // Maven coordinates as the project, which Gradle would not allow otherwise. + group = "virtual_group" + val depModule = "io.opentelemetry:${base.archivesName.get()}:$version@jar" + val depJar = "${base.archivesName.get()}-$version.jar" + val configuration: Configuration = configurations.detachedConfiguration( + dependencies.create(depModule), + ) + return files(configuration.files).filter { + it.name.equals(depJar) + }.singleFile + } finally { + group = existingGroup + } +} + +// generate the api diff report for any module that is stable and publishes a jar. +if (!project.hasProperty("otel.release") && !project.name.startsWith("bom")) { + afterEvaluate { + tasks { + val jApiCmp by registering(JapicmpTask::class) { + dependsOn("jar") + + // the japicmp "new" version is either the user-specified one, or the locally built jar. + val apiNewVersion: String? by project + val newArtifact = apiNewVersion?.let { findArtifact(it) } + ?: file(getByName("jar").archiveFile) + newClasspath.from(files(newArtifact)) + + // only output changes, not everything + onlyModified.set(true) + + // the japicmp "old" version is either the user-specified one, or the latest release. + val apiBaseVersion: String? by project + val baselineVersion = apiBaseVersion ?: latestReleasedVersion + oldClasspath.from( + try { + files(findArtifact(baselineVersion)) + } catch (e: Exception) { + // if we can't find the baseline artifact, this is probably one that's never been published before, + // so publish the whole API. We do that by flipping this flag, and comparing the current against nothing. + onlyModified.set(false) + files() + }, + ) + + // Reproduce defaults from https://github.com/melix/japicmp-gradle-plugin/blob/09f52739ef1fccda6b4310cf3f4b19dc97377024/src/main/java/me/champeau/gradle/japicmp/report/ViolationsGenerator.java#L130 + // with some changes. + val exclusions = mutableListOf() + // Generics are not detected correctly + exclusions.add("CLASS_GENERIC_TEMPLATE_CHANGED") + // Allow new default methods on interfaces + exclusions.add("METHOD_NEW_DEFAULT") + // Allow adding default implementations for default methods + exclusions.add("METHOD_ABSTRACT_NOW_DEFAULT") + // Bug prevents recognizing default methods of superinterface. + // Fixed in https://github.com/siom79/japicmp/pull/343 but not yet available in me.champeau.gradle.japicmp + exclusions.add("METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE") + compatibilityChangeExcludes.set(exclusions) + richReport { + addSetupRule(RecordSeenMembersSetup::class.java) + addRule(JApiChangeStatus.NEW, SourceCompatibleRule::class.java) + addRule(JApiChangeStatus.MODIFIED, SourceCompatibleRule::class.java) + addRule(JApiChangeStatus.UNCHANGED, UnchangedMemberRule::class.java) + // Allow new abstract methods on autovalue + addRule(AllowNewAbstractMethodOnAutovalueClasses::class.java) + addRule(BinaryIncompatibleRule::class.java) + // Disallow source incompatible changes, which are allowed by default for some reason + addRule(SourceIncompatibleRule::class.java) + } + + // this is needed so that we only consider the current artifact, and not dependencies + ignoreMissingClasses.set(true) + packageExcludes.addAll("*.internal", "*.internal.*", "io.opentelemetry.internal.shaded.jctools.*") + val baseVersionString = if (apiBaseVersion == null) "latest" else baselineVersion + txtOutputFile.set( + apiNewVersion?.let { file("$rootDir/docs/apidiffs/${apiNewVersion}_vs_$baselineVersion/${base.archivesName.get()}.txt") } + ?: file("$rootDir/docs/apidiffs/current_vs_$baseVersionString/${base.archivesName.get()}.txt"), + ) + } + // have the check task depend on the api comparison task, to make it more likely it will get used. + named("check") { + dependsOn(jApiCmp) + } + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts new file mode 100644 index 00000000..2e2bb42d --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts @@ -0,0 +1,268 @@ +import io.opentelemetry.gradle.OtelJavaExtension +import org.gradle.api.tasks.testing.logging.TestExceptionFormat + +plugins { + `java-library` + + checkstyle + eclipse + idea + + id("otel.errorprone-conventions") + id("otel.jacoco-conventions") + id("org.owasp.dependencycheck") +} + +val otelJava = extensions.create("otelJava") + +base { + // May be set already by a parent project, only set if not. + // TODO(anuraaga): Make this less hacky by creating a "module group" plugin. + if (!archivesName.get().startsWith("opentelemetry-")) { + archivesName.set("opentelemetry-$name") + } +} + +// normalize timestamps and file ordering in jars, making the outputs reproducible +// see open-telemetry/opentelemetry-java#4488 +tasks.withType().configureEach { + isPreserveFileTimestamps = false + isReproducibleFileOrder = true +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } + + withJavadocJar() + withSourcesJar() +} + +checkstyle { + configDirectory.set(file("$rootDir/buildscripts/")) + toolVersion = "10.20.1" + isIgnoreFailures = false + configProperties["rootDir"] = rootDir +} + +dependencyCheck { + skipConfigurations = mutableListOf( + "errorprone", + "checkstyle", + "annotationProcessor", + "java9AnnotationProcessor", + "moduleAnnotationProcessor", + "testAnnotationProcessor", + "testJpmsAnnotationProcessor", + "animalsniffer", + "spotless996155815", // spotless996155815 is a weird configuration that's only added in jaeger-proto, jaeger-remote-sampler + "js2p", + "jmhAnnotationProcessor", + "jmhBasedTestAnnotationProcessor", + "jmhCompileClasspath", + "jmhRuntimeClasspath", + "jmhRuntimeOnly") + failBuildOnCVSS = 7.0f // fail on high or critical CVE + analyzers.assemblyEnabled = false // not sure why its trying to analyze .NET assemblies +} + +val testJavaVersion = gradle.startParameter.projectProperties.get("testJavaVersion")?.let(JavaVersion::toVersion) + +tasks { + withType().configureEach { + with(options) { + release.set(8) + + if (name != "jmhCompileGeneratedClasses") { + compilerArgs.addAll( + listOf( + "-Xlint:all", + // We suppress the "try" warning because it disallows managing an auto-closeable with + // try-with-resources without referencing the auto-closeable within the try block. + "-Xlint:-try", + // We suppress the "processing" warning as suggested in + // https://groups.google.com/forum/#!topic/bazel-discuss/_R3A9TJSoPM + "-Xlint:-processing", + // We suppress the "options" warning because it prevents compilation on modern JDKs + "-Xlint:-options", + // Fail build on any warning + "-Werror", + ), + ) + } + + encoding = "UTF-8" + + if (name.contains("Test")) { + // serialVersionUID is basically guaranteed to be useless in tests + compilerArgs.add("-Xlint:-serial") + } + } + } + + withType().configureEach { + useJUnitPlatform() + + if (testJavaVersion != null) { + javaLauncher.set( + javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(testJavaVersion.majorVersion)) + }, + ) + } + + testLogging { + exceptionFormat = TestExceptionFormat.FULL + showExceptions = true + showCauses = true + showStackTraces = true + + showStandardStreams = true + } + maxHeapSize = "1500m" + } + + withType().configureEach { + exclude("io/opentelemetry/**/internal/**") + + with(options as StandardJavadocDocletOptions) { + source = "8" + encoding = "UTF-8" + docEncoding = "UTF-8" + breakIterator(true) + + addBooleanOption("html5", true) + + // TODO (trask) revisit to see if url is fixed + // currently broken because https://docs.oracle.com/javase/8/docs/api/element-list is missing + // and redirects + // links("https://docs.oracle.com/javase/8/docs/api/") + + addBooleanOption("Xdoclint:all,-missing", true) + } + } + + withType().configureEach { + inputs.property("moduleName", otelJava.moduleName) + + manifest { + attributes( + "Automatic-Module-Name" to otelJava.moduleName, + "Built-By" to System.getProperty("user.name"), + "Built-JDK" to System.getProperty("java.version"), + "Implementation-Title" to project.name, + "Implementation-Version" to project.version, + ) + } + } + + afterEvaluate { + withType().configureEach { + with(options as StandardJavadocDocletOptions) { + val title = "${project.description}" + docTitle = title + windowTitle = title + } + } + } +} + +// Add version information to published artifacts. +plugins.withId("otel.publish-conventions") { + tasks { + register("generateVersionResource") { + val moduleName = otelJava.moduleName + val propertiesDir = moduleName.map { File(layout.buildDirectory.asFile.get(), "generated/properties/${it.replace('.', '/')}") } + + inputs.property("project.version", project.version.toString()) + outputs.dir(propertiesDir) + + doLast { + File(propertiesDir.get(), "version.properties").writeText("sdk.version=${project.version}") + } + } + } + + sourceSets { + main { + output.dir("${layout.buildDirectory.asFile.get()}/generated/properties", "builtBy" to "generateVersionResource") + } + } +} + +configurations.configureEach { + resolutionStrategy { + failOnVersionConflict() + preferProjectModules() + } +} + +val dependencyManagement by configurations.creating { + isCanBeConsumed = false + isCanBeResolved = false + isVisible = false +} + +dependencies { + dependencyManagement(platform(project(":dependencyManagement"))) + afterEvaluate { + configurations.configureEach { + if (isCanBeResolved && !isCanBeConsumed) { + extendsFrom(dependencyManagement) + } + } + } + + compileOnly("com.google.auto.value:auto-value-annotations") + compileOnly("com.google.code.findbugs:jsr305") + + annotationProcessor("com.google.guava:guava-beta-checker") + + // Workaround for @javax.annotation.Generated + // see: https://github.com/grpc/grpc-java/issues/3633 + compileOnly("javax.annotation:javax.annotation-api") + + modules { + // checkstyle uses the very old google-collections which causes Java 9 module conflict with + // guava which is also on the classpath + module("com.google.collections:google-collections") { + replacedBy("com.google.guava:guava", "google-collections is now part of Guava") + } + } +} + +testing { + suites.withType(JvmTestSuite::class).configureEach { + dependencies { + implementation(project(project.path)) + + implementation(project(":testing-internal")) + + compileOnly("com.google.auto.value:auto-value-annotations") + compileOnly("com.google.errorprone:error_prone_annotations") + compileOnly("com.google.code.findbugs:jsr305") + + implementation("org.junit.jupiter:junit-jupiter-api") + implementation("org.junit.jupiter:junit-jupiter-params") + implementation("nl.jqno.equalsverifier:equalsverifier") + implementation("org.mockito:mockito-core") + implementation("org.mockito:mockito-junit-jupiter") + implementation("org.assertj:assertj-core") + implementation("org.awaitility:awaitility") + implementation("org.junit-pioneer:junit-pioneer") + implementation("io.github.netmikey.logunit:logunit-jul") + + runtimeOnly("org.junit.jupiter:junit-jupiter-engine") + runtimeOnly("org.slf4j:slf4j-simple") + } + + targets { + all { + testTask.configure { + systemProperty("java.util.logging.config.class", "io.opentelemetry.internal.testing.slf4j.JulBridgeInitializer") + } + } + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.jmh-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.jmh-conventions.gradle.kts new file mode 100644 index 00000000..3e4ad431 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.jmh-conventions.gradle.kts @@ -0,0 +1,44 @@ +plugins { + id("me.champeau.jmh") + id("io.morethan.jmhreport") +} + +dependencies { + jmh(platform(project(":dependencyManagement"))) + jmh("org.openjdk.jmh:jmh-core") + jmh("org.openjdk.jmh:jmh-generator-bytecode") + + // This enables running JMH benchmark classes within IntelliJ using + // JMH plugins + jmh("org.openjdk.jmh:jmh-generator-annprocess") + jmhAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess") +} + +// invoke jmh on a single benchmark class like so: +// ./gradlew -PjmhIncludeSingleClass=StatsTraceContextBenchmark clean :grpc-core:jmh +jmh { + failOnError.set(true) + resultFormat.set("JSON") + // Otherwise an error will happen: + // Could not expand ZIP 'byte-buddy-agent-1.9.7.jar'. + includeTests.set(false) + profilers.add("gc") + val jmhIncludeSingleClass: String? by project + if (jmhIncludeSingleClass != null) { + includes.add(jmhIncludeSingleClass as String) + } +} + +jmhReport { + val buildDirectory = layout.buildDirectory.asFile.get() + jmhResultPath = file("$buildDirectory/results/jmh/results.json").absolutePath + jmhReportOutput = file("$buildDirectory/results/jmh").absolutePath +} + +tasks { + named("jmh") { + finalizedBy(named("jmhReport")) + + outputs.cacheIf { false } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.protobuf-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.protobuf-conventions.gradle.kts new file mode 100644 index 00000000..905545d2 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.protobuf-conventions.gradle.kts @@ -0,0 +1,36 @@ +import com.google.protobuf.gradle.* + +plugins { + id("otel.java-conventions") + + id("com.google.protobuf") +} + +protobuf { + val versions: Map by project + protoc { + // The artifact spec for the Protobuf Compiler + artifact = "com.google.protobuf:protoc:${versions["com.google.protobuf"]}" + } + plugins { + id("grpc") { + artifact = "io.grpc:protoc-gen-grpc-java:${versions["io.grpc"]}" + } + } + generateProtoTasks { + all().configureEach { + plugins { + id("grpc") + } + } + } +} + +afterEvaluate { + // Classpath when compiling protos, we add dependency management directly + // since it doesn't follow Gradle conventions of naming / properties. + dependencies { + add("compileProtoPath", platform(project(":dependencyManagement"))) + add("testCompileProtoPath", platform(project(":dependencyManagement"))) + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.publish-conventions.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.publish-conventions.gradle.kts new file mode 100644 index 00000000..cc8cf3a0 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/src/main/kotlin/otel.publish-conventions.gradle.kts @@ -0,0 +1,65 @@ +plugins { + `maven-publish` + signing + + id("otel.japicmp-conventions") +} + +publishing { + publications { + register("mavenPublication") { + groupId = "io.opentelemetry" + afterEvaluate { + // not available until evaluated. + artifactId = base.archivesName.get() + pom.description.set(project.description) + } + + plugins.withId("java-platform") { + from(components["javaPlatform"]) + } + plugins.withId("java-library") { + from(components["java"]) + } + + versionMapping { + allVariants { + fromResolutionResult() + } + } + + pom { + name.set("OpenTelemetry Java") + url.set("https://github.com/open-telemetry/opentelemetry-java") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + + developers { + developer { + id.set("opentelemetry") + name.set("OpenTelemetry") + url.set("https://github.com/open-telemetry/community") + } + } + + scm { + connection.set("scm:git:git@github.com:open-telemetry/opentelemetry-java.git") + developerConnection.set("scm:git:git@github.com:open-telemetry/opentelemetry-java.git") + url.set("git@github.com:open-telemetry/opentelemetry-java.git") + } + } + } + } +} + +if (System.getenv("CI") != null) { + signing { + useInMemoryPgpKeys(System.getenv("GPG_PRIVATE_KEY"), System.getenv("GPG_PASSWORD")) + sign(publishing.publications["mavenPublication"]) + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/context/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/context/build.gradle.kts new file mode 100644 index 00000000..6c8fa638 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/context/build.gradle.kts @@ -0,0 +1,84 @@ +plugins { + id("otel.java-conventions") + id("otel.publish-conventions") + + id("otel.jmh-conventions") + id("otel.animalsniffer-conventions") +} + +description = "OpenTelemetry Context (Incubator)" +otelJava.moduleName.set("io.opentelemetry.context") + +dependencies { + // MustBeClosed + compileOnly("com.google.errorprone:error_prone_annotations") + + testImplementation("com.google.guava:guava") +} + +dependencyCheck { + skipConfigurations.add("braveInOtelTestAnnotationProcessor") + skipConfigurations.add("grpcInOtelTestAnnotationProcessor") + skipConfigurations.add("otelAsBraveTestAnnotationProcessor") + skipConfigurations.add("otelInBraveTestAnnotationProcessor") + skipConfigurations.add("otelInGrpcTestAnnotationProcessor") + skipConfigurations.add("storageWrappersTestAnnotationProcessor") + skipConfigurations.add("strictContextEnabledTestAnnotationProcessor") +} + +testing { + suites { + register("grpcInOtelTest") { + dependencies { + implementation("io.grpc:grpc-api") + } + } + + register("otelInGrpcTest") { + dependencies { + implementation("io.grpc:grpc-api") + } + } + + register("braveInOtelTest") { + dependencies { + implementation("io.zipkin.brave:brave") + } + } + + register("otelInBraveTest") { + dependencies { + implementation("io.zipkin.brave:brave") + } + } + + register("otelAsBraveTest") { + dependencies { + implementation("io.zipkin.brave:brave") + } + } + + register("storageWrappersTest") { + } + + register("strictContextEnabledTest") { + dependencies { + implementation(project(":api:all")) + } + + targets { + all { + testTask.configure { + jvmArgs("-Dio.opentelemetry.context.enableStrictContext=true") + } + } + } + } + } +} + +tasks { + check { + dependsOn(testing.suites) + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/custom-checks/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/custom-checks/build.gradle.kts new file mode 100644 index 00000000..5167a979 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/custom-checks/build.gradle.kts @@ -0,0 +1,82 @@ +plugins { + id("otel.java-conventions") +} + +dependencies { + implementation("com.google.errorprone:error_prone_core") + + testImplementation("com.google.errorprone:error_prone_test_helpers") +} + +otelJava.moduleName.set("io.opentelemetry.javaagent.customchecks") + +// We cannot use "--release" javac option here because that will forbid exporting com.sun.tools package. +// We also can't seem to use the toolchain without the "--release" option. So disable everything. + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + toolchain { + languageVersion.set(null as JavaLanguageVersion?) + } +} + +tasks { + withType().configureEach { + with(options) { + release.set(null as Int?) + + compilerArgs.addAll( + listOf( + "--add-exports", + "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + "--add-exports", + "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-exports", + "jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", + "--add-exports", + "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports", + "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + ), + ) + } + } + + // only test on java 17+ + val testJavaVersion: String? by project + if (testJavaVersion != null && Integer.valueOf(testJavaVersion) < 17) { + test { + enabled = false + } + } +} + +tasks.withType().configureEach { + // required on jdk17 + jvmArgs("--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED") + jvmArgs("--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED") + jvmArgs("--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED") + jvmArgs("--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED") + jvmArgs("--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED") + jvmArgs("--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED") + jvmArgs("--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED") + jvmArgs("--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED") + jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") +} + +tasks.withType().configureEach { + // using com.sun.tools.javac.api.JavacTrees breaks javadoc generation + enabled = false +} + +// Our conventions apply this project as a dependency in the errorprone configuration, which would cause +// a circular dependency if trying to compile this project with that still there. So we filter this +// project out. +configurations { + named("errorprone") { + dependencies.removeIf { + it is ProjectDependency && it.dependencyProject == project + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/dependencyManagement/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/dependencyManagement/build.gradle.kts new file mode 100644 index 00000000..5d89c61c --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/dependencyManagement/build.gradle.kts @@ -0,0 +1,105 @@ +plugins { + `java-platform` +} + +data class DependencySet(val group: String, val version: String, val modules: List) + +val dependencyVersions = hashMapOf() +rootProject.extra["versions"] = dependencyVersions + +val DEPENDENCY_BOMS = listOf( + "com.fasterxml.jackson:jackson-bom:2.18.1", + "com.google.guava:guava-bom:33.3.1-jre", + "com.google.protobuf:protobuf-bom:3.25.5", + "com.linecorp.armeria:armeria-bom:1.30.1", + "com.squareup.okhttp3:okhttp-bom:4.12.0", + "com.squareup.okio:okio-bom:3.9.1", // applies to transitive dependencies of okhttp + "io.grpc:grpc-bom:1.68.1", + "io.netty:netty-bom:4.1.114.Final", + "io.zipkin.brave:brave-bom:6.0.3", + "io.zipkin.reporter2:zipkin-reporter-bom:3.4.2", + "org.assertj:assertj-bom:3.26.3", + "org.junit:junit-bom:5.11.3", + "org.testcontainers:testcontainers-bom:1.20.3", + "org.snakeyaml:snakeyaml-engine:2.8" +) + +val autoValueVersion = "1.11.0" +val errorProneVersion = "2.35.1" +val jmhVersion = "1.37" +// Mockito 5.x.x requires Java 11 https://github.com/mockito/mockito/releases/tag/v5.0.0 +val mockitoVersion = "4.11.0" +val slf4jVersion = "2.0.16" +val opencensusVersion = "0.31.1" +val prometheusClientVersion = "0.16.0" + +val DEPENDENCIES = listOf( + "com.google.auto.value:auto-value:${autoValueVersion}", + "com.google.auto.value:auto-value-annotations:${autoValueVersion}", + "com.google.errorprone:error_prone_annotations:${errorProneVersion}", + "com.google.errorprone:error_prone_core:${errorProneVersion}", + "com.google.errorprone:error_prone_test_helpers:${errorProneVersion}", + "io.opencensus:opencensus-api:${opencensusVersion}", + "io.opencensus:opencensus-impl-core:${opencensusVersion}", + "io.opencensus:opencensus-impl:${opencensusVersion}", + "io.opencensus:opencensus-exporter-metrics-util:${opencensusVersion}", + "io.opencensus:opencensus-contrib-exemplar-util:${opencensusVersion}", + "org.openjdk.jmh:jmh-core:${jmhVersion}", + "org.openjdk.jmh:jmh-generator-bytecode:${jmhVersion}", + "org.openjdk.jmh:jmh-generator-annprocess:${jmhVersion}", + "org.mockito:mockito-core:${mockitoVersion}", + "org.mockito:mockito-junit-jupiter:${mockitoVersion}", + "org.slf4j:slf4j-simple:${slf4jVersion}", + "org.slf4j:jul-to-slf4j:${slf4jVersion}", + "io.prometheus:prometheus-metrics-shaded-protobuf:1.3.1", + "io.prometheus:simpleclient:${prometheusClientVersion}", + "io.prometheus:simpleclient_common:${prometheusClientVersion}", + "io.prometheus:simpleclient_httpserver:${prometheusClientVersion}", + "javax.annotation:javax.annotation-api:1.3.2", + "com.github.stefanbirkner:system-rules:1.19.0", + "com.google.api.grpc:proto-google-common-protos:2.48.0", + "com.google.code.findbugs:jsr305:3.0.2", + "com.google.guava:guava-beta-checker:1.0", + "com.sun.net.httpserver:http:20070405", + "com.tngtech.archunit:archunit-junit5:1.3.0", + "com.uber.nullaway:nullaway:0.12.1", + "edu.berkeley.cs.jqf:jqf-fuzz:1.7", // jqf-fuzz version 1.8+ requires Java 11+ + "eu.rekawek.toxiproxy:toxiproxy-java:2.1.7", + "io.github.netmikey.logunit:logunit-jul:2.0.0", + "io.jaegertracing:jaeger-client:1.8.1", + "io.opentelemetry.contrib:opentelemetry-aws-xray-propagator:1.39.0-alpha", + "io.opentelemetry.semconv:opentelemetry-semconv-incubating:1.28.0-alpha", + "io.opentelemetry.proto:opentelemetry-proto:1.3.2-alpha", + "io.opentracing:opentracing-api:0.33.0", + "io.opentracing:opentracing-noop:0.33.0", + "io.prometheus:prometheus-metrics-exporter-httpserver:1.3.3", + "junit:junit:4.13.2", + "nl.jqno.equalsverifier:equalsverifier:3.17.3", + "org.awaitility:awaitility:4.2.2", + "org.bouncycastle:bcpkix-jdk15on:1.70", + "org.codehaus.mojo:animal-sniffer-annotations:1.24", + "org.jctools:jctools-core:4.0.5", + "org.junit-pioneer:junit-pioneer:1.9.1", + "org.mock-server:mockserver-netty:5.15.0:shaded", + "org.skyscreamer:jsonassert:1.5.3", + "com.android.tools:desugar_jdk_libs:2.1.3", +) + +javaPlatform { + allowDependencies() +} + +dependencies { + for (bom in DEPENDENCY_BOMS) { + api(enforcedPlatform(bom)) + val split = bom.split(':') + dependencyVersions[split[0]] = split[2] + } + constraints { + for (dependency in DEPENDENCIES) { + api(dependency) + val split = dependency.split(':') + dependencyVersions[split[0]] = split[2] + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/build.gradle.kts new file mode 100644 index 00000000..f0744dfe --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/build.gradle.kts @@ -0,0 +1,10 @@ +subprojects { + // Workaround https://github.com/gradle/gradle/issues/847 + group = "io.opentelemetry.extensions" + val proj = this + plugins.withId("java") { + configure { + archivesName.set("opentelemetry-extension-${proj.name}") + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/kotlin/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/kotlin/build.gradle.kts new file mode 100644 index 00000000..f423ca36 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/kotlin/build.gradle.kts @@ -0,0 +1,63 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("otel.java-conventions") + id("otel.publish-conventions") + + id("otel.jmh-conventions") + id("org.jetbrains.kotlin.jvm") + id("otel.animalsniffer-conventions") +} + +description = "OpenTelemetry Kotlin Extensions" +otelJava.moduleName.set("io.opentelemetry.extension.kotlin") + +dependencies { + implementation(platform("org.jetbrains.kotlin:kotlin-bom")) + + api(project(":api:all")) + + compileOnly("org.jetbrains.kotlin:kotlin-stdlib-common") + compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") + +// testImplementation(project(":sdk:testing")) + testImplementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") +} + +testing { + suites { + register("testStrictContext") { + dependencies { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2") + } + + targets { + all { + testTask.configure { + jvmArgs("-Dio.opentelemetry.context.enableStrictContext=true") + } + } + } + } + } +} + +tasks { + withType(KotlinCompile::class) { + kotlinOptions { + jvmTarget = "1.8" + languageVersion = "1.6" + } + } + + // We don't have any public Java classes + named("javadoc") { + enabled = false + } + + check { + dependsOn(testing.suites) + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/trace-propagators/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/trace-propagators/build.gradle.kts new file mode 100644 index 00000000..cf5a87bb --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/extensions/trace-propagators/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("otel.java-conventions") + id("otel.publish-conventions") + + id("otel.animalsniffer-conventions") + id("otel.jmh-conventions") +} + +description = "OpenTelemetry Extension : Trace Propagators" +otelJava.moduleName.set("io.opentelemetry.extension.trace.propagation") + +dependencies { + api(project(":api:all")) + +// compileOnly(project(":sdk-extensions:autoconfigure-spi")) + + testImplementation("io.jaegertracing:jaeger-client") + testImplementation("com.google.guava:guava") +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle.properties b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle.properties new file mode 100644 index 00000000..b7fce695 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/gradle.properties @@ -0,0 +1,14 @@ +org.gradle.parallel=true + +org.gradle.priority=low + +# Gradle default is 256m which causes issues with our build - https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory +org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m + +# Try to reduce CI failures due to maven central flakiness +# in particular this has been a problem for maven-metadata.xml files, which are TTL'd quickly out of +# the gradle cache since they contain the latest versions available in maven central +systemProp.org.gradle.internal.http.connectionTimeout=120000 +systemProp.org.gradle.internal.http.socketTimeout=120000 +systemProp.org.gradle.internal.repository.max.retries=10 +systemProp.org.gradle.internal.repository.initial.backoff=500 diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/settings.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/settings.gradle.kts new file mode 100644 index 00000000..3c3854ad --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/settings.gradle.kts @@ -0,0 +1,110 @@ +pluginManagement { + plugins { + id("com.gradleup.shadow") version "8.3.5" + id("com.gradle.develocity") version "3.18.1" + id("de.undercouch.download") version "5.6.0" + id("org.jsonschema2pojo") version "1.2.2" + id("io.github.gradle-nexus.publish-plugin") version "2.0.0" + id("org.graalvm.buildtools.native") version "0.10.3" + } +} + +plugins { + id("com.gradle.develocity") +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + google() + mavenLocal() + } +} + +rootProject.name = "opentelemetry-java" +include(":all") +include(":api:all") +include(":api:incubator") +include(":api:testing-internal") +include(":bom") +include(":bom-alpha") +include(":context") +include(":custom-checks") +include(":dependencyManagement") +include(":extensions:kotlin") +include(":extensions:trace-propagators") + +// include(":exporters:common") +// include(":exporters:common:compile-stub") +// include(":exporters:sender:grpc-managed-channel") +// include(":exporters:sender:jdk") +// include(":exporters:sender:okhttp") +// include(":exporters:logging") +// include(":exporters:logging-otlp") +// include(":exporters:otlp:all") +// include(":exporters:otlp:common") +// include(":exporters:otlp:profiles") +// include(":exporters:otlp:testing-internal") +// include(":exporters:prometheus") +// include(":exporters:zipkin") + +// include(":integration-tests") +// include(":integration-tests:otlp") +// include(":integration-tests:tracecontext") +// include(":integration-tests:graal") +// include(":integration-tests:graal-incubating") +// include(":opencensus-shim") +// include(":opentracing-shim") +// include(":perf-harness") +// include(":sdk:all") +// include(":sdk:common") +// include(":sdk:logs") +// include(":sdk:metrics") +// include(":sdk:testing") +// include(":sdk:trace") +// include(":sdk:trace-shaded-deps") +// include(":sdk-extensions:autoconfigure") +// include(":sdk-extensions:autoconfigure-spi") +// include(":sdk-extensions:incubator") +// include(":sdk-extensions:jaeger-remote-sampler") +include(":testing-internal") +include(":animal-sniffer-signature") + +val gradleEnterpriseServer = "https://ge.opentelemetry.io" +val isCI = System.getenv("CI") != null +val geAccessKey = System.getenv("GRADLE_ENTERPRISE_ACCESS_KEY") ?: "" + +// if GE access key is not given and we are in CI, then we publish to scans.gradle.com +val useScansGradleCom = isCI && geAccessKey.isEmpty() + +if (useScansGradleCom) { + develocity { + buildScan { + termsOfUseUrl.set("https://gradle.com/terms-of-service") + termsOfUseAgree.set("yes") + uploadInBackground.set(!isCI) + publishing.onlyIf { true } + + capture { + fileFingerprints.set(true) + } + } + } +} else { + develocity { + server = gradleEnterpriseServer + buildScan { + uploadInBackground.set(!isCI) + publishing.onlyIf { + it.isAuthenticated + } + + capture { + fileFingerprints.set(true) + } + + gradle.startParameter.projectProperties["testJavaVersion"]?.let { tag(it) } + gradle.startParameter.projectProperties["testJavaVM"]?.let { tag(it) } + } + } +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/testing-internal/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/testing-internal/build.gradle.kts new file mode 100644 index 00000000..6a0cd952 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/testing-internal/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("otel.java-conventions") +} + +description = "OpenTelemetry Testing (Internal)" +otelJava.moduleName.set("io.opentelemetry.internal.testing") + +dependencies { + api("org.junit.jupiter:junit-jupiter-api") + implementation("org.slf4j:jul-to-slf4j") +} diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/version.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/version.gradle.kts new file mode 100644 index 00000000..7ee10b23 --- /dev/null +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/version.gradle.kts @@ -0,0 +1,13 @@ +val snapshot = false + +allprojects { + var ver = "1.44.1" + val release = findProperty("otel.release") + if (release != null) { + ver += "-" + release + } + if (snapshot) { + ver += "-SNAPSHOT" + } + version = ver +} From 600c2c526c8ef7ffd1eb7fc1e8a5f2f734550968 Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Mon, 20 Jan 2025 11:32:02 +0000 Subject: [PATCH 4/6] Use JDK11 for OpenTelemetry --- .../buildSrc/build.gradle.kts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/build.gradle.kts index ca9e459c..369e9fc7 100644 --- a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/build.gradle.kts +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/buildSrc/build.gradle.kts @@ -5,22 +5,22 @@ plugins { id("com.diffplug.spotless") version "6.25.0" } -if (!hasLauncherForJavaVersion(11)) { - throw GradleException( - "JDK 17 is required to build and gradle was unable to detect it on the system. " + - "Please install it and see https://docs.gradle.org/current/userguide/toolchains.html#sec:auto_detection " + - "for details on how gradle detects java toolchains." - ) -} +// if (!hasLauncherForJavaVersion(11)) { +// throw GradleException( +// "JDK 17 is required to build and gradle was unable to detect it on the system. " + +// "Please install it and see https://docs.gradle.org/current/userguide/toolchains.html#sec:auto_detection " + +// "for details on how gradle detects java toolchains." +// ) +// } -fun hasLauncherForJavaVersion(version: Int): Boolean { - return try { - javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(version) }.get() - true - } catch (e: Exception) { - false - } -} +// fun hasLauncherForJavaVersion(version: Int): Boolean { +// return try { +// javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(version) }.get() +// true +// } catch (e: Exception) { +// false +// } +// } spotless { kotlinGradle { @@ -72,8 +72,8 @@ dependencies { // We can't apply conventions to this build so include important ones such as the Java compilation // target. -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } -} +// java { +// toolchain { +// languageVersion.set(JavaLanguageVersion.of(17)) +// } +// } From 9a1d5a32466decdff1874799deebed7a153bf5f6 Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Mon, 20 Jan 2025 11:41:51 +0000 Subject: [PATCH 5/6] NCLSUP-1188 Improve constraint handling --- .../gm/analyzer/alignment/AlignmentTask.java | 69 ++----------------- 1 file changed, 5 insertions(+), 64 deletions(-) diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java index 452f392b..56d45618 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java @@ -633,22 +633,6 @@ private Map getDependencies(Project Configuration internalConfig, Set lockFileDeps) { - // if (!constraint) { - // constraint = project.getConfigurations().stream() - // .anyMatch(config -> // try { - // // || Class.forName( - // // "org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint_Decorated") - // // .isInstance(obj) - // // } catch (ClassNotFoundException e) { - // // throw new RuntimeException(e); - // // } - // config - // .getAllDependencyConstraints().stream() - // .anyMatch(AlignmentTask::isDefaultProjectDependencyConstraint)); - // // .anyMatch(AlignmentTask::isDefaultProjectDependencyConstraint)); - // } - // logger.warn("### In project {} constraint found {} in class {}", project.getName(), constraint , System.identityHashCode()); - final Map depMap = new LinkedHashMap<>(); project.getConfigurations().all(configuration -> { logger.warn("### project {} configuration {} canbeConsumed {} canberesolved {} visible {} canbedeclared {}", @@ -657,40 +641,10 @@ private Map getDependencies(Project configuration.isCanBeConsumed(), configuration.isCanBeResolved(), configuration.isVisible()); - // configuration.isCanBeDeclared()); // canBeResolved: Indicates that this configuration is intended for resolving a set of dependencies into a dependency graph. A resolvable configuration should not be declarable or consumable. if (configuration.isCanBeResolved()) { - - final Boolean anyConstraints = configuration.getAllDependencyConstraints().isEmpty(); - logger.warn( - "###@@@ For project {} examining configuration {} with consume {} and any constraint {} and defaultproject constraint {} ", - project.getName(), - configuration.getName(), configuration.isCanBeConsumed(), anyConstraints, cache.isConstraints()); - logger.trace("Examining configuration {}", configuration.getName()); - // https://docs.gradle.org/current/userguide/declaring_configurations.html - - // if (!configuration.isCanBeConsumed() - // && (configuration.getName().toLowerCase().endsWith("compileclasspath") || - // configuration.getName().toLowerCase().endsWith("runtimeclasspath")) - // - // /*&& !configuration.isCanBeDeclared()*/) { - // logger.warn("Not altering configuration for {} under {}", configuration.getName(), project.getName()); - // return; - // - // } - // Boolean classpathConfiguration = false; - // if ( - // //constraint - // /*&& GradleVersion.current().compareTo(GradleVersion.version("8.0")) >= 0*/ - // // && !configuration.isCanBeConsumed() - // (configuration.getName().equalsIgnoreCase("runtimeClasspath") || - // configuration.getName().equalsIgnoreCase("compileClasspath"))) { - // logger.warn("Not altering configuration for {} under {}", configuration.getName(), project.getName()); - // classpathConfiguration = true; - // } - // // using getAllDependencies here instead of getDependencies because the latter // was returning an empty array for the root project of SpringLikeLayoutFunctionalTest final DependencySet allDependencies = configuration.getAllDependencies(); @@ -715,38 +669,25 @@ private Map getDependencies(Project // NCLSUP-1188: to avoid "Dependency constraints can not be declared against the `compileClasspath` configuration" // we now avoid recursive copying if constraints are active in any configuration in any subproject. if (!cache.isConstraints()) { + logger.info("Found dependency constraints in {}", configuration.getName()); cache.setConstraints(configuration.getAllDependencyConstraints().stream() .anyMatch(AlignmentTask::isDefaultProjectDependencyConstraint)); } - logger.warn("### In project {} constraint found {} in class {}", project.getName(), cache.isConstraints(), - System.identityHashCode(AlignmentTask.class)); LenientConfiguration lenient; org.gradle.api.artifacts.Configuration copy; // Attempt to call copyRecursive for all types (kotlin/gradle). - // if (!cache.isConstraints() - if (configuration - .getAllDependencyConstraints().stream() - .noneMatch(AlignmentTask::isDefaultProjectDependencyConstraint)) { - // if (!constraint) { - // if (!configuration.isCanBeDeclared() && - // !classpathConfiguration && - // configuration + if (!cache.isConstraints()) { + // if (configuration // .getAllDependencyConstraints().stream() // .noneMatch(AlignmentTask::isDefaultProjectDependencyConstraint)) { - // !configuration.isCanBeDeclared() && - // !classpathConfiguration && - // configuration - // .getAllDependencyConstraints().stream() - // .noneMatch(AlignmentTask::isDefaultProjectDependencyConstraint) - // ) { + logger.debug("Recursively copying configuration for {}", configuration.getName()); copy = configuration.copyRecursive(); lenient = copy.getResolvedConfiguration().getLenientConfiguration(); } else { logger.debug( - "DefaultProjectDependencyConstraint found ({}), not recursively copying configuration", - configuration.getAllDependencyConstraints()); + "DefaultProjectDependencyConstraint found, not recursively copying configuration"); copy = configuration.copy(); lenient = copy.getResolvedConfiguration().getLenientConfiguration(); } From 74bfc3fa531418eaf02bb6de03dc42a73d13fbf4 Mon Sep 17 00:00:00 2001 From: Nick Cross Date: Mon, 20 Jan 2025 15:29:36 +0000 Subject: [PATCH 6/6] NCLSUP-1188 Add integration test and improve fix --- .../OpenTelemetryFunctionalTest.java | 64 +++++++++++++++++++ .../opentelemetry-kotlin-2/build.gradle.kts | 4 ++ .../resources/spring-like-layout-da-root.json | 6 ++ .../gm/analyzer/alignment/AlignmentTask.java | 51 +++++++-------- .../jboss/gm/common/ManipulationCache.java | 3 +- 5 files changed, 102 insertions(+), 26 deletions(-) diff --git a/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java b/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java index e27a82a3..7ae11339 100644 --- a/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java +++ b/analyzer/src/functTest/java/org/jboss/gm/analyzer/alignment/OpenTelemetryFunctionalTest.java @@ -203,4 +203,68 @@ public void verifyOpenTelemetryJavaInstrumentationKotlin() throws Exception { assertThat(systemOutRule.getLog()).contains("Found archivesBaseName override ; resetting project name " + "'benchmark-overhead-jmh' to 'opentelemetry-benchmark-overhead-jmh'"); } + + @Test + public void verifyOpenTelemetryKotlin2() throws IOException, URISyntaxException, ManipulationException { + // XXX: Use of pluginManagement.plugins{} + assumeTrue(GradleVersion.current().compareTo(GradleVersion.version("8.5")) >= 0); + final Map map = new HashMap<>(); + map.put("-DoverrideTransitive", "false"); + map.put("-Potel.stable", "true"); + map.put("-DignoreUnresolvableDependencies", "true"); + + final File projectRoot = tempDir.newFolder("opentelemetry-kotlin-2"); + final TestManipulationModel alignmentModel = TestUtils.align(projectRoot, projectRoot.getName(), map); + + assertTrue(new File(projectRoot, AlignmentTask.GME).exists()); + assertEquals(AlignmentTask.INJECT_GME_START_KOTLIN + " }", TestUtils.getLine(projectRoot)); + assertEquals(AlignmentTask.INJECT_GME_END_KOTLIN, + FileUtils.getLastLine(new File(projectRoot, Project.DEFAULT_BUILD_FILE + ".kts"))); + + assertThat(alignmentModel).isNotNull().satisfies(am -> { + assertThat(am.getGroup()).isEqualTo("io.opentelemetry"); + assertThat(am.getName()).isEqualTo("opentelemetry-java"); + assertThat(am.getVersion()).isEqualTo("1.44.1.redhat-00001"); + assertThat(am.getOriginalVersion()).isEqualTo("1.44.1"); + + assertThat(am.getChildren().keySet()).hasSize(10).containsExactlyInAnyOrder( + "all", + "animal-sniffer-signature", + "api", + "bom", + "bom-alpha", + "context", + "custom-checks", + "dependencyManagement", + "extensions", + "testing-internal"); + + assertThat(am.getChildren().get("bom")) + .hasToString("io.opentelemetry:opentelemetry-bom:1.44.1.redhat-00001"); + assertThat(am.getChildren().get("api")).hasToString("io.opentelemetry:api:1.44.1.redhat-00001"); + + assertThat(am.findCorrespondingChild("bom")).satisfies(root -> { + assertThat(root.getVersion()).isEqualTo("1.44.1.redhat-00001"); + assertThat(root.getAlignedDependencies()).isEmpty(); + }); + + assertThat(am.findCorrespondingChild("bom-alpha")).satisfies(root -> { + assertThat(root.getVersion()).isEqualTo("1.44.1.alpha-redhat-00001"); + assertThat(root.getOriginalVersion()).isEqualTo("1.44.1-alpha"); + assertThat(root.getAlignedDependencies()).isEmpty(); + }); + + assertThat(am.findCorrespondingChild(":api:all")).satisfies(root -> { + assertThat(root.getVersion()).isEqualTo("1.44.1.redhat-00001"); + final Collection alignedDependencies = root.getAlignedDependencies().values(); + assertThat(alignedDependencies) + .extracting("artifactId", "versionString") + .containsOnly( + tuple("protobuf-bom", "3.25.5-redhat-00001")); + }); + }); + + verify(1, postRequestedFor(urlEqualTo("/da/rest/v-1/" + DefaultTranslator.Endpoint.LOOKUP_GAVS))); + assertThat(systemOutRule.getLog()).contains("io.opentelemetry:bom:1.44.1"); + } } diff --git a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts index 4ec7fd89..3748272a 100644 --- a/analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts +++ b/analyzer/src/functTest/resources/opentelemetry-kotlin-2/build.gradle.kts @@ -2,6 +2,8 @@ import java.time.Duration plugins { id("io.github.gradle-nexus.publish-plugin") + + id("org.jboss.gm.analyzer") } apply(from = "version.gradle.kts") @@ -35,6 +37,8 @@ tasks.register("generateBuildSubstitutions") { subprojects { group = "io.opentelemetry" + + apply(plugin = "org.jboss.gm.analyzer") } tasks { diff --git a/analyzer/src/functTest/resources/spring-like-layout-da-root.json b/analyzer/src/functTest/resources/spring-like-layout-da-root.json index 18bfe32a..c98d398c 100644 --- a/analyzer/src/functTest/resources/spring-like-layout-da-root.json +++ b/analyzer/src/functTest/resources/spring-like-layout-da-root.json @@ -16,5 +16,11 @@ "version": "3.14.0", "groupId": "com.google.protobuf", "artifactId": "protobuf-bom" + }, + { + "bestMatchVersion": "3.25.5-redhat-00001", + "version": "3.25.5", + "groupId": "com.google.protobuf", + "artifactId": "protobuf-bom" } ] diff --git a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java index 56d45618..2f08ae20 100644 --- a/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java +++ b/analyzer/src/main/java/org/jboss/gm/analyzer/alignment/AlignmentTask.java @@ -48,6 +48,7 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.DependencyConstraintSet; import org.gradle.api.artifacts.DependencySet; import org.gradle.api.artifacts.LenientConfiguration; import org.gradle.api.artifacts.ModuleVersionIdentifier; @@ -635,26 +636,10 @@ private Map getDependencies(Project final Map depMap = new LinkedHashMap<>(); project.getConfigurations().all(configuration -> { - logger.warn("### project {} configuration {} canbeConsumed {} canberesolved {} visible {} canbedeclared {}", - project.getName(), - configuration.getName(), - configuration.isCanBeConsumed(), - configuration.isCanBeResolved(), - configuration.isVisible()); - // canBeResolved: Indicates that this configuration is intended for resolving a set of dependencies into a dependency graph. A resolvable configuration should not be declarable or consumable. if (configuration.isCanBeResolved()) { - // https://docs.gradle.org/current/userguide/declaring_configurations.html - // using getAllDependencies here instead of getDependencies because the latter - // was returning an empty array for the root project of SpringLikeLayoutFunctionalTest - final DependencySet allDependencies = configuration.getAllDependencies(); - final Set allProjectDependencies = allDependencies - .stream() - .filter(d -> ProjectDependency.class.isAssignableFrom(d.getClass())) - .map(ProjectDependency.class::cast) - .collect(Collectors.toSet()); - ProjectUtils.updateResolutionStrategy(configuration); + logger.trace("Examining configuration {}", configuration.getName()); // If we have dependency constraints we can get a ClassCastException when attempting to copy the configurations. // This is due to an unchecked cast in @@ -669,25 +654,42 @@ private Map getDependencies(Project // NCLSUP-1188: to avoid "Dependency constraints can not be declared against the `compileClasspath` configuration" // we now avoid recursive copying if constraints are active in any configuration in any subproject. if (!cache.isConstraints()) { - logger.info("Found dependency constraints in {}", configuration.getName()); - cache.setConstraints(configuration.getAllDependencyConstraints().stream() - .anyMatch(AlignmentTask::isDefaultProjectDependencyConstraint)); + DependencyConstraintSet allConstraints = configuration.getAllDependencyConstraints(); + // Extremely bizarrely but a simple stream like allConstraints.stream().anyMatch + // fails without a preceding allConstraints.isEmpty call. This alternative also + // appears to work and satisfies lazy configuration handling. + allConstraints.configureEach(c -> { + if (isDefaultProjectDependencyConstraint(c)) { + logger.info("Found dependency constraints in {}", configuration.getName()); + cache.setConstraints(true); + } + }); } + // https://docs.gradle.org/current/userguide/declaring_configurations.html + // using getAllDependencies here instead of getDependencies because the latter + // was returning an empty array for the root project of SpringLikeLayoutFunctionalTest + final DependencySet allDependencies = configuration.getAllDependencies(); + final Set allProjectDependencies = allDependencies + .stream() + .filter(d -> ProjectDependency.class.isAssignableFrom(d.getClass())) + .map(ProjectDependency.class::cast) + .collect(Collectors.toSet()); + + ProjectUtils.updateResolutionStrategy(configuration); + LenientConfiguration lenient; org.gradle.api.artifacts.Configuration copy; // Attempt to call copyRecursive for all types (kotlin/gradle). if (!cache.isConstraints()) { - // if (configuration - // .getAllDependencyConstraints().stream() - // .noneMatch(AlignmentTask::isDefaultProjectDependencyConstraint)) { logger.debug("Recursively copying configuration for {}", configuration.getName()); copy = configuration.copyRecursive(); lenient = copy.getResolvedConfiguration().getLenientConfiguration(); } else { logger.debug( - "DefaultProjectDependencyConstraint found, not recursively copying configuration"); + "DefaultProjectDependencyConstraint found, not recursively copying configuration for {}", + configuration.getName()); copy = configuration.copy(); lenient = copy.getResolvedConfiguration().getLenientConfiguration(); } @@ -944,7 +946,6 @@ private void processAlignmentReport(Project project, Configuration configuration .getDependencies(); final Set>> entrySet = projectDependencies .entrySet(); - logger.info("### all project dependencies for {}", entrySet); for (Map.Entry> entry : entrySet) { final Project name = entry.getKey(); diff --git a/common/src/main/java/org/jboss/gm/common/ManipulationCache.java b/common/src/main/java/org/jboss/gm/common/ManipulationCache.java index 7f33d02f..b60c645a 100644 --- a/common/src/main/java/org/jboss/gm/common/ManipulationCache.java +++ b/common/src/main/java/org/jboss/gm/common/ManipulationCache.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import lombok.Getter; @@ -79,7 +80,7 @@ public class ManipulationCache { */ @Getter @Setter - private boolean constraints; + private boolean constraints = false; /** * Retrieves the cache given any project. It will access the root project, check if the