Correctly use muzzleTooling configuration to allow for external additions
MODIFY
gradle-plugins/build.gradle.kts
gradle-plugins/build.gradle.kts
@@ -13,7 +13,6 @@ version = "0.2.0-SNAPSHOT"
repositories {
mavenCentral()
- mavenLocal()
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
@@ -41,6 +40,10 @@ dependencies {
testImplementation("io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:1.5.0-alpha-SNAPSHOT")
}
+tasks.withType<Test>().configureEach {
+ useJUnitPlatform()
+}
+
pluginBundle {
website = "https://opentelemetry.io"
vcsUrl = "https://github.com/open-telemetry/opentelemetry-java-instrumentation"

MODIFY
gradle-plugins/src/main/java/io/opentelemetry/javaagent/muzzle/matcher/MuzzleGradlePluginUtil.java
gradle-plugins/src/main/java/io/opentelemetry/javaagent/muzzle/matcher/MuzzleGradlePluginUtil.java
@@ -25,7 +25,7 @@ import java.util.ServiceLoader;
* different independent class loaders at play here.
* <p>
* First, Gradle class loader that has loaded the muzzle-check plugin that calls this class. This
- * one has a lot of Gradle specific stuff and we don't want that it to be available during muzzle checks.
+ * one has a lot of Gradle specific stuff and we don't want it to be available during muzzle checks.
* <p>
* Second, there is agent or instrumentation class loader, which contains all InstrumentationModules
* and helper classes. The actual muzzle check process happens "inside" that class loader. This means

MODIFY
gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts
gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts
@@ -34,11 +34,11 @@ val RANGE_COUNT_LIMIT = 10
val muzzleConfig = extensions.create<MuzzleExtension>("muzzle")
-val muzzleTooling by configurations.creating {
+val muzzleTooling: Configuration by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
}
-val muzzleBootstrap by configurations.creating {
+val muzzleBootstrap: Configuration by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
}
@@ -123,12 +123,13 @@ if (hasRelevantTask) {
}
fun createInstrumentationClassloader(): ClassLoader {
- logger.info("Creating instrumentation classpath for: ${name}")
+ logger.info("Creating instrumentation class loader for: $path")
val runtimeClasspath = sourceSets.main.get().runtimeClasspath
- return classpathLoader(runtimeClasspath, MuzzleGradlePluginUtil::class.java.classLoader)
+ return classpathLoader(runtimeClasspath + muzzleTooling, ClassLoader.getPlatformClassLoader())
}
fun classpathLoader(classpath: FileCollection, parent: ClassLoader): ClassLoader {
+ logger.info("Adding to classloader:")
val urls: Array<URL> = StreamSupport.stream(classpath.spliterator(), false)
.map {
logger.info("--${it}")
@@ -238,10 +239,8 @@ fun addMuzzleTask(muzzleDirective: MuzzleDirective, versionArtifact: Artifact?,
}
fun createClassLoaderForTask(muzzleTaskConfiguration: Configuration): ClassLoader {
- val userUrls = objects.fileCollection()
- logger.info("Creating task classpath")
- userUrls.from(muzzleTaskConfiguration.resolvedConfiguration.files)
- return classpathLoader(userUrls.plus(muzzleBootstrap), ClassLoader.getPlatformClassLoader())
+ logger.info("Creating user classloader for muzzle check")
+ return classpathLoader(muzzleTaskConfiguration + muzzleBootstrap, ClassLoader.getPlatformClassLoader())
}
fun inverseOf(muzzleDirective: MuzzleDirective, system: RepositorySystem, session: RepositorySystemSession): Set<MuzzleDirective> {

MODIFY
gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/AcceptableVersions.kt
gradle-plugins/src/main/kotlin/io/opentelemetry/javaagent/muzzle/AcceptableVersions.kt
@@ -9,7 +9,7 @@ import org.eclipse.aether.version.Version
import java.util.Locale
import java.util.function.Predicate
-internal class AcceptableVersions(private val skipVersions: Collection<String>) :
+class AcceptableVersions(private val skipVersions: Collection<String>) :
Predicate<Version?> {
override fun test(version: Version?): Boolean {

ADD
gradle-plugins/src/test/java/io/opentelemetry/javaagent/muzzle/MuzzlePluginTest.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.muzzle;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Collections;
+import org.eclipse.aether.version.Version;
+import org.junit.jupiter.api.Test;
+
+class MuzzlePluginTest {
+
+ @Test
+ void rangeRequest() {
+ AcceptableVersions predicate = new AcceptableVersions(Collections.emptyList());
+
+ assertThat(predicate.test(new TestVersion("10.1.0-rc2+19-8e20bb26"))).isFalse();
+ assertThat(predicate.test(new TestVersion("2.4.5.BUILD-SNAPSHOT"))).isFalse();
+ }
+
+ static class TestVersion implements Version {
+
+ private final String version;
+
+ TestVersion(String version) {
+ this.version = version;
+ }
+
+ @Override
+ public int compareTo(Version o) {
+ return toString().compareTo(o.toString());
+ }
+
+ @Override
+ public String toString() {
+ return version;
+ }
+ }
+}

Correctly use muzzleTooling configuration to allow for external additions (#3743)