Append uninstall links

This commit is contained in:
René Pfeuffer
2019-09-16 17:50:05 +02:00
parent 0243edf585
commit fc319f90e3
5 changed files with 91 additions and 7 deletions

View File

@@ -74,10 +74,9 @@ public abstract class PluginDtoMapper {
) {
links.single(link("update", resourceLinks.availablePlugin().install(information.getName())));
}
if (!plugin.isCore()
if (plugin.isUninstallable()
&& (!availablePlugin.isPresent() || !availablePlugin.get().isPending())
&& PluginPermissions.manage().isPermitted()
// TODO check if plugin is no dependency of another plugin
) {
links.single(link("uninstall", resourceLinks.installedPlugin().uninstall(information.getName())));
}

View File

@@ -82,15 +82,16 @@ public class DefaultPluginManager implements PluginManager {
this.center = center;
this.installer = installer;
this.computeRequiredPlugins();
this.computeInstallationDependencies();
}
@VisibleForTesting
synchronized void computeRequiredPlugins() {
synchronized void computeInstallationDependencies() {
loader.getInstalledPlugins()
.stream()
.map(InstalledPlugin::getDescriptor)
.forEach(dependencyTracker::addInstalled);
updateMayUninstallFlag();
}
@Override
@@ -166,6 +167,7 @@ public class DefaultPluginManager implements PluginManager {
for (AvailablePlugin plugin : plugins) {
try {
PendingPluginInstallation pending = installer.install(plugin);
dependencyTracker.addInstalled(plugin.getDescriptor());
pendingInstallations.add(pending);
} catch (PluginInstallException ex) {
cancelPending(pendingInstallations);
@@ -178,6 +180,7 @@ public class DefaultPluginManager implements PluginManager {
restart("plugin installation");
} else {
pendingQueue.addAll(pendingInstallations);
updateMayUninstallFlag();
}
}
}
@@ -197,6 +200,23 @@ public class DefaultPluginManager implements PluginManager {
} catch (IOException e) {
throw new PluginException("could not mark plugin " + name + " in path " + installed.getDirectory() + " for uninstall", e);
}
if (restartAfterInstallation) {
restart("plugin installation");
} else {
updateMayUninstallFlag();
}
}
private void updateMayUninstallFlag() {
loader.getInstalledPlugins()
.forEach(p -> p.setUninstallable(isUninstallable(p)));
}
private boolean isUninstallable(InstalledPlugin p) {
return !p.isCore()
&& !p.isMarkedForUninstall()
&& dependencyTracker.mayUninstall(p.getDescriptor().getInformation().getName());
}
@Override