|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -66,6 +66,8 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
|
66 | 66 |
|
67 | 67 | private static final Pattern INTELLIJ_CLASSPATH_JAR_PATTERN = Pattern.compile(".*classpath(\\d+)?\\.jar");
|
68 | 68 |
|
| 69 | + private static final int MAX_RESOLUTION_ATTEMPTS = 5; |
| 70 | + |
69 | 71 | private final ClassLoader junitLoader;
|
70 | 72 |
|
71 | 73 | ModifiedClassPathClassLoader(URL[] urls, ClassLoader parent, ClassLoader junitLoader) {
|
@@ -191,29 +193,35 @@ private static List<URL> getAdditionalUrls(MergedAnnotation<ClassPathOverrides>
|
191 | 193 | }
|
192 | 194 |
|
193 | 195 | private static List<URL> resolveCoordinates(String[] coordinates) {
|
| 196 | + Exception latestFailure = null; |
194 | 197 | DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator();
|
195 | 198 | serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
|
196 | 199 | serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class);
|
197 | 200 | RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class);
|
198 | 201 | DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
|
199 | 202 | LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
|
200 | 203 | session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepository));
|
201 |
| - CollectRequest collectRequest = new CollectRequest(null, Arrays.asList( |
202 |
| - new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build())); |
203 |
| - |
204 |
| - collectRequest.setDependencies(createDependencies(coordinates)); |
205 |
| - DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null); |
206 |
| - try { |
207 |
| - DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest); |
208 |
| - List<URL> resolvedArtifacts = new ArrayList<>(); |
209 |
| - for (ArtifactResult artifact : result.getArtifactResults()) { |
210 |
| - resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL()); |
| 204 | + for (int i = 0; i < MAX_RESOLUTION_ATTEMPTS; i++) { |
| 205 | + CollectRequest collectRequest = new CollectRequest(null, |
| 206 | + Arrays.asList( |
| 207 | + new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2") |
| 208 | + .build())); |
| 209 | + collectRequest.setDependencies(createDependencies(coordinates)); |
| 210 | + DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null); |
| 211 | + try { |
| 212 | + DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest); |
| 213 | + List<URL> resolvedArtifacts = new ArrayList<>(); |
| 214 | + for (ArtifactResult artifact : result.getArtifactResults()) { |
| 215 | + resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL()); |
| 216 | + } |
| 217 | + return resolvedArtifacts; |
| 218 | + } |
| 219 | + catch (Exception ex) { |
| 220 | + latestFailure = ex; |
211 | 221 | }
|
212 |
| - return resolvedArtifacts; |
213 |
| - } |
214 |
| - catch (Exception ignored) { |
215 |
| - return Collections.emptyList(); |
216 | 222 | }
|
| 223 | + throw new IllegalStateException("Resolution failed after " + MAX_RESOLUTION_ATTEMPTS + " attempts", |
| 224 | + latestFailure); |
217 | 225 | }
|
218 | 226 |
|
219 | 227 | private static List<Dependency> createDependencies(String[] allCoordinates) {
|
|
0 commit comments