Merge branch '3.0.x' into 3.1.x

3.1.x
Andy Wilkinson 1 year ago
commit 701ce0058d

@ -16,36 +16,39 @@
package org.springframework.boot.build.bom.bomr; package org.springframework.boot.build.bom.bomr;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.stream.Stream;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.build.bom.Library; import org.springframework.boot.build.bom.Library;
import org.springframework.boot.build.bom.UpgradePolicy;
/** /**
* Uses multiple threads to find library updates. * {@link LibraryUpdateResolver} decorator that uses multiple threads to find library
* updates.
* *
* @author Moritz Halbritter * @author Moritz Halbritter
* @author Andy Wilkinson
*/ */
class MultithreadedLibraryUpdateResolver extends StandardLibraryUpdateResolver { class MultithreadedLibraryUpdateResolver implements LibraryUpdateResolver {
private static final Logger LOGGER = LoggerFactory.getLogger(MultithreadedLibraryUpdateResolver.class); private static final Logger LOGGER = LoggerFactory.getLogger(MultithreadedLibraryUpdateResolver.class);
private final int threads; private final int threads;
MultithreadedLibraryUpdateResolver(VersionResolver versionResolver, UpgradePolicy upgradePolicy, int threads) { private final LibraryUpdateResolver delegate;
super(versionResolver, upgradePolicy);
MultithreadedLibraryUpdateResolver(int threads, LibraryUpdateResolver delegate) {
this.threads = threads; this.threads = threads;
this.delegate = delegate;
} }
@Override @Override
@ -54,33 +57,27 @@ class MultithreadedLibraryUpdateResolver extends StandardLibraryUpdateResolver {
LOGGER.info("Looking for updates using {} threads", this.threads); LOGGER.info("Looking for updates using {} threads", this.threads);
ExecutorService executorService = Executors.newFixedThreadPool(this.threads); ExecutorService executorService = Executors.newFixedThreadPool(this.threads);
try { try {
List<Future<LibraryWithVersionOptions>> jobs = new ArrayList<>(); return librariesToUpgrade.stream()
for (Library library : librariesToUpgrade) { .map((library) -> executorService.submit(
if (isLibraryExcluded(library)) { () -> this.delegate.findLibraryUpdates(Collections.singletonList(library), librariesByName)))
continue; .flatMap(this::getResult)
.toList();
} }
jobs.add(executorService.submit(() -> { finally {
LOGGER.info("Looking for updates for {}", library.getName()); executorService.shutdownNow();
long start = System.nanoTime();
List<VersionOption> versionOptions = getVersionOptions(library, librariesByName);
LOGGER.info("Found {} updates for {}, took {}", versionOptions.size(), library.getName(),
Duration.ofNanos(System.nanoTime() - start));
return new LibraryWithVersionOptions(library, versionOptions);
}));
} }
List<LibraryWithVersionOptions> result = new ArrayList<>(); }
for (Future<LibraryWithVersionOptions> job : jobs) {
private Stream<LibraryWithVersionOptions> getResult(Future<List<LibraryWithVersionOptions>> job) {
try { try {
result.add(job.get()); return job.get().stream();
} }
catch (InterruptedException | ExecutionException ex) { catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} catch (ExecutionException ex) {
return result; throw new RuntimeException(ex);
}
finally {
executorService.shutdownNow();
} }
} }

@ -208,8 +208,9 @@ public abstract class UpgradeDependencies extends DefaultTask {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private List<Upgrade> resolveUpgrades() { private List<Upgrade> resolveUpgrades() {
List<Upgrade> upgrades = new InteractiveUpgradeResolver(getServices().get(UserInputHandler.class), List<Upgrade> upgrades = new InteractiveUpgradeResolver(getServices().get(UserInputHandler.class),
new MultithreadedLibraryUpdateResolver(new MavenMetadataVersionResolver(getRepositoryUris().get()), new MultithreadedLibraryUpdateResolver(getThreads().get(),
this.bom.getUpgrade().getPolicy(), getThreads().get())) new StandardLibraryUpdateResolver(new MavenMetadataVersionResolver(getRepositoryUris().get()),
this.bom.getUpgrade().getPolicy())))
.resolveUpgrades(matchingLibraries(getLibraries().getOrNull()), this.bom.getLibraries()); .resolveUpgrades(matchingLibraries(getLibraries().getOrNull()), this.bom.getLibraries());
return upgrades; return upgrades;
} }

Loading…
Cancel
Save