mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
add rest api updateAllPlugins
This commit is contained in:
@@ -56,6 +56,21 @@ public class InstalledPluginResource {
|
||||
return Response.ok(collectionMapper.mapInstalled(plugins, available)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all installed plugins.
|
||||
*/
|
||||
@POST
|
||||
@Path("/update")
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(CollectionDto.class)
|
||||
public Response updateAll(@QueryParam("restart") boolean restartAfterInstallation) {
|
||||
pluginManager.updateAll(restartAfterInstallation);
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the installed plugin with the given id.
|
||||
*
|
||||
|
||||
@@ -12,6 +12,7 @@ import sonia.scm.plugin.PluginPermissions;
|
||||
import java.util.List;
|
||||
|
||||
import static de.otto.edison.hal.Embedded.embeddedBuilder;
|
||||
import static de.otto.edison.hal.Link.*;
|
||||
import static de.otto.edison.hal.Links.linkingTo;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@@ -44,6 +45,9 @@ public class PluginDtoCollectionMapper {
|
||||
|
||||
Links.Builder linksBuilder = linkingTo()
|
||||
.with(Links.linkingTo().self(baseUrl).build());
|
||||
|
||||
linksBuilder.single(link("update", resourceLinks.installedPluginCollection().update()));
|
||||
|
||||
return linksBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -686,6 +686,10 @@ class ResourceLinks {
|
||||
String self() {
|
||||
return installedPluginCollectionLinkBuilder.method("installedPlugins").parameters().method("getInstalledPlugins").parameters().href();
|
||||
}
|
||||
|
||||
String update() {
|
||||
return installedPluginCollectionLinkBuilder.method("installedPlugins").parameters().method("updateAll").parameters().href();
|
||||
}
|
||||
}
|
||||
|
||||
public AvailablePluginLinks availablePlugin() {
|
||||
|
||||
@@ -193,7 +193,6 @@ public class DefaultPluginManager implements PluginManager {
|
||||
.orElseThrow(() -> NotFoundException.notFound(entity(InstalledPlugin.class, name)));
|
||||
doThrow().violation("plugin is a core plugin and cannot be uninstalled").when(installed.isCore());
|
||||
|
||||
|
||||
markForUninstall(installed);
|
||||
|
||||
if (restartAfterInstallation) {
|
||||
@@ -279,4 +278,19 @@ public class DefaultPluginManager implements PluginManager {
|
||||
pendingUninstallQueue.forEach(PendingPluginUninstallation::cancel);
|
||||
pendingInstallQueue.forEach(PendingPluginInstallation::cancel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAll(boolean restartAfterInstallation) {
|
||||
PluginPermissions.manage().check();
|
||||
|
||||
for (InstalledPlugin installedPlugin : getInstalled()) {
|
||||
String pluginName = installedPlugin.getDescriptor().getInformation().getName();
|
||||
if (isUpdatable(pluginName)) {
|
||||
install(pluginName, false);
|
||||
}
|
||||
if (restartAfterInstallation) {
|
||||
restart("update all plugin");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user