From 2072c83adf6bef035b32a50c4b88eb49fb86be42 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Wed, 23 Sep 2026 19:42:35 +0000 Subject: [PATCH] Use Fabric as the primary Muzzle Depot repository --- .../plugin/muzzle/MuzzleMavenRepoUtils.kt | 25 +++++++++-- .../plugin/muzzle/MuzzleMavenRepoUtilsTest.kt | 41 +++++++++---------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/buildSrc/src/main/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtils.kt b/buildSrc/src/main/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtils.kt index c5bb333da6f..fb2de094807 100644 --- a/buildSrc/src/main/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtils.kt +++ b/buildSrc/src/main/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtils.kt @@ -18,9 +18,14 @@ import org.eclipse.aether.transport.http.HttpTransporterFactory import org.eclipse.aether.version.Version import org.gradle.api.GradleException import org.gradle.api.logging.Logging +import java.net.URI import java.nio.file.Files internal object MuzzleMavenRepoUtils { + private const val DEPOT_JAVA_HOST = "depot-read-api-java.us1.ddbuild.io" + private const val DEPOT_JAVA_FABRIC_URL = + "https://depot-read-api-java.rapid-dependency-management-depot.all-clusters.local-dc.fabric.dog:8443/" + + "magicmirror/magicmirror/@current/" private val log = Logging.getLogger(MuzzleMavenRepoUtils::class.java) private val backoffDelaysSeconds = listOf(5L, 10L, 30L) @@ -31,18 +36,32 @@ internal object MuzzleMavenRepoUtils { * be reused across builds with different MAVEN_REPOSITORY_PROXY values. */ @JvmStatic - fun defaultMuzzleRepos(): List { + fun defaultMuzzleRepos(): List = + defaultMuzzleRepos(System.getenv("MAVEN_REPOSITORY_PROXY")) + + internal fun defaultMuzzleRepos(mavenProxyUrl: String?): List { val central = RemoteRepository.Builder("central", "default", "https://repo1.maven.org/maven2/").build() - val mavenProxyUrl = System.getenv("MAVEN_REPOSITORY_PROXY") return if (mavenProxyUrl == null) { listOf(central) } else { val proxy = RemoteRepository.Builder("central-proxy", "default", mavenProxyUrl).build() // TODO: temporary hack for Maven Central rate limiting - listOf(proxy /*, central*/) + if (isDepotJavaProxy(mavenProxyUrl)) { + val fabricProxy = RemoteRepository.Builder( + "central-proxy-fabric", + "default", + DEPOT_JAVA_FABRIC_URL + ).build() + listOf(fabricProxy, proxy /*, central*/) + } else { + listOf(proxy /*, central*/) + } } } + private fun isDepotJavaProxy(url: String): Boolean = + runCatching { URI(url).host.equals(DEPOT_JAVA_HOST, ignoreCase = true) }.getOrDefault(false) + /** * Create new RepositorySystem for muzzle's Maven/Aether resolutions. * Supports both HTTP/HTTPS and file:// repositories. diff --git a/buildSrc/src/test/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtilsTest.kt b/buildSrc/src/test/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtilsTest.kt index e6983e45b15..67497bc8540 100644 --- a/buildSrc/src/test/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtilsTest.kt +++ b/buildSrc/src/test/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtilsTest.kt @@ -11,8 +11,6 @@ import org.eclipse.aether.util.version.GenericVersionScheme import org.gradle.api.GradleException import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable import org.junit.jupiter.api.io.TempDir import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.CsvSource @@ -24,6 +22,11 @@ import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy private const val MAVEN_CENTRAL_URL = "https://repo1.maven.org/maven2/" +private const val DEPOT_JAVA_URL = + "https://depot-read-api-java.us1.ddbuild.io/magicmirror/magicmirror/@current/" +private const val DEPOT_JAVA_FABRIC_URL = + "https://depot-read-api-java.rapid-dependency-management-depot.all-clusters.local-dc.fabric.dog:8443/" + + "magicmirror/magicmirror/@current/" class MuzzleMavenRepoUtilsTest { @@ -115,31 +118,27 @@ class MuzzleMavenRepoUtilsTest { .hasMessageContaining("Backoff:\n disabled") } - // The two tests below are mutually exclusive: MAVEN_REPOSITORY_PROXY is read from the real - // environment (defaultMuzzleRepos deliberately does not take it as a parameter), so each of - // them covers the branch its environment can reach -- unset locally, set in CI. - @Test - @DisabledIfEnvironmentVariable( - named = "MAVEN_REPOSITORY_PROXY", - matches = ".*", - disabledReason = "A mirror is configured; the proxy variant of this test covers that case" - ) fun `defaultMuzzleRepos is Maven Central alone when no proxy is configured`() { - assertThat(MuzzleMavenRepoUtils.defaultMuzzleRepos().map { it.id to it.url }) + assertThat(MuzzleMavenRepoUtils.defaultMuzzleRepos(null).map { it.id to it.url }) .containsExactly("central" to MAVEN_CENTRAL_URL) } - // TODO: Re-enable after removing the temporary Maven Central rate limiting workaround. @Test - @Disabled("Temporarily using the configured proxy without a Maven Central fallback") - @EnabledIfEnvironmentVariable(named = "MAVEN_REPOSITORY_PROXY", matches = ".*") - fun `defaultMuzzleRepos queries the configured proxy before Maven Central`() { - val proxyUrl = System.getenv("MAVEN_REPOSITORY_PROXY") - - // Central stays in the list as a fallback, but the proxy is consulted first. - assertThat(MuzzleMavenRepoUtils.defaultMuzzleRepos().map { it.id to it.url }) - .containsExactly("central-proxy" to proxyUrl, "central" to MAVEN_CENTRAL_URL) + fun `defaultMuzzleRepos queries Depot through Fabric before the public endpoint`() { + assertThat(MuzzleMavenRepoUtils.defaultMuzzleRepos(DEPOT_JAVA_URL).map { it.id to it.url }) + .containsExactly( + "central-proxy-fabric" to DEPOT_JAVA_FABRIC_URL, + "central-proxy" to DEPOT_JAVA_URL + ) + } + + @Test + fun `defaultMuzzleRepos does not prepend Fabric to a custom proxy`() { + val customProxy = "https://maven.example.com/repository/" + + assertThat(MuzzleMavenRepoUtils.defaultMuzzleRepos(customProxy).map { it.id to it.url }) + .containsExactly("central-proxy" to customProxy) } @Test