add avatarUrl / fix conditions_os to list of string

This commit is contained in:
Eduard Heimbuch
2019-08-12 11:16:47 +02:00
parent b102c19f5f
commit c58788e1e5
8 changed files with 88 additions and 319 deletions

View File

@@ -1,19 +1,19 @@
/** /**
* Copyright (c) 2010, Sebastian Sdorra * Copyright (c) 2010, Sebastian Sdorra
* All rights reserved. * All rights reserved.
* * <p>
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * <p>
* 1. Redistributions of source code must retain the above copyright notice, * 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, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. Neither the name of SCM-Manager; nor the names of its * 3. Neither the name of SCM-Manager; nor the names of its
* contributors may be used to endorse or promote products derived from this * contributors may be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* * <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 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 * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* * <p>
* http://bitbucket.org/sdorra/scm-manager * http://bitbucket.org/sdorra/scm-manager
*
*/ */
package sonia.scm.plugin; package sonia.scm.plugin;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
@@ -39,6 +37,8 @@ import com.github.sdorra.ssp.PermissionObject;
import com.github.sdorra.ssp.StaticPermissions; import com.github.sdorra.ssp.StaticPermissions;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import lombok.Getter;
import lombok.Setter;
import sonia.scm.Validateable; import sonia.scm.Validateable;
import sonia.scm.util.Util; 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.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
import java.util.Map;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
/** /**
*
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@StaticPermissions( @StaticPermissions(
value = "plugin", value = "plugin",
generatedClass = "PluginPermissions", generatedClass = "PluginPermissions",
permissions = {}, permissions = {},
globalPermissions = { "read", "manage" }, globalPermissions = {"read", "manage"},
custom = true, customGlobal = true custom = true, customGlobal = true
) )
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "plugin-information") @XmlRootElement(name = "plugin-information")
public class PluginInformation @Getter
implements PermissionObject, Validateable, Cloneable, Serializable @Setter
{ public class PluginInformation implements PermissionObject, Validateable, Cloneable, Serializable {
/** Field description */
private static final long serialVersionUID = 461382048865977206L; 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 @Override
public PluginInformation clone() public PluginInformation clone() {
{
PluginInformation clone = new PluginInformation(); PluginInformation clone = new PluginInformation();
clone.setName(name); clone.setName(name);
clone.setAuthor(author); clone.setAuthor(author);
@@ -90,33 +85,22 @@ public class PluginInformation
clone.setDescription(description); clone.setDescription(description);
clone.setState(state); clone.setState(state);
clone.setVersion(version); clone.setVersion(version);
clone.setAvatarUrl(avatarUrl);
if (condition != null) if (condition != null) {
{
clone.setCondition(condition.clone()); clone.setCondition(condition.clone());
} }
return clone; return clone;
} }
/**
* Method description
*
*
* @param obj
*
* @return
*/
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{ if (obj == null) {
if (obj == null)
{
return false; return false;
} }
if (getClass() != obj.getClass()) if (getClass() != obj.getClass()) {
{
return false; return false;
} }
@@ -125,276 +109,54 @@ public class PluginInformation
//J- //J-
return return
Objects.equal(author, other.author) Objects.equal(author, other.author)
&& Objects.equal(category, other.category) && Objects.equal(category, other.category)
&& Objects.equal(condition, other.condition) && Objects.equal(condition, other.condition)
&& Objects.equal(description, other.description) && Objects.equal(description, other.description)
&& Objects.equal(name, other.name) && Objects.equal(name, other.name)
&& Objects.equal(state, other.state) && Objects.equal(state, other.state)
&& Objects.equal(version, other.version); && Objects.equal(version, other.version)
&& Objects.equal(avatarUrl, other.avatarUrl);
//J+ //J+
} }
/**
* Method description
*
*
* @return
*/
@Override @Override
public int hashCode() public int hashCode() {
{
return Objects.hashCode(author, category, condition, return Objects.hashCode(author, category, condition,
description, name, state, version); description, name, state, version, avatarUrl);
} }
/**
* Method description
*
*
* @return
*/
@Override @Override
public String toString() public String toString() {
{
//J- //J-
return MoreObjects.toStringHelper(this) return MoreObjects.toStringHelper(this)
.add("author", author) .add("author", author)
.add("category", category) .add("category", category)
.add("condition", condition) .add("condition", condition)
.add("description", description) .add("description", description)
.add("name", name) .add("name", name)
.add("state", state) .add("state", state)
.add("version", version) .add("version", version)
.toString(); .add("avatarUrl", avatarUrl)
.toString();
//J+ //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 @Override
public String getId() public String getId() {
{
return getName(true); return getName(true);
} }
/** public String getName(boolean withVersion) {
* Method description
*
*
* @param withVersion
*
* @return
* @since 1.21
*/
public String getName(boolean withVersion)
{
StringBuilder id = new StringBuilder(name); StringBuilder id = new StringBuilder(name);
if (withVersion) if (withVersion) {
{
id.append(":").append(version); id.append(":").append(version);
} }
return id.toString(); 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 @Override
public boolean isValid() public boolean isValid() {
{
return Util.isNotEmpty(name) && Util.isNotEmpty(version); 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;
} }

View File

@@ -1,11 +1,12 @@
//@flow //@flow
import type { Collection, Links } from "./hal"; import type {Collection, Links} from "./hal";
export type Plugin = { export type Plugin = {
name: string, name: string,
type: string, type: string,
version: string, version: string,
author: string, author: string,
avatarUrl: string,
description?: string, description?: string,
_links: Links _links: Links
}; };

View File

@@ -1,8 +1,8 @@
//@flow //@flow
import React from "react"; import React from "react";
import { ExtensionPoint } from "@scm-manager/ui-extensions"; import {ExtensionPoint} from "@scm-manager/ui-extensions";
import type { Plugin } from "@scm-manager/ui-types"; import type {Plugin} from "@scm-manager/ui-types";
import { Image } from "@scm-manager/ui-components"; import {Image} from "@scm-manager/ui-components";
type Props = { type Props = {
plugin: Plugin plugin: Plugin
@@ -14,7 +14,7 @@ export default class PluginAvatar extends React.Component<Props> {
return ( return (
<p className="image is-64x64"> <p className="image is-64x64">
<ExtensionPoint name="plugins.plugin-avatar" props={{ plugin }}> <ExtensionPoint name="plugins.plugin-avatar" props={{ plugin }}>
<Image src="/images/blib.jpg" alt="Logo" /> <Image src={plugin.avatarUrl ? plugin.avatarUrl : "/images/blib.jpg"} alt="Logo" />
</ExtensionPoint> </ExtensionPoint>
</p> </p>
); );

View File

@@ -3,7 +3,6 @@ package sonia.scm.api.v2.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
@@ -51,6 +50,7 @@ public final class PluginCenterDto implements Serializable {
private String category; private String category;
private String version; private String version;
private String author; private String author;
private String avatarUrl;
private String sha256; private String sha256;
@XmlElement(name = "conditions") @XmlElement(name = "conditions")
@@ -69,7 +69,7 @@ public final class PluginCenterDto implements Serializable {
@AllArgsConstructor @AllArgsConstructor
public static class Condition { public static class Condition {
private String os; private List<String> os;
private String arch; private String arch;
private String minVersion; private String minVersion;
} }

View File

@@ -3,7 +3,6 @@ package sonia.scm.api.v2.resources;
import sonia.scm.plugin.PluginCondition; import sonia.scm.plugin.PluginCondition;
import sonia.scm.plugin.PluginInformation; import sonia.scm.plugin.PluginInformation;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -24,7 +23,7 @@ public class PluginCenterDtoMapper {
if (plugin.getConditions() != null) { if (plugin.getConditions() != null) {
PluginCenterDto.Condition condition = plugin.getConditions(); 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); pluginInformationSet.add(pluginInformation);

View File

@@ -3,7 +3,6 @@ package sonia.scm.api.v2.resources;
import de.otto.edison.hal.HalRepresentation; import de.otto.edison.hal.HalRepresentation;
import de.otto.edison.hal.Links; import de.otto.edison.hal.Links;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@@ -16,6 +15,7 @@ public class PluginDto extends HalRepresentation {
private String category; private String category;
private String version; private String version;
private String author; private String author;
private String avatarUrl;
private String description; private String description;
public PluginDto(Links links) { public PluginDto(Links links) {

View File

@@ -4,9 +4,10 @@ import de.otto.edison.hal.Links;
import sonia.scm.plugin.PluginInformation; import sonia.scm.plugin.PluginInformation;
import sonia.scm.plugin.PluginState; import sonia.scm.plugin.PluginState;
import sonia.scm.plugin.PluginWrapper; import sonia.scm.plugin.PluginWrapper;
import javax.inject.Inject; 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; import static de.otto.edison.hal.Links.linkingTo;
public class PluginDtoMapper { public class PluginDtoMapper {
@@ -43,6 +44,7 @@ public class PluginDtoMapper {
pluginDto.setVersion(pluginInformation.getVersion()); pluginDto.setVersion(pluginInformation.getVersion());
pluginDto.setAuthor(pluginInformation.getAuthor()); pluginDto.setAuthor(pluginInformation.getAuthor());
pluginDto.setDescription(pluginInformation.getDescription()); pluginDto.setDescription(pluginInformation.getDescription());
pluginDto.setAvatarUrl(pluginInformation.getAvatarUrl());
return pluginDto; return pluginDto;
} }

View File

@@ -12,7 +12,9 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat; 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 { class PluginCenterDtoMapperTest {
@@ -32,8 +34,9 @@ class PluginCenterDtoMapperTest {
"Travel", "Travel",
"2.0.0", "2.0.0",
"trillian", "trillian",
"http://avatar.url",
"555000444", "555000444",
new Condition("linux", "amd64","2.0.0"), new Condition(Collections.singletonList("linux"), "amd64","2.0.0"),
new Dependency("scm-review-plugin"), new Dependency("scm-review-plugin"),
new HashMap<>()); new HashMap<>());
@@ -44,7 +47,7 @@ class PluginCenterDtoMapperTest {
assertThat(result.getVersion()).isEqualTo(plugin.getVersion()); assertThat(result.getVersion()).isEqualTo(plugin.getVersion());
assertThat(result.getCondition().getArch()).isEqualTo(plugin.getConditions().getArch()); assertThat(result.getCondition().getArch()).isEqualTo(plugin.getConditions().getArch());
assertThat(result.getCondition().getMinVersion()).isEqualTo(plugin.getConditions().getMinVersion()); 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.getDescription()).isEqualTo(plugin.getDescription());
assertThat(result.getName()).isEqualTo(plugin.getName()); assertThat(result.getName()).isEqualTo(plugin.getName());
} }
@@ -52,26 +55,28 @@ class PluginCenterDtoMapperTest {
@Test @Test
void shouldMapMultiplePlugins() { void shouldMapMultiplePlugins() {
Plugin plugin1 = new Plugin( 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-review-plugin",
"SCM Hitchhiker Plugin", "SCM Hitchhiker Plugin",
"plugin for hitchhikers", "plugin for hitchhikers",
"Travel", "Travel",
"2.1.0", "2.1.0",
"trillian", "trillian",
"https://avatar.url",
"12345678aa", "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 Dependency("scm-review-plugin"),
new HashMap<>()); new HashMap<>());