33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6+ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
67import io.opentelemetry.javaagent.muzzle.AcceptableVersions
78import io.opentelemetry.javaagent.muzzle.MuzzleDirective
89import io.opentelemetry.javaagent.muzzle.MuzzleExtension
@@ -27,6 +28,8 @@ import java.util.stream.StreamSupport
2728
2829plugins {
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+
4145val 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+
4672val 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
127154fun 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
133161fun 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
239268fun 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
244274fun inverseOf (muzzleDirective : MuzzleDirective , system : RepositorySystem , session : RepositorySystemSession ): Set <MuzzleDirective > {
0 commit comments