cancel installation on pending plugins

This commit is contained in:
Eduard Heimbuch
2019-09-28 11:44:39 +02:00
parent e1dd393cce
commit 333579ef2a
6 changed files with 17 additions and 10 deletions

View File

@@ -5,7 +5,7 @@ import com.google.common.base.Preconditions;
public class AvailablePlugin implements Plugin {
private final AvailablePluginDescriptor pluginDescriptor;
private final boolean pending;
private boolean pending;
public AvailablePlugin(AvailablePluginDescriptor pluginDescriptor) {
this(pluginDescriptor, false);
@@ -25,6 +25,10 @@ public class AvailablePlugin implements Plugin {
return pending;
}
public void cancelInstallation() {
this.pending = false;
}
public AvailablePlugin install() {
Preconditions.checkState(!pending, "installation is already pending");
return new AvailablePlugin(pluginDescriptor, true);

View File

@@ -109,5 +109,5 @@ public interface PluginManager {
/**
* Update all installed plugins.
*/
void updateAll(boolean restartAfterInstallation);
void updateAll();
}

View File

@@ -67,7 +67,7 @@ public class InstalledPluginResource {
})
@TypeHint(CollectionDto.class)
public Response updateAll(@QueryParam("restart") boolean restartAfterInstallation) {
pluginManager.updateAll(restartAfterInstallation);
pluginManager.updateAll();
return Response.ok().build();
}

View File

@@ -288,17 +288,19 @@ public class DefaultPluginManager implements PluginManager {
}
@Override
public void updateAll(boolean restartAfterInstallation) {
public void updateAll() {
PluginPermissions.manage().check();
boolean pluginUpdated = false;
for (InstalledPlugin installedPlugin : getInstalled()) {
String pluginName = installedPlugin.getDescriptor().getInformation().getName();
if (isUpdatable(pluginName)) {
install(pluginName, false);
pluginUpdated = true;
}
if (restartAfterInstallation) {
restart("update all plugin");
}
}
if (pluginUpdated) {
restart("update all plugins");
}
}
}

View File

@@ -28,6 +28,7 @@ class PendingPluginInstallation {
LOG.info("cancel installation of plugin {}", name);
try {
Files.delete(file);
plugin.cancelInstallation();
} catch (IOException ex) {
throw new PluginFailedToCancelInstallationException("failed to cancel installation of plugin " + name, ex);
}

View File

@@ -487,7 +487,7 @@ class DefaultPluginManagerTest {
when(center.getAvailable()).thenReturn(ImmutableSet.of(newMailPlugin, newReviewPlugin));
manager.updateAll(false);
manager.updateAll();
verify(installer).install(newMailPlugin);
verify(installer).install(newReviewPlugin);
@@ -503,7 +503,7 @@ class DefaultPluginManagerTest {
when(center.getAvailable()).thenReturn(ImmutableSet.of(oldScriptPlugin));
manager.updateAll(false);
manager.updateAll();
verify(installer, never()).install(oldScriptPlugin);
}
@@ -569,7 +569,7 @@ class DefaultPluginManagerTest {
@Test
void shouldThrowAuthorizationExceptionsForUpdateAll() {
assertThrows(AuthorizationException.class, () -> manager.updateAll(false));
assertThrows(AuthorizationException.class, () -> manager.updateAll());
}
}
}