From c58788e1e5572e015c1e80e5889384611cd5f281 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Mon, 12 Aug 2019 11:16:47 +0200 Subject: [PATCH] add avatarUrl / fix conditions_os to list of string --- .../sonia/scm/plugin/PluginInformation.java | 346 +++--------------- .../packages/ui-types/src/Plugin.js | 3 +- .../admin/plugins/components/PluginAvatar.js | 8 +- .../scm/api/v2/resources/PluginCenterDto.java | 4 +- .../v2/resources/PluginCenterDtoMapper.java | 3 +- .../sonia/scm/api/v2/resources/PluginDto.java | 2 +- .../scm/api/v2/resources/PluginDtoMapper.java | 4 +- .../resources/PluginCenterDtoMapperTest.java | 37 +- 8 files changed, 88 insertions(+), 319 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/plugin/PluginInformation.java b/scm-core/src/main/java/sonia/scm/plugin/PluginInformation.java index de0a3ca1e9..99ad1e82e8 100644 --- a/scm-core/src/main/java/sonia/scm/plugin/PluginInformation.java +++ b/scm-core/src/main/java/sonia/scm/plugin/PluginInformation.java @@ -1,19 +1,19 @@ /** * Copyright (c) 2010, Sebastian Sdorra * All rights reserved. - * + *

* Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: - * + *

* 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. + * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. * 3. Neither the name of SCM-Manager; nor the names of its - * contributors may be used to endorse or promote products derived from this - * software without specific prior written permission. - * + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + *

* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -24,13 +24,11 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + *

* http://bitbucket.org/sdorra/scm-manager - * */ - package sonia.scm.plugin; //~--- non-JDK imports -------------------------------------------------------- @@ -39,6 +37,8 @@ import com.github.sdorra.ssp.PermissionObject; import com.github.sdorra.ssp.StaticPermissions; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; +import lombok.Getter; +import lombok.Setter; import sonia.scm.Validateable; import sonia.scm.util.Util; @@ -46,43 +46,38 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; -import java.util.Map; //~--- JDK imports ------------------------------------------------------------ /** - * * @author Sebastian Sdorra */ @StaticPermissions( - value = "plugin", - generatedClass = "PluginPermissions", + value = "plugin", + generatedClass = "PluginPermissions", permissions = {}, - globalPermissions = { "read", "manage" }, + globalPermissions = {"read", "manage"}, custom = true, customGlobal = true ) @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "plugin-information") -public class PluginInformation - implements PermissionObject, Validateable, Cloneable, Serializable -{ +@Getter +@Setter +public class PluginInformation implements PermissionObject, Validateable, Cloneable, Serializable { - /** Field description */ private static final long serialVersionUID = 461382048865977206L; - //~--- methods -------------------------------------------------------------- + private String author; + private String category; + private PluginCondition condition; + private String description; + private String name; + private PluginState state; + private String version; + private String avatarUrl; - /** - * Method description - * - * - * @return - * - * @since 1.11 - */ @Override - public PluginInformation clone() - { + public PluginInformation clone() { PluginInformation clone = new PluginInformation(); clone.setName(name); clone.setAuthor(author); @@ -90,33 +85,22 @@ public class PluginInformation clone.setDescription(description); clone.setState(state); clone.setVersion(version); + clone.setAvatarUrl(avatarUrl); - if (condition != null) - { + if (condition != null) { clone.setCondition(condition.clone()); } return clone; } - /** - * Method description - * - * - * @param obj - * - * @return - */ @Override - public boolean equals(Object obj) - { - if (obj == null) - { + public boolean equals(Object obj) { + if (obj == null) { return false; } - if (getClass() != obj.getClass()) - { + if (getClass() != obj.getClass()) { return false; } @@ -125,276 +109,54 @@ public class PluginInformation //J- return Objects.equal(author, other.author) - && Objects.equal(category, other.category) - && Objects.equal(condition, other.condition) - && Objects.equal(description, other.description) - && Objects.equal(name, other.name) - && Objects.equal(state, other.state) - && Objects.equal(version, other.version); + && Objects.equal(category, other.category) + && Objects.equal(condition, other.condition) + && Objects.equal(description, other.description) + && Objects.equal(name, other.name) + && Objects.equal(state, other.state) + && Objects.equal(version, other.version) + && Objects.equal(avatarUrl, other.avatarUrl); //J+ } - /** - * Method description - * - * - * @return - */ @Override - public int hashCode() - { + public int hashCode() { return Objects.hashCode(author, category, condition, - description, name, state, version); + description, name, state, version, avatarUrl); } - /** - * Method description - * - * - * @return - */ @Override - public String toString() - { + public String toString() { //J- return MoreObjects.toStringHelper(this) - .add("author", author) - .add("category", category) - .add("condition", condition) - .add("description", description) - .add("name", name) - .add("state", state) - .add("version", version) - .toString(); + .add("author", author) + .add("category", category) + .add("condition", condition) + .add("description", description) + .add("name", name) + .add("state", state) + .add("version", version) + .add("avatarUrl", avatarUrl) + .toString(); //J+ } - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - public String getAuthor() - { - return author; - } - - /** - * Method description - * - * - * @return - */ - public String getCategory() - { - return category; - } - - /** - * Method description - * - * - * @return - */ - public PluginCondition getCondition() - { - return condition; - } - - /** - * Method description - * - * - * @return - */ - public String getDescription() - { - return description; - } - - - /** - * Method description - * - * - * @return - */ @Override - public String getId() - { + public String getId() { return getName(true); } - /** - * Method description - * - * - * @param withVersion - * - * @return - * @since 1.21 - */ - public String getName(boolean withVersion) - { + public String getName(boolean withVersion) { StringBuilder id = new StringBuilder(name); - if (withVersion) - { + if (withVersion) { id.append(":").append(version); } - return id.toString(); } - /** - * Method description - * - * - * @return - */ - public String getName() - { - return name; - } - - /** - * Method description - * - * - * @return - */ - public PluginState getState() - { - return state; - } - - /** - * Method description - * - * - * @return - */ - public String getVersion() - { - return version; - } - - /** - * Method description - * - * - * @return - */ @Override - public boolean isValid() - { + public boolean isValid() { return Util.isNotEmpty(name) && Util.isNotEmpty(version); } - - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @param author - */ - public void setAuthor(String author) - { - this.author = author; - } - - /** - * Method description - * - * - * @param category - */ - public void setCategory(String category) - { - this.category = category; - } - - /** - * Method description - * - * - * @param condition - */ - public void setCondition(PluginCondition condition) - { - this.condition = condition; - } - - /** - * Method description - * - * - * @param description - */ - public void setDescription(String description) - { - this.description = description; - } - - - /** - * Method description - * - * - * @param name - */ - public void setName(String name) - { - this.name = name; - } - - /** - * Method description - * - * - * @param state - */ - public void setState(PluginState state) - { - this.state = state; - } - - /** - * Method description - * - * - * @param version - */ - public void setVersion(String version) - { - this.version = version; - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private String author; - - /** Field description */ - private String category; - - /** Field description */ - private PluginCondition condition; - - /** Field description */ - private String description; - - /** Field description */ - private String name; - - /** Field description */ - private PluginState state; - - /** Field description */ - private String version; - } diff --git a/scm-ui-components/packages/ui-types/src/Plugin.js b/scm-ui-components/packages/ui-types/src/Plugin.js index bb9c5e7d88..72e4908a54 100644 --- a/scm-ui-components/packages/ui-types/src/Plugin.js +++ b/scm-ui-components/packages/ui-types/src/Plugin.js @@ -1,11 +1,12 @@ //@flow -import type { Collection, Links } from "./hal"; +import type {Collection, Links} from "./hal"; export type Plugin = { name: string, type: string, version: string, author: string, + avatarUrl: string, description?: string, _links: Links }; diff --git a/scm-ui/src/admin/plugins/components/PluginAvatar.js b/scm-ui/src/admin/plugins/components/PluginAvatar.js index 10408f14bd..42a1fd732b 100644 --- a/scm-ui/src/admin/plugins/components/PluginAvatar.js +++ b/scm-ui/src/admin/plugins/components/PluginAvatar.js @@ -1,8 +1,8 @@ //@flow import React from "react"; -import { ExtensionPoint } from "@scm-manager/ui-extensions"; -import type { Plugin } from "@scm-manager/ui-types"; -import { Image } from "@scm-manager/ui-components"; +import {ExtensionPoint} from "@scm-manager/ui-extensions"; +import type {Plugin} from "@scm-manager/ui-types"; +import {Image} from "@scm-manager/ui-components"; type Props = { plugin: Plugin @@ -14,7 +14,7 @@ export default class PluginAvatar extends React.Component { return (

- Logo + Logo

); diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginCenterDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginCenterDto.java index 2b72e7fddc..423a0ba0d2 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginCenterDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginCenterDto.java @@ -3,7 +3,6 @@ package sonia.scm.api.v2.resources; import com.google.common.collect.ImmutableList; import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.Setter; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -51,6 +50,7 @@ public final class PluginCenterDto implements Serializable { private String category; private String version; private String author; + private String avatarUrl; private String sha256; @XmlElement(name = "conditions") @@ -69,7 +69,7 @@ public final class PluginCenterDto implements Serializable { @AllArgsConstructor public static class Condition { - private String os; + private List os; private String arch; private String minVersion; } diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginCenterDtoMapper.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginCenterDtoMapper.java index 4ec5a48667..3a4e8a1947 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginCenterDtoMapper.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginCenterDtoMapper.java @@ -3,7 +3,6 @@ package sonia.scm.api.v2.resources; import sonia.scm.plugin.PluginCondition; import sonia.scm.plugin.PluginInformation; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -24,7 +23,7 @@ public class PluginCenterDtoMapper { if (plugin.getConditions() != null) { PluginCenterDto.Condition condition = plugin.getConditions(); - pluginInformation.setCondition(new PluginCondition(condition.getMinVersion(), Collections.singletonList(condition.getOs()), condition.getArch())); + pluginInformation.setCondition(new PluginCondition(condition.getMinVersion(), condition.getOs(), condition.getArch())); } pluginInformationSet.add(pluginInformation); diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginDto.java index a35c3e848d..75386aed63 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginDto.java @@ -3,7 +3,6 @@ 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; @@ -16,6 +15,7 @@ public class PluginDto extends HalRepresentation { private String category; private String version; private String author; + private String avatarUrl; private String description; public PluginDto(Links links) { diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginDtoMapper.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginDtoMapper.java index 9604ccbcc0..020e706e43 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginDtoMapper.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/PluginDtoMapper.java @@ -4,9 +4,10 @@ import de.otto.edison.hal.Links; import sonia.scm.plugin.PluginInformation; import sonia.scm.plugin.PluginState; import sonia.scm.plugin.PluginWrapper; + import javax.inject.Inject; -import static de.otto.edison.hal.Link.*; +import static de.otto.edison.hal.Link.link; import static de.otto.edison.hal.Links.linkingTo; public class PluginDtoMapper { @@ -43,6 +44,7 @@ public class PluginDtoMapper { pluginDto.setVersion(pluginInformation.getVersion()); pluginDto.setAuthor(pluginInformation.getAuthor()); pluginDto.setDescription(pluginInformation.getDescription()); + pluginDto.setAvatarUrl(pluginInformation.getAvatarUrl()); return pluginDto; } diff --git a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/PluginCenterDtoMapperTest.java b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/PluginCenterDtoMapperTest.java index ecbc44a1ed..1175526f75 100644 --- a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/PluginCenterDtoMapperTest.java +++ b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/PluginCenterDtoMapperTest.java @@ -12,7 +12,9 @@ import java.util.List; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; -import static sonia.scm.api.v2.resources.PluginCenterDto.*; +import static sonia.scm.api.v2.resources.PluginCenterDto.Condition; +import static sonia.scm.api.v2.resources.PluginCenterDto.Dependency; +import static sonia.scm.api.v2.resources.PluginCenterDto.Plugin; class PluginCenterDtoMapperTest { @@ -32,8 +34,9 @@ class PluginCenterDtoMapperTest { "Travel", "2.0.0", "trillian", + "http://avatar.url", "555000444", - new Condition("linux", "amd64","2.0.0"), + new Condition(Collections.singletonList("linux"), "amd64","2.0.0"), new Dependency("scm-review-plugin"), new HashMap<>()); @@ -44,7 +47,7 @@ class PluginCenterDtoMapperTest { assertThat(result.getVersion()).isEqualTo(plugin.getVersion()); assertThat(result.getCondition().getArch()).isEqualTo(plugin.getConditions().getArch()); assertThat(result.getCondition().getMinVersion()).isEqualTo(plugin.getConditions().getMinVersion()); - assertThat(result.getCondition().getOs().iterator().next()).isEqualTo(plugin.getConditions().getOs()); + assertThat(result.getCondition().getOs().iterator().next()).isEqualTo(plugin.getConditions().getOs().iterator().next()); assertThat(result.getDescription()).isEqualTo(plugin.getDescription()); assertThat(result.getName()).isEqualTo(plugin.getName()); } @@ -52,26 +55,28 @@ class PluginCenterDtoMapperTest { @Test void shouldMapMultiplePlugins() { Plugin plugin1 = new Plugin( - "scm-hitchhiker-plugin", - "SCM Hitchhiker Plugin", - "plugin for hitchhikers", - "Travel", - "2.0.0", - "dent", - "555000444", - new Condition("linux", "amd64","2.0.0"), - new Dependency("scm-review-plugin"), - new HashMap<>()); - - Plugin plugin2 = new Plugin( "scm-review-plugin", "SCM Hitchhiker Plugin", "plugin for hitchhikers", "Travel", "2.1.0", "trillian", + "https://avatar.url", "12345678aa", - new Condition("linux", "amd64","2.0.0"), + new Condition(Collections.singletonList("linux"), "amd64","2.0.0"), + new Dependency("scm-review-plugin"), + new HashMap<>()); + + Plugin plugin2 = new Plugin( + "scm-hitchhiker-plugin", + "SCM Hitchhiker Plugin", + "plugin for hitchhikers", + "Travel", + "2.0.0", + "dent", + "http://avatar.url", + "555000444", + new Condition(Collections.singletonList("linux"), "amd64","2.0.0"), new Dependency("scm-review-plugin"), new HashMap<>());