@@ -136,10 +136,21 @@ val muzzle by tasks.registering {
136136tasks.register(" printMuzzleReferences" ) {
137137 group = " Muzzle"
138138 description = " Print references created by instrumentation muzzle"
139+ val muzzleShadowJarFile = shadowModule.flatMap { it.archiveFile }
140+ val muzzleToolingShadowJarFile = shadowMuzzleTooling.flatMap { it.archiveFile }
141+
139142 dependsOn(compileMuzzle)
140143 dependsOn(shadowModule)
144+ dependsOn(shadowMuzzleTooling)
145+
141146 doLast {
142- val instrumentationCL = createInstrumentationClassloader()
147+ // Create instrumentation classloader
148+ val instrumentationUrls = arrayOf(
149+ muzzleShadowJarFile.get().asFile.toURI().toURL(),
150+ muzzleToolingShadowJarFile.get().asFile.toURI().toURL()
151+ )
152+ val instrumentationCL = URLClassLoader (instrumentationUrls, ClassLoader .getPlatformClassLoader())
153+
143154 MuzzleGradlePluginUtil .printMuzzleReferences(instrumentationCL)
144155 }
145156}
@@ -149,7 +160,8 @@ val hasRelevantTask = gradle.startParameter.taskNames.any {
149160 val taskName = it.removePrefix(" :" )
150161 val projectPath = project.path.substring(1 )
151162 // Either the specific muzzle task in this project or a top level muzzle task.
152- taskName == " ${projectPath} :muzzle" || taskName.startsWith(" instrumentation:muzzle" )
163+ taskName == " ${projectPath} :muzzle" || taskName.startsWith(" instrumentation:muzzle" ) ||
164+ taskName.contains(" :muzzle-Assert" )
153165}
154166
155167if (hasRelevantTask) {
@@ -206,10 +218,8 @@ fun getProjectRepositories(project: Project): List<RemoteRepository> {
206218 return projectRepositories
207219}
208220
209- fun createInstrumentationClassloader (): ClassLoader {
221+ fun createInstrumentationClassloader (muzzleShadowJar : File , muzzleToolingShadowJar : File ): ClassLoader {
210222 logger.info(" Creating instrumentation class loader for: $path " )
211- val muzzleShadowJar = shadowModule.get().archiveFile.get()
212- val muzzleToolingShadowJar = shadowMuzzleTooling.get().archiveFile.get()
213223 return classpathLoader(files(muzzleShadowJar, muzzleToolingShadowJar), ClassLoader .getPlatformClassLoader())
214224}
215225
@@ -296,24 +306,42 @@ fun addMuzzleTask(muzzleDirective: MuzzleDirective, versionArtifact: Artifact?,
296306 }
297307
298308 val muzzleTask = tasks.register(taskName) {
309+ val configFiles = config.incoming.files
310+ val muzzleShadowJarFile = shadowModule.flatMap { it.archiveFile }
311+ val muzzleToolingShadowJarFile = shadowMuzzleTooling.flatMap { it.archiveFile }
312+ val muzzleBootstrapShadowJarFile = shadowMuzzleBootstrap.flatMap { it.archiveFile }
313+ val excludedNames = muzzleDirective.excludedInstrumentationNames.get()
314+ val shouldAssertPass = muzzleDirective.assertPass.get()
315+
299316 dependsOn(configurations.named(" runtimeClasspath" ))
300317 dependsOn(shadowModule)
318+ dependsOn(shadowMuzzleTooling)
319+ dependsOn(shadowMuzzleBootstrap)
320+
301321 doLast {
302- val instrumentationCL = createInstrumentationClassloader()
303- val userCL = createClassLoaderForTask(config)
322+ // Create instrumentation classloader
323+ val instrumentationUrls = arrayOf(
324+ muzzleShadowJarFile.get().asFile.toURI().toURL(),
325+ muzzleToolingShadowJarFile.get().asFile.toURI().toURL()
326+ )
327+ val instrumentationCL = URLClassLoader (instrumentationUrls, ClassLoader .getPlatformClassLoader())
328+
329+ // Create user classloader
330+ val userUrls = (configFiles + muzzleBootstrapShadowJarFile.get().asFile).map { it.toURI().toURL() }.toTypedArray()
331+ val userCL = URLClassLoader (userUrls, ClassLoader .getPlatformClassLoader())
332+
304333 MuzzleGradlePluginUtil .assertInstrumentationMuzzled(instrumentationCL, userCL,
305- muzzleDirective.excludedInstrumentationNames.get(), muzzleDirective.assertPass.get() )
334+ excludedNames, shouldAssertPass )
306335 }
307336 }
308337
309338 runAfter.configure { finalizedBy(muzzleTask) }
310339 return muzzleTask
311340}
312341
313- fun createClassLoaderForTask (muzzleTaskConfiguration : Configuration ): ClassLoader {
342+ fun createClassLoaderForTask (muzzleTaskFiles : FileCollection , muzzleBootstrapShadowJar : File ): ClassLoader {
314343 logger.info(" Creating user class loader for muzzle check" )
315- val muzzleBootstrapShadowJar = shadowMuzzleBootstrap.get().archiveFile.get()
316- return classpathLoader(muzzleTaskConfiguration + files(muzzleBootstrapShadowJar), ClassLoader .getPlatformClassLoader())
344+ return classpathLoader(muzzleTaskFiles + files(muzzleBootstrapShadowJar), ClassLoader .getPlatformClassLoader())
317345}
318346
319347fun inverseOf (muzzleDirective : MuzzleDirective , system : RepositorySystem , session : RepositorySystemSession , repos : List <RemoteRepository >): Set <MuzzleDirective > {
0 commit comments