File tree Expand file tree Collapse file tree
spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232import java .util .List ;
3333import java .util .Map ;
3434import java .util .Set ;
35+ import java .util .function .Function ;
3536import java .util .jar .Attributes ;
3637import java .util .jar .JarFile ;
3738import 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
You can’t perform that action at this time.
0 commit comments