mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
added rest interface to expose plugin bundles
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import de.otto.edison.hal.Links;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter @NoArgsConstructor
|
||||
public class UIPluginDto extends HalRepresentation {
|
||||
|
||||
private String name;
|
||||
private Iterable<String> bundles;
|
||||
|
||||
public UIPluginDto(String name, Iterable<String> bundles) {
|
||||
this.name = name;
|
||||
this.bundles = bundles;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HalRepresentation add(Links links) {
|
||||
return super.add(links);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import sonia.scm.plugin.PluginLoader;
|
||||
import sonia.scm.plugin.PluginWrapper;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Path("v2/ui")
|
||||
public class UIRootResource {
|
||||
|
||||
private final PluginLoader pluginLoader;
|
||||
|
||||
@Inject
|
||||
public UIRootResource(PluginLoader pluginLoader) {
|
||||
this.pluginLoader = pluginLoader;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("plugins")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public List<UIPluginDto> getInstalledPlugins() {
|
||||
return pluginLoader.getInstalledPlugins()
|
||||
.stream()
|
||||
.filter(this::filter)
|
||||
.map(this::map)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private boolean filter(PluginWrapper plugin) {
|
||||
return plugin.getPlugin().getResources() != null;
|
||||
}
|
||||
|
||||
private UIPluginDto map(PluginWrapper plugin) {
|
||||
return new UIPluginDto(
|
||||
plugin.getPlugin().getInformation().getName(),
|
||||
plugin.getPlugin().getResources().getScriptResources()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user