@@ -117,22 +117,33 @@ internal object MuzzleMavenRepoUtils {
117
117
* Equivalent to the Groovy implementation in MuzzlePlugin.
118
118
*/
119
119
fun resolveVersionRange (
120
- muzzleDirective : MuzzleDirective ,
121
- system : RepositorySystem ,
122
- session : RepositorySystemSession
120
+ muzzleDirective : MuzzleDirective ,
121
+ system : RepositorySystem ,
122
+ session : RepositorySystemSession
123
123
): 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
134
142
}
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." )
136
147
}
137
148
138
149
/* *
@@ -157,6 +168,7 @@ internal object MuzzleMavenRepoUtils {
157
168
): Map <String , TestedArtifact > {
158
169
val scanPluginClass = cl.loadClass(" datadog.trace.agent.tooling.muzzle.MuzzleVersionScanPlugin" )
159
170
val listMethod = scanPluginClass.getMethod(" listInstrumentationNames" , ClassLoader ::class .java, String ::class .java)
171
+
160
172
@Suppress(" UNCHECKED_CAST" )
161
173
val names = listMethod.invoke(null , cl, directive.name) as Set <String >
162
174
@@ -178,12 +190,12 @@ internal object MuzzleMavenRepoUtils {
178
190
/* *
179
191
* Returns the highest of two Version objects.
180
192
*/
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
182
194
183
195
/* *
184
196
* Returns the lowest of two Version objects.
185
197
*/
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
187
199
188
200
/* *
189
201
* Convert a muzzle directive to a set of artifacts for all filtered versions.
0 commit comments