mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-04 13:49:13 +01:00
Include cloudogu plugins to plugin center (#1709)
Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
@@ -98,6 +97,7 @@ public class AvailablePluginResource {
|
||||
PluginPermissions.read().check();
|
||||
List<InstalledPlugin> installed = pluginManager.getInstalled();
|
||||
List<AvailablePlugin> available = pluginManager.getAvailable().stream().filter(a -> notInstalled(a, installed)).collect(Collectors.toList());
|
||||
|
||||
return Response.ok(collectionMapper.mapAvailable(available)).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import de.otto.edison.hal.Links;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import sonia.scm.plugin.PluginInformation;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -48,6 +49,7 @@ public class PluginDto extends HalRepresentation {
|
||||
private String author;
|
||||
private String category;
|
||||
private String avatarUrl;
|
||||
private PluginInformation.PluginType type = PluginInformation.PluginType.SCM;
|
||||
private boolean pending;
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Boolean core;
|
||||
|
||||
@@ -36,7 +36,6 @@ import sonia.scm.plugin.PluginInformation;
|
||||
import sonia.scm.plugin.PluginPermissions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -71,6 +70,9 @@ public abstract class PluginDtoMapper {
|
||||
PluginDto dto = createDtoForAvailable(plugin);
|
||||
map(dto, plugin);
|
||||
dto.setPending(plugin.isPending());
|
||||
if (dto.getType() == null) {
|
||||
dto.setType(PluginInformation.PluginType.SCM);
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
@@ -91,8 +93,14 @@ public abstract class PluginDtoMapper {
|
||||
.self(information.getName()));
|
||||
|
||||
if (!plugin.isPending() && PluginPermissions.write().isPermitted()) {
|
||||
String href = resourceLinks.availablePlugin().install(information.getName());
|
||||
appendLink(links, "install", href);
|
||||
boolean isCloudoguPlugin = plugin.getDescriptor().getInformation().getType() == PluginInformation.PluginType.CLOUDOGU;
|
||||
if (isCloudoguPlugin) {
|
||||
Optional<String> cloudoguInstallLink = plugin.getDescriptor().getInstallLink();
|
||||
cloudoguInstallLink.ifPresent(link -> links.single(link("cloudoguInstall", link)));
|
||||
} else {
|
||||
String href = resourceLinks.availablePlugin().install(information.getName());
|
||||
appendLink(links, "install", href);
|
||||
}
|
||||
}
|
||||
|
||||
return new PluginDto(links.build());
|
||||
|
||||
@@ -37,9 +37,9 @@ import javax.ws.rs.Path;
|
||||
@Path("v2/plugins")
|
||||
public class PluginRootResource {
|
||||
|
||||
private Provider<InstalledPluginResource> installedPluginResourceProvider;
|
||||
private Provider<AvailablePluginResource> availablePluginResourceProvider;
|
||||
private Provider<PendingPluginResource> pendingPluginResourceProvider;
|
||||
private final Provider<InstalledPluginResource> installedPluginResourceProvider;
|
||||
private final Provider<AvailablePluginResource> availablePluginResourceProvider;
|
||||
private final Provider<PendingPluginResource> pendingPluginResourceProvider;
|
||||
|
||||
@Inject
|
||||
public PluginRootResource(Provider<InstalledPluginResource> installedPluginResourceProvider, Provider<AvailablePluginResource> availablePluginResourceProvider, Provider<PendingPluginResource> pendingPluginResourceProvider) {
|
||||
|
||||
@@ -70,26 +70,27 @@ public final class PluginCenterDto implements Serializable {
|
||||
@AllArgsConstructor
|
||||
public static class Plugin {
|
||||
|
||||
private String name;
|
||||
private String version;
|
||||
private String displayName;
|
||||
private String description;
|
||||
private String category;
|
||||
private String author;
|
||||
private String avatarUrl;
|
||||
private String sha256sum;
|
||||
private final String name;
|
||||
private final String version;
|
||||
private final String displayName;
|
||||
private final String description;
|
||||
private final String category;
|
||||
private final String author;
|
||||
private final String avatarUrl;
|
||||
private final String sha256sum;
|
||||
private PluginInformation.PluginType type;
|
||||
|
||||
@XmlElement(name = "conditions")
|
||||
private Condition conditions;
|
||||
private final Condition conditions;
|
||||
|
||||
@XmlElement(name = "dependencies")
|
||||
private Set<String> dependencies;
|
||||
private final Set<String> dependencies;
|
||||
|
||||
@XmlElement(name = "optionalDependencies")
|
||||
private Set<String> optionalDependencies;
|
||||
private final Set<String> optionalDependencies;
|
||||
|
||||
@XmlElement(name = "_links")
|
||||
private Map<String, Link> links;
|
||||
private final Map<String, Link> links;
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@@ -98,9 +99,9 @@ public final class PluginCenterDto implements Serializable {
|
||||
@AllArgsConstructor
|
||||
public static class Condition {
|
||||
|
||||
private List<String> os;
|
||||
private String arch;
|
||||
private String minVersion;
|
||||
private final List<String> os;
|
||||
private final String arch;
|
||||
private final String minVersion;
|
||||
}
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
@@ -31,22 +31,32 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Mapper
|
||||
public abstract class PluginCenterDtoMapper {
|
||||
public abstract class PluginCenterDtoMapper {
|
||||
|
||||
static final PluginCenterDtoMapper INSTANCE = Mappers.getMapper(PluginCenterDtoMapper.class);
|
||||
|
||||
abstract PluginInformation map(PluginCenterDto.Plugin plugin);
|
||||
|
||||
abstract PluginCondition map(PluginCenterDto.Condition condition);
|
||||
|
||||
Set<AvailablePlugin> map(PluginCenterDto pluginCenterDto) {
|
||||
Set<AvailablePlugin> plugins = new HashSet<>();
|
||||
for (PluginCenterDto.Plugin plugin : pluginCenterDto.getEmbedded().getPlugins()) {
|
||||
String url = plugin.getLinks().get("download").getHref();
|
||||
String installLink = getInstallLink(plugin);
|
||||
AvailablePluginDescriptor descriptor = new AvailablePluginDescriptor(
|
||||
map(plugin), map(plugin.getConditions()), plugin.getDependencies(), plugin.getOptionalDependencies(), url, plugin.getSha256sum()
|
||||
map(plugin), map(plugin.getConditions()), plugin.getDependencies(), plugin.getOptionalDependencies(), url, plugin.getSha256sum(), installLink
|
||||
);
|
||||
plugins.add(new AvailablePlugin(descriptor));
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
private String getInstallLink(PluginCenterDto.Plugin plugin) {
|
||||
PluginCenterDto.Link link = plugin.getLinks().get("install");
|
||||
if (link != null) {
|
||||
return link.getHref();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user