Actually use requested number of versions to test muzzle
MODIFY
buildSrc/src/main/groovy/MuzzlePlugin.groovy
buildSrc/src/main/groovy/MuzzlePlugin.groovy
import java.lang.reflect.Method
import java.security.SecureClassLoader
import java.util.concurrent.atomic.AtomicReference
+import java.util.function.Predicate
import java.util.regex.Pattern
import org.apache.maven.repository.internal.MavenRepositorySystemUtils
import org.eclipse.aether.DefaultRepositorySystemSession
@@ -220,15 +221,9 @@ class MuzzlePlugin implements Plugin<Project> {
rangeRequest.setRepositories(MUZZLE_REPOS)
rangeRequest.setArtifact(directiveArtifact)
VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest)
- Set<Version> versions = rangeResult.versions.toSet()
- limitLargeRanges(rangeResult, versions, muzzleDirective.skipVersions)
-
-// println "Range Request: " + rangeRequest
-// println "Range Result: " + rangeResult
-
- Set<Artifact> allVersionArtifacts = filterVersion(versions, muzzleDirective.skipVersions).collect { version ->
- new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", version.toString())
+ Set<Artifact> allVersionArtifacts = filterVersions(rangeResult, muzzleDirective.skipVersions).collect { version ->
+ new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", version)
}.toSet()
if (allVersionArtifacts.isEmpty()) {
@@ -244,47 +239,92 @@ class MuzzlePlugin implements Plugin<Project> {
private static Set<MuzzleDirective> inverseOf(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) {
Set<MuzzleDirective> inverseDirectives = new HashSet<>()
- Artifact allVerisonsArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", "[,)")
+ Artifact allVersionsArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", "[,)")
Artifact directiveArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", muzzleDirective.versions)
-
VersionRangeRequest allRangeRequest = new VersionRangeRequest()
allRangeRequest.setRepositories(MUZZLE_REPOS)
- allRangeRequest.setArtifact(allVerisonsArtifact)
+ allRangeRequest.setArtifact(allVersionsArtifact)
VersionRangeResult allRangeResult = system.resolveVersionRange(session, allRangeRequest)
VersionRangeRequest rangeRequest = new VersionRangeRequest()
rangeRequest.setRepositories(MUZZLE_REPOS)
rangeRequest.setArtifact(directiveArtifact)
VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest)
- Set<Version> versions = rangeResult.versions.toSet()
- filterVersion(allRangeResult.versions.toSet(), muzzleDirective.skipVersions).collect { version ->
- if (!versions.contains(version)) {
+ allRangeResult.getVersions().removeAll(rangeResult.getVersions())
+
+ filterVersions(allRangeResult, muzzleDirective.skipVersions).each { version ->
MuzzleDirective inverseDirective = new MuzzleDirective()
inverseDirective.group = muzzleDirective.group
inverseDirective.module = muzzleDirective.module
- inverseDirective.versions = "$version"
+ inverseDirective.versions = version
inverseDirective.assertPass = !muzzleDirective.assertPass
inverseDirectives.add(inverseDirective)
}
- }
return inverseDirectives
}
- private static void limitLargeRanges(VersionRangeResult result, Set<Version> versions, Set<String> skipVersions) {
- List<Version> copy = new ArrayList<>(versions)
- copy.removeAll(skipVersions)
+ private static Set<String> filterVersions(VersionRangeResult range, Set<String> skipVersions) {
+ Set<String> result = new HashSet<>()
+
+ def predicate = new AcceptableVersions(range, skipVersions)
+ if (predicate.test(range.lowestVersion)) {
+ result.add(range.lowestVersion.toString())
+ }
+ if (predicate.test(range.highestVersion)) {
+ result.add(range.highestVersion.toString())
+ }
+
+ List<Version> copy = new ArrayList<>(range.versions)
Collections.shuffle(copy)
- while (RANGE_COUNT_LIMIT <= copy.size()) {
+ while (result.size() < RANGE_COUNT_LIMIT && !copy.isEmpty()) {
Version version = copy.pop()
- if (!(version.equals(result.lowestVersion) || version.equals(result.highestVersion))) {
- skipVersions.add(version.toString())
+ if (predicate.test(version)) {
+ result.add(version.toString())
+ }
+ }
+
+ return result
+ }
+
+ static class AcceptableVersions implements Predicate<Version> {
+ private static final Pattern GIT_SHA_PATTERN = Pattern.compile('^.*-[0-9a-f]{7,}$')
+
+ private final VersionRangeResult range
+ private final Collection<String> skipVersions
+
+ AcceptableVersions(VersionRangeResult range, Collection<String> skipVersions) {
+ this.range = range
+ this.skipVersions = skipVersions
+ }
+
+ @Override
+ boolean test(Version version) {
+ if (version == null) {
+ return false
}
+ def versionString = version.toString()
+ if (skipVersions.contains(versionString)) {
+ return false
}
- if (skipVersions.size() > 0) {
- println "Muzzle skipping " + skipVersions.size() + " versions"
+
+ versionString = versionString.toLowerCase()
+ def draftVersion = versionString.contains("rc") ||
+ versionString.contains(".cr") ||
+ versionString.contains("alpha") ||
+ versionString.contains("beta") ||
+ versionString.contains("-b") ||
+ versionString.contains(".m") ||
+ versionString.contains("-m") ||
+ versionString.contains("-dev") ||
+ versionString.contains("-ea") ||
+ versionString.contains("-atlassian-") ||
+ versionString.contains("public_draft") ||
+ versionString.matches(GIT_SHA_PATTERN)
+
+ return !draftVersion
}
}
@@ -335,6 +375,7 @@ class MuzzlePlugin implements Plugin<Project> {
String toString() {
return "bogus"
}
+
}
Thread.currentThread().contextClassLoader = bogusLoader
ClassLoader userCL = createClassLoaderForTask(instrumentationProject, bootstrapProject, taskName)
@@ -369,6 +410,7 @@ class MuzzlePlugin implements Plugin<Project> {
return locator.getService(RepositorySystem.class)
}
+
/**
* Create muzzle's repository system session
*/
@@ -382,31 +424,6 @@ class MuzzlePlugin implements Plugin<Project> {
return session
}
-
- private static final Pattern GIT_SHA_PATTERN = Pattern.compile('^.*-[0-9a-f]{7,}$')
-
- /**
- * Filter out snapshot-type builds from versions list.
- */
- private static filterVersion(Set<Version> list, Set<String> skipVersions) {
- list.removeIf {
- def version = it.toString().toLowerCase()
- return version.contains("rc") ||
- version.contains(".cr") ||
- version.contains("alpha") ||
- version.contains("beta") ||
- version.contains("-b") ||
- version.contains(".m") ||
- version.contains("-m") ||
- version.contains("-dev") ||
- version.contains("-ea") ||
- version.contains("-atlassian-") ||
- version.contains("public_draft") ||
- skipVersions.contains(version) ||
- version.matches(GIT_SHA_PATTERN)
- }
- return list
- }
}
// plugin extension classes

ADD
buildSrc/src/test/groovy/VersionTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import org.eclipse.aether.resolution.VersionRangeRequest
+import org.eclipse.aether.resolution.VersionRangeResult
+import org.eclipse.aether.util.version.GenericVersion
+import spock.lang.Specification
+
+class VersionTest extends Specification {
+
+ def "test range request"() {
+ setup:
+ def predicate = new MuzzlePlugin.AcceptableVersions(new VersionRangeResult(new VersionRangeRequest()), [])
+ expect:
+ !predicate.test(new GenericVersion("10.1.0-rc2+19-8e20bb26"))
+ }
+}

MODIFY
instrumentation/elasticsearch/elasticsearch-rest-6.4/elasticsearch-rest-6.4.gradle
instrumentation/elasticsearch/elasticsearch-rest-6.4/elasticsearch-rest-6.4.gradle
@@ -13,7 +13,6 @@ muzzle {
group = "org.elasticsearch.client"
module = "rest"
versions = "(,)"
- assertInverse = true
}
}

Actually use requested number of versions to test muzzle (#1396)