Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NCLSUP-1188 Improve constraint handling #473

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectVersionRef> alignedDependencies = root.getAlignedDependencies().values();
assertThat(alignedDependencies)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<String, String> 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<ProjectVersionRef> 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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id("java-platform")

id("otel.publish-conventions")
}

description = "OpenTelemetry Instrumentation Bill of Materials (Alpha)"
group = "io.opentelemetry.instrumentation"
base.archivesName.set("opentelemetry-instrumentation-bom-alpha")

javaPlatform {
allowDependencies()
}

dependencies {
api(platform("io.opentelemetry:opentelemetry-bom:1.17.0"))
api(platform("io.opentelemetry:opentelemetry-bom-alpha:1.17.0-alpha"))
}

dependencies {
constraints {
rootProject.subprojects {
val proj = this
if (!proj.name.startsWith("bom") && proj.name != "javaagent") {
proj.plugins.withId("maven-publish") {
api(proj)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.time.Duration

plugins {
id("idea")

id("com.github.ben-manes.versions")
// id("otel.spotless-conventions")

id("org.jboss.gm.analyzer")
}

apply(from = "version.gradle.kts")

description = "OpenTelemetry instrumentations for Java"

subprojects {
apply(plugin = "org.jboss.gm.analyzer")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
plugins {
id("otel.java-conventions")
}

dependencies {
implementation("com.google.errorprone:error_prone_core")

annotationProcessor("com.google.auto.service:auto-service")
compileOnly("com.google.auto.service:auto-service-annotations")

testImplementation("com.google.errorprone:error_prone_test_helpers")
}

otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_11)
}

// 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_11
targetCompatibility = JavaVersion.VERSION_11
toolchain {
languageVersion.set(null as JavaLanguageVersion?)
}
}

tasks {
withType<JavaCompile>().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.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"
)
)
}
}
}

tasks.withType<Test>().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")
}

// 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
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask

plugins {
`java-platform`

id("com.github.ben-manes.versions")
}

data class DependencySet(val group: String, val version: String, val modules: List<String>)

val dependencyVersions = hashMapOf<String, String>()
rootProject.extra["versions"] = dependencyVersions

// this line is managed by .github/scripts/update-sdk-version.sh
val otelVersion = "1.17.0"

rootProject.extra["otelVersion"] = otelVersion

// Need both BOM and groovy jars
val groovyVersion = "4.0.2"

// We don't force libraries we instrument to new versions since we compile and test against specific
// old baseline versions but we do try to force those libraries' transitive dependencies to new
// versions where possible so that we don't end up with explosion of dependency versions in
// Intellij, which causes Intellij to spend lots of time indexing all of those different dependency
// versions, and makes debugging painful because Intellij has no idea which dependency version's
// source to use when stepping through code.
//
// Sometimes libraries we instrument do require a specific version of a transitive dependency and
// that can be applied in the specific instrumentation gradle file, e.g.
// configurations.testRuntimeClasspath.resolutionStrategy.force "com.google.guava:guava:19.0"

val DEPENDENCY_BOMS = listOf(
"com.fasterxml.jackson:jackson-bom:2.13.2.20220328",
"com.google.guava:guava-bom:31.1-jre",
"org.apache.groovy:groovy-bom:${groovyVersion}",
"io.opentelemetry:opentelemetry-bom:${otelVersion}",
"io.opentelemetry:opentelemetry-bom-alpha:${otelVersion}-alpha",
"org.junit:junit-bom:5.8.2",
"org.testcontainers:testcontainers-bom:1.17.1",
)

val DEPENDENCY_SETS = listOf(
DependencySet(
"com.google.auto.service",
"1.0.1",
listOf("auto-service", "auto-service-annotations")
),
DependencySet(
"com.google.auto.value",
"1.9",
listOf("auto-value", "auto-value-annotations")
),
DependencySet(
"com.google.errorprone",
"2.14.0",
listOf("error_prone_annotations", "error_prone_core", "error_prone_test_helpers")
),
DependencySet(
"net.bytebuddy",
// When updating, also update conventions/build.gradle.kts
"1.12.10",
listOf("byte-buddy", "byte-buddy-dep", "byte-buddy-agent", "byte-buddy-gradle-plugin")
),
DependencySet(
"org.openjdk.jmh",
"1.35",
listOf("jmh-core", "jmh-generator-bytecode")
),
DependencySet(
"org.mockito",
"4.5.1",
listOf("mockito-core", "mockito-junit-jupiter", "mockito-inline")
),
DependencySet(
"org.slf4j",
"1.7.36",
listOf("slf4j-api", "slf4j-simple", "log4j-over-slf4j", "jcl-over-slf4j", "jul-to-slf4j")
),
)

// See the comment above about why we keep this rather large list.
// There are dependencies included here that appear to have no usages, but are maintained at
// this top level to help consistently satisfy large numbers of transitive dependencies.
val DEPENDENCIES = listOf(
"ch.qos.logback:logback-classic:1.2.11",
"com.github.stefanbirkner:system-lambda:1.2.1",
"com.github.stefanbirkner:system-rules:1.19.0",
"uk.org.webcompere:system-stubs-jupiter:2.0.1",
"com.uber.nullaway:nullaway:0.9.7",
"commons-beanutils:commons-beanutils:1.9.4",
"commons-cli:commons-cli:1.5.0",
"commons-codec:commons-codec:1.15",
"commons-collections:commons-collections:3.2.2",
"commons-digester:commons-digester:2.1",
"commons-fileupload:commons-fileupload:1.4",
"commons-io:commons-io:2.11.0",
"commons-lang:commons-lang:2.6",
"commons-logging:commons-logging:1.2",
"commons-validator:commons-validator:1.7",
"io.netty:netty:3.10.6.Final",
"io.opentelemetry.proto:opentelemetry-proto:0.17.0-alpha",
"org.assertj:assertj-core:3.22.0",
"org.awaitility:awaitility:4.2.0",
"com.google.code.findbugs:annotations:3.0.1u2",
"com.google.code.findbugs:jsr305:3.0.2",
"org.apache.groovy:groovy:${groovyVersion}",
"org.apache.groovy:groovy-json:${groovyVersion}",
"org.junit-pioneer:junit-pioneer:1.7.0",
"org.objenesis:objenesis:3.2",
"org.spockframework:spock-core:2.2-M1-groovy-4.0",
"org.spockframework:spock-junit4:2.2-M1-groovy-4.0",
"org.scala-lang:scala-library:2.11.12",
// Note that this is only referenced as "org.springframework.boot" in build files, not the artifact name.
"org.springframework.boot:spring-boot-dependencies:2.7.2"
)

javaPlatform {
allowDependencies()
}

dependencies {
for (bom in DEPENDENCY_BOMS) {
api(enforcedPlatform(bom))
val split = bom.split(':')
dependencyVersions[split[0]] = split[2]
}
constraints {
for (set in DEPENDENCY_SETS) {
for (module in set.modules) {
api("${set.group}:${module}:${set.version}")
dependencyVersions[set.group] = set.version
}
}
for (dependency in DEPENDENCIES) {
api(dependency)
val split = dependency.split(':')
dependencyVersions[split[0]] = split[2]
}
}
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isGuava = version.endsWith("-jre")
val isStable = stableKeyword || regex.matches(version) || isGuava
return isStable.not()
}

tasks {
named<DependencyUpdatesTask>("dependencyUpdates") {
revision = "release"
checkConstraints = true

rejectVersionIf {
isNonStable(candidate.version)
}
}
}
Loading
Loading