diff --git a/.circleci/config.yml b/.circleci/config.yml index 8c3b6506d44..8ba2e19dc4e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,11 +7,11 @@ defaults: &defaults - image: &default_container datadog/dd-trace-java-docker-build:latest cache_keys: &cache_keys - # Reset the cache approx every release keys: - - dd-trace-java-{{ checksum "dd-trace-java.gradle" }}-{{ .Branch }}-{{ .Revision }} - - dd-trace-java-{{ checksum "dd-trace-java.gradle" }}-{{ .Branch }} - - dd-trace-java-{{ checksum "dd-trace-java.gradle" }} + # Rev the version when the cache gets too big + - dd-trace-java-v1-{{ .Branch }}-{{ .Revision }} + - dd-trace-java-v1-{{ .Branch }} + # - dd-trace-java-v1- jobs: build: @@ -225,16 +225,18 @@ jobs: - checkout - restore_cache: - # Reset the cache approx every release keys: - - dd-trace-java-muzzle-{{ checksum "dd-trace-java.gradle" }} + # Rev the version when the cache gets too big + - dd-trace-java-muzzle-v1-{{ .Branch }}-{{ .Revision }} + - dd-trace-java-muzzle-v1-{{ .Branch }} + # - dd-trace-java-muzzle-v1- - run: name: Verify Muzzle command: SKIP_BUILDSCAN="true" GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx4G -Xms64M' -Ddatadog.forkedMaxHeapSize=4G -Ddatadog.forkedMinHeapSize=64M" ./gradlew muzzle --parallel --stacktrace --no-daemon --max-workers=16 - save_cache: - key: dd-trace-java-muzzle-{{ checksum "dd-trace-java.gradle" }} + key: dd-trace-java-muzzle-v1-{{ .Branch }}-{{ .Revision }} paths: ~/.gradle workflows: diff --git a/buildSrc/src/main/groovy/MuzzlePlugin.groovy b/buildSrc/src/main/groovy/MuzzlePlugin.groovy index 2e8e56d45f5..bdd5e63d254 100644 --- a/buildSrc/src/main/groovy/MuzzlePlugin.groovy +++ b/buildSrc/src/main/groovy/MuzzlePlugin.groovy @@ -30,11 +30,16 @@ import java.util.regex.Pattern * muzzle task plugin which runs muzzle validation against a range of dependencies. */ class MuzzlePlugin implements Plugin { + /** + * Select a random set of versions to test + */ + private static final int RANGE_COUNT_LIMIT = 10 /** * Remote repositories used to query version ranges and fetch dependencies */ private static final List MUZZLE_REPOS private static final AtomicReference TOOLING_LOADER = new AtomicReference<>() + static { RemoteRepository central = new RemoteRepository.Builder("central", "default", "https://repo1.maven.org/maven2/").build() RemoteRepository sonatype = new RemoteRepository.Builder("sonatype", "default", "https://oss.sonatype.org/content/repositories/releases/").build() @@ -204,20 +209,23 @@ class MuzzlePlugin implements Plugin { /** * Convert a muzzle directive to a list of artifacts */ - private static List muzzleDirectiveToArtifacts(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) { + private static Set muzzleDirectiveToArtifacts(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) { final Artifact directiveArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", muzzleDirective.versions) final VersionRangeRequest rangeRequest = new VersionRangeRequest() rangeRequest.setRepositories(MUZZLE_REPOS) rangeRequest.setArtifact(directiveArtifact) final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest) + final Set versions = rangeResult.versions.toSet() + + limitLargeRanges(rangeResult, versions, muzzleDirective.skipVersions) // println "Range Request: " + rangeRequest // println "Range Result: " + rangeResult - final List allVersionArtifacts = filterVersion(rangeResult.versions, muzzleDirective.skipVersions).collect { version -> + final Set allVersionArtifacts = filterVersion(versions, muzzleDirective.skipVersions).collect { version -> new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", version.toString()) - } + }.toSet() if (allVersionArtifacts.isEmpty()) { throw new GradleException("No muzzle artifacts found for $muzzleDirective.group:$muzzleDirective.module $muzzleDirective.versions") @@ -229,8 +237,8 @@ class MuzzlePlugin implements Plugin { /** * Create a list of muzzle directives which assert the opposite of the given MuzzleDirective. */ - private static List inverseOf(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) { - List inverseDirectives = new ArrayList<>() + private static Set inverseOf(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) { + Set inverseDirectives = new HashSet<>() final Artifact allVerisonsArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", "[,)") final Artifact directiveArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", muzzleDirective.versions) @@ -245,9 +253,10 @@ class MuzzlePlugin implements Plugin { rangeRequest.setRepositories(MUZZLE_REPOS) rangeRequest.setArtifact(directiveArtifact) final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest) + final Set versions = rangeResult.versions.toSet() - filterVersion(allRangeResult.versions, muzzleDirective.skipVersions).collect { version -> - if (!rangeResult.versions.contains(version)) { + filterVersion(allRangeResult.versions.toSet(), muzzleDirective.skipVersions).collect { version -> + if (!versions.contains(version)) { final MuzzleDirective inverseDirective = new MuzzleDirective() inverseDirective.group = muzzleDirective.group inverseDirective.module = muzzleDirective.module @@ -260,6 +269,21 @@ class MuzzlePlugin implements Plugin { return inverseDirectives } + private static void limitLargeRanges(VersionRangeResult result, Set versions, Set skipVersions) { + List copy = new ArrayList<>(versions) + Collections.shuffle(copy) + copy.removeAll(skipVersions) + while (RANGE_COUNT_LIMIT <= copy.size()) { + Version version = copy.pop() + if (!(version.equals(result.lowestVersion) || version.equals(result.highestVersion))) { + skipVersions.add(version.toString()) + } + } + if (skipVersions.size() > 0) { + println "Muzzle skipping " + skipVersions.size() + " versions" + } + } + /** * Configure a muzzle task to pass or fail a given version. * @@ -360,7 +384,7 @@ class MuzzlePlugin implements Plugin { /** * Filter out snapshot-type builds from versions list. */ - private static filterVersion(List list, Set skipVersions) { + private static filterVersion(Set list, Set skipVersions) { list.removeIf { def version = it.toString().toLowerCase() return version.contains("rc") ||