Fix minor review mentions

This commit is contained in:
Sebastian Sdorra
2020-08-11 08:07:06 +02:00
parent 0dc84ed94e
commit 50608b0189
8 changed files with 34 additions and 26 deletions

View File

@@ -69,24 +69,29 @@ public class DefaultPluginManager implements PluginManager {
private final Collection<PendingPluginUninstallation> pendingUninstallQueue = new ArrayList<>();
private final PluginDependencyTracker dependencyTracker = new PluginDependencyTracker();
private Function<List<AvailablePlugin>, PluginInstallationContext> contextFactory;
private final Function<List<AvailablePlugin>, PluginInstallationContext> contextFactory;
@Inject
public DefaultPluginManager(PluginLoader loader, PluginCenter center, PluginInstaller installer, Restarter restarter, ScmEventBus eventBus) {
this(loader, center, installer, restarter, eventBus, null);
}
DefaultPluginManager(PluginLoader loader, PluginCenter center, PluginInstaller installer, Restarter restarter, ScmEventBus eventBus, Function<List<AvailablePlugin>, PluginInstallationContext> contextFactory) {
this.loader = loader;
this.center = center;
this.installer = installer;
this.restarter = restarter;
this.eventBus = eventBus;
if (contextFactory != null) {
this.contextFactory = contextFactory;
} else {
this.contextFactory = (availablePlugins -> PluginInstallationContext.from(getInstalled(), availablePlugins));
}
this.computeInstallationDependencies();
this.contextFactory = (availablePlugins -> PluginInstallationContext.from(getInstalled(), availablePlugins));
}
@VisibleForTesting
void setContextFactory(Function<List<AvailablePlugin>, PluginInstallationContext> contextFactory) {
this.contextFactory = contextFactory;
}
@VisibleForTesting
synchronized void computeInstallationDependencies() {

View File

@@ -26,7 +26,7 @@ package sonia.scm.plugin;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
@SuppressWarnings("java:S110")
@SuppressWarnings("squid:MaximumInheritanceDepth") // exceptions have a deep inheritance depth themselves; therefore we accept this here
public class DependencyNotFoundException extends PluginInstallException {
private final String plugin;

View File

@@ -29,7 +29,7 @@ import lombok.Getter;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
@Getter
@SuppressWarnings("java:S110")
@SuppressWarnings("squid:MaximumInheritanceDepth") // exceptions have a deep inheritance depth themselves; therefore we accept this here
public class DependencyVersionMismatchException extends PluginInstallException {
private final String plugin;

View File

@@ -26,7 +26,7 @@ package sonia.scm.plugin;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
@SuppressWarnings("java:S110")
@SuppressWarnings("squid:MaximumInheritanceDepth") // exceptions have a deep inheritance depth themselves; therefore we accept this here
public class PluginChecksumMismatchException extends PluginInstallException {
public PluginChecksumMismatchException(AvailablePlugin plugin, String calculatedChecksum, String expectedChecksum) {
super(

View File

@@ -29,7 +29,7 @@ import lombok.Getter;
import static sonia.scm.ContextEntry.ContextBuilder.entity;
@Getter
@SuppressWarnings("java:S110")
@SuppressWarnings("squid:MaximumInheritanceDepth") // exceptions have a deep inheritance depth themselves; therefore we accept this here
public class PluginInformationMismatchException extends PluginInstallException {
private final PluginInformation api;

View File

@@ -38,7 +38,8 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
@SuppressWarnings("UnstableApiUsage") // guava hash is marked as unstable
@SuppressWarnings("UnstableApiUsage")
// guava hash is marked as unstable
class PluginInstaller {
private final SCMContextProvider scmContext;
@@ -76,28 +77,28 @@ class PluginInstaller {
}
}
private void verifyInformation(AvailablePluginDescriptor api, InstalledPluginDescriptor downloaded) {
verifyInformation(api.getInformation(), downloaded.getInformation());
private void verifyInformation(AvailablePluginDescriptor descriptorFromPluginCenter, InstalledPluginDescriptor downloadedDescriptor) {
verifyInformation(descriptorFromPluginCenter.getInformation(), downloadedDescriptor.getInformation());
}
private void verifyInformation(PluginInformation api, PluginInformation downloaded) {
if (!api.getName().equals(downloaded.getName())) {
private void verifyInformation(PluginInformation informationFromPluginCenter, PluginInformation downloadedInformation) {
if (!informationFromPluginCenter.getName().equals(downloadedInformation.getName())) {
throw new PluginInformationMismatchException(
api, downloaded,
informationFromPluginCenter, downloadedInformation,
String.format(
"downloaded plugin name \"%s\" does not match the expected name \"%s\" from plugin-center",
downloaded.getName(),
api.getName()
downloadedInformation.getName(),
informationFromPluginCenter.getName()
)
);
}
if (!api.getVersion().equals(downloaded.getVersion())) {
if (!informationFromPluginCenter.getVersion().equals(downloadedInformation.getVersion())) {
throw new PluginInformationMismatchException(
api, downloaded,
informationFromPluginCenter, downloadedInformation,
String.format(
"downloaded plugin version \"%s\" does not match the expected version \"%s\" from plugin-center",
downloaded.getVersion(),
api.getVersion()
downloadedInformation.getVersion(),
informationFromPluginCenter.getVersion()
)
);
}