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,34 +57,28 @@ 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(() -> {
LOGGER.info("Looking for updates for {}", library.getName());
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) {
try {
result.add(job.get());
}
catch (InterruptedException | ExecutionException ex) {
throw new RuntimeException(ex);
}
}
return result;
} }
finally { finally {
executorService.shutdownNow(); executorService.shutdownNow();
} }
} }
private Stream<LibraryWithVersionOptions> getResult(Future<List<LibraryWithVersionOptions>> job) {
try {
return job.get().stream();
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new RuntimeException(ex);
}
catch (ExecutionException ex) {
throw new RuntimeException(ex);
}
}
} }

@ -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