Skip to content

Commit 3801bb3

Browse files
authored
Run muzzle check against OpenTelemetry API instrumentation (bridge) (#4797)
* Run muzzle check against bridge * Simplify * Renames
1 parent 32e3deb commit 3801bb3

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

gradle-plugins/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ apply(from = "../version.gradle.kts")
1414

1515
repositories {
1616
mavenCentral()
17+
gradlePluginPortal()
1718
}
1819

1920
val bbGradlePlugin by configurations.creating
@@ -33,6 +34,8 @@ dependencies {
3334
implementation("org.eclipse.aether:aether-transport-http:1.1.0")
3435
implementation("org.apache.maven:maven-aether-provider:3.3.9")
3536

37+
implementation("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0")
38+
3639
testImplementation("org.assertj:assertj-core:3.19.0")
3740

3841
testImplementation(enforcedPlatform("org.junit:junit-bom:5.7.2"))

conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts renamed to gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts

File renamed without changes.

gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
67
import io.opentelemetry.javaagent.muzzle.AcceptableVersions
78
import io.opentelemetry.javaagent.muzzle.MuzzleDirective
89
import io.opentelemetry.javaagent.muzzle.MuzzleExtension
@@ -27,6 +28,8 @@ import java.util.stream.StreamSupport
2728

2829
plugins {
2930
`java-library`
31+
32+
id("io.opentelemetry.instrumentation.javaagent-shadowing")
3033
}
3134

3235
// Select a random set of versions to test
@@ -38,14 +41,37 @@ val muzzleTooling: Configuration by configurations.creating {
3841
isCanBeConsumed = false
3942
isCanBeResolved = true
4043
}
44+
4145
val muzzleBootstrap: Configuration by configurations.creating {
4246
isCanBeConsumed = false
4347
isCanBeResolved = true
4448
}
4549

50+
val shadowModule by tasks.registering(ShadowJar::class) {
51+
from(tasks.jar)
52+
53+
configurations = listOf(project.configurations.runtimeClasspath.get())
54+
55+
archiveFileName.set("module-for-muzzle-check.jar")
56+
57+
dependsOn(tasks.jar)
58+
}
59+
60+
val shadowMuzzleTooling by tasks.registering(ShadowJar::class) {
61+
configurations = listOf(muzzleTooling)
62+
63+
archiveFileName.set("tooling-for-muzzle-check.jar")
64+
}
65+
66+
val shadowMuzzleBootstrap by tasks.registering(ShadowJar::class) {
67+
configurations = listOf(muzzleBootstrap)
68+
69+
archiveFileName.set("bootstrap-for-muzzle-check.jar")
70+
}
71+
4672
val compileMuzzle by tasks.registering {
47-
dependsOn(muzzleBootstrap)
48-
dependsOn(muzzleTooling)
73+
dependsOn(shadowMuzzleBootstrap)
74+
dependsOn(shadowMuzzleTooling)
4975
dependsOn(tasks.named("classes"))
5076
}
5177

@@ -59,6 +85,7 @@ tasks.register("printMuzzleReferences") {
5985
group = "Muzzle"
6086
description = "Print references created by instrumentation muzzle"
6187
dependsOn(compileMuzzle)
88+
dependsOn(shadowModule)
6289
doLast {
6390
val instrumentationCL = createInstrumentationClassloader()
6491
withContextClassLoader(instrumentationCL) {
@@ -126,8 +153,9 @@ if (hasRelevantTask) {
126153

127154
fun createInstrumentationClassloader(): ClassLoader {
128155
logger.info("Creating instrumentation class loader for: $path")
129-
val runtimeClasspath = sourceSets.main.get().runtimeClasspath
130-
return classpathLoader(runtimeClasspath + muzzleTooling, ClassLoader.getPlatformClassLoader())
156+
val muzzleShadowJar = shadowModule.get().archiveFile.get()
157+
val muzzleToolingShadowJar = shadowMuzzleTooling.get().archiveFile.get()
158+
return classpathLoader(files(muzzleShadowJar, muzzleToolingShadowJar), ClassLoader.getPlatformClassLoader())
131159
}
132160

133161
fun classpathLoader(classpath: FileCollection, parent: ClassLoader): ClassLoader {
@@ -214,6 +242,7 @@ fun addMuzzleTask(muzzleDirective: MuzzleDirective, versionArtifact: Artifact?,
214242

215243
val muzzleTask = tasks.register(taskName) {
216244
dependsOn(configurations.named("runtimeClasspath"))
245+
dependsOn(shadowModule)
217246
doLast {
218247
val instrumentationCL = createInstrumentationClassloader()
219248
val userCL = createClassLoaderForTask(config)
@@ -238,7 +267,8 @@ fun addMuzzleTask(muzzleDirective: MuzzleDirective, versionArtifact: Artifact?,
238267

239268
fun createClassLoaderForTask(muzzleTaskConfiguration: Configuration): ClassLoader {
240269
logger.info("Creating user classloader for muzzle check")
241-
return classpathLoader(muzzleTaskConfiguration + muzzleBootstrap, ClassLoader.getPlatformClassLoader())
270+
val muzzleBootstrapShadowJar = shadowMuzzleBootstrap.get().archiveFile.get()
271+
return classpathLoader(muzzleTaskConfiguration + files(muzzleBootstrapShadowJar), ClassLoader.getPlatformClassLoader())
242272
}
243273

244274
fun inverseOf(muzzleDirective: MuzzleDirective, system: RepositorySystem, session: RepositorySystemSession): Set<MuzzleDirective> {

instrumentation/opentelemetry-annotations-1.0/javaagent/build.gradle.kts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ plugins {
22
id("otel.javaagent-instrumentation")
33
}
44

5-
// TODO: add muzzle once 1.4.0 is released
5+
muzzle {
6+
pass {
7+
group.set("io.opentelemetry")
8+
module.set("opentelemetry-extension-annotations")
9+
versions.set("[0.16.0,)")
10+
skip("0.13.0") // opentelemetry-api has a bad dependency on non-alpha api-metric 0.13.0
11+
assertInverse.set(true)
12+
}
13+
}
614

715
val versions: Map<String, String> by project
816

instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/build.gradle.kts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ plugins {
22
id("otel.javaagent-instrumentation")
33
}
44

5-
// TODO: add muzzle once 1.4.0 is released
5+
muzzle {
6+
pass {
7+
group.set("io.opentelemetry")
8+
module.set("opentelemetry-api")
9+
versions.set("[0.17.0,)")
10+
skip("0.13.0") // has a bad dependency on non-alpha api-metric 0.13.0
11+
skip("0.9.0") // has no pom file in maven central
12+
assertInverse.set(true)
13+
}
14+
}
615

716
dependencies {
817
// this instrumentation needs to be able to reference both the OpenTelemetry API

0 commit comments

Comments
 (0)