Skip to content

Commit ae3222d

Browse files
committed
Polish "Use new Maven Resolver API for ModifiedClassPathClassLoader"
See gh-50447
1 parent 155b02f commit ae3222d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathClassLoader.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333
import java.util.Map;
3434
import java.util.Set;
35+
import java.util.function.Function;
3536
import java.util.jar.Attributes;
3637
import java.util.jar.JarFile;
3738
import java.util.regex.Pattern;
@@ -238,9 +239,8 @@ private static List<URL> getAdditionalUrls(List<MergedAnnotations> annotations)
238239
}
239240

240241
private static List<URL> resolveCoordinates(String[] coordinates) {
241-
Exception latestFailure = null;
242-
RepositorySystem repositorySystem = new RepositorySystemSupplier().get();
243-
try {
242+
return doWithRepositorySystem((repositorySystem) -> {
243+
Exception latestFailure = null;
244244
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
245245
session.setSystemProperties(System.getProperties());
246246
LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
@@ -266,10 +266,17 @@ private static List<URL> resolveCoordinates(String[] coordinates) {
266266
}
267267
throw new IllegalStateException("Resolution failed after " + MAX_RESOLUTION_ATTEMPTS + " attempts",
268268
latestFailure);
269+
});
270+
}
271+
272+
private static <T> T doWithRepositorySystem(Function<RepositorySystem, T> repositorySystem) {
273+
RepositorySystem rs = new RepositorySystemSupplier().get();
274+
try {
275+
return repositorySystem.apply(rs);
269276
}
270277
finally {
271278
try {
272-
repositorySystem.shutdown();
279+
rs.shutdown();
273280
}
274281
catch (Exception ex) {
275282
// Ignore

0 commit comments

Comments
 (0)