Skip to content

Commit ecbabc4

Browse files
authored
ci: Retries the version range resolution in MuzzlePlugin (#9534)
1 parent d7d38bc commit ecbabc4

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

buildSrc/src/main/kotlin/datadog/gradle/plugin/muzzle/MuzzleMavenRepoUtils.kt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,33 @@ internal object MuzzleMavenRepoUtils {
117117
* Equivalent to the Groovy implementation in MuzzlePlugin.
118118
*/
119119
fun resolveVersionRange(
120-
muzzleDirective: MuzzleDirective,
121-
system: RepositorySystem,
122-
session: RepositorySystemSession
120+
muzzleDirective: MuzzleDirective,
121+
system: RepositorySystem,
122+
session: RepositorySystemSession
123123
): VersionRangeResult {
124-
val directiveArtifact: Artifact = DefaultArtifact(
125-
muzzleDirective.group,
126-
muzzleDirective.module,
127-
muzzleDirective.classifier ?: "",
128-
"jar",
129-
muzzleDirective.versions
130-
)
131-
val rangeRequest = VersionRangeRequest().apply {
132-
repositories = muzzleDirective.getRepositories(MUZZLE_REPOS)
133-
artifact = directiveArtifact
124+
val directiveArtifact: Artifact = DefaultArtifact(
125+
muzzleDirective.group,
126+
muzzleDirective.module,
127+
muzzleDirective.classifier ?: "",
128+
"jar",
129+
muzzleDirective.versions
130+
)
131+
val rangeRequest = VersionRangeRequest().apply {
132+
repositories = muzzleDirective.getRepositories(MUZZLE_REPOS)
133+
artifact = directiveArtifact
134+
}
135+
136+
// In rare cases, the version resolution range silently failed with the maven proxy,
137+
// retries 3 times at most then suggest to restart the job later.
138+
var range = system.resolveVersionRange(session, rangeRequest)
139+
for (i in 0..3) {
140+
if (range.lowestVersion != null && range.highestVersion != null) {
141+
return range
134142
}
135-
return system.resolveVersionRange(session, rangeRequest)
143+
range = system.resolveVersionRange(session, rangeRequest)
144+
}
145+
146+
throw IllegalStateException("The version range resolution failed during report, this is not expected. Advised course of action: Restart the job later.")
136147
}
137148

138149
/**
@@ -157,6 +168,7 @@ internal object MuzzleMavenRepoUtils {
157168
): Map<String, TestedArtifact> {
158169
val scanPluginClass = cl.loadClass("datadog.trace.agent.tooling.muzzle.MuzzleVersionScanPlugin")
159170
val listMethod = scanPluginClass.getMethod("listInstrumentationNames", ClassLoader::class.java, String::class.java)
171+
160172
@Suppress("UNCHECKED_CAST")
161173
val names = listMethod.invoke(null, cl, directive.name) as Set<String>
162174

@@ -178,12 +190,12 @@ internal object MuzzleMavenRepoUtils {
178190
/**
179191
* Returns the highest of two Version objects.
180192
*/
181-
fun highest(a: Version, b: Version): Version = if (a.compareTo(b) > 0) a else b
193+
fun highest(a: Version, b: Version): Version = if (a > b) a else b
182194

183195
/**
184196
* Returns the lowest of two Version objects.
185197
*/
186-
fun lowest(a: Version, b: Version): Version = if (a.compareTo(b) < 0) a else b
198+
fun lowest(a: Version, b: Version): Version = if (a < b) a else b
187199

188200
/**
189201
* Convert a muzzle directive to a set of artifacts for all filtered versions.

0 commit comments

Comments
 (0)