refactor plugin backend + fix tests

This commit is contained in:
Eduard Heimbuch
2019-07-29 11:52:53 +02:00
parent 27dc47a590
commit 785e5e1142
13 changed files with 54 additions and 165 deletions

View File

@@ -44,11 +44,8 @@ import sonia.scm.util.Util;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
@@ -87,29 +84,18 @@ public class PluginInformation
public PluginInformation clone() public PluginInformation clone()
{ {
PluginInformation clone = new PluginInformation(); PluginInformation clone = new PluginInformation();
clone.setName(name);
clone.setAuthor(author); clone.setAuthor(author);
clone.setCategory(category); clone.setCategory(category);
clone.setTags(tags); clone.setDescription(description);
clone.setState(state);
clone.setVersion(version);
if (condition != null) if (condition != null)
{ {
clone.setCondition(condition.clone()); clone.setCondition(condition.clone());
} }
clone.setDescription(description);
clone.setName(name);
if (Util.isNotEmpty(screenshots))
{
clone.setScreenshots(new ArrayList<String>(screenshots));
}
clone.setState(state);
clone.setUrl(url);
clone.setVersion(version);
clone.setWiki(wiki);
return clone; return clone;
} }
@@ -140,15 +126,11 @@ public class PluginInformation
return return
Objects.equal(author, other.author) Objects.equal(author, other.author)
&& Objects.equal(category, other.category) && Objects.equal(category, other.category)
&& Objects.equal(tags, other.tags)
&& 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(screenshots, other.screenshots)
&& Objects.equal(state, other.state) && Objects.equal(state, other.state)
&& Objects.equal(url, other.url) && Objects.equal(version, other.version);
&& Objects.equal(version, other.version)
&& Objects.equal(wiki, other.wiki);
//J+ //J+
} }
@@ -161,8 +143,8 @@ public class PluginInformation
@Override @Override
public int hashCode() public int hashCode()
{ {
return Objects.hashCode(author, category, tags, condition, return Objects.hashCode(author, category, condition,
description, name, screenshots, state, url, version, wiki); description, name, state, version);
} }
/** /**
@@ -178,15 +160,11 @@ public class PluginInformation
return MoreObjects.toStringHelper(this) return MoreObjects.toStringHelper(this)
.add("author", author) .add("author", author)
.add("category", category) .add("category", category)
.add("tags", tags)
.add("condition", condition) .add("condition", condition)
.add("description", description) .add("description", description)
.add("name", name) .add("name", name)
.add("screenshots", screenshots)
.add("state", state) .add("state", state)
.add("url", url)
.add("version", version) .add("version", version)
.add("wiki", wiki)
.toString(); .toString();
//J+ //J+
} }
@@ -282,17 +260,6 @@ public class PluginInformation
return name; return name;
} }
/**
* Method description
*
*
* @return
*/
public List<String> getScreenshots()
{
return screenshots;
}
/** /**
* Method description * Method description
* *
@@ -304,28 +271,6 @@ public class PluginInformation
return state; return state;
} }
/**
* Method description
*
*
* @return
*/
public List<String> getTags()
{
return tags;
}
/**
* Method description
*
*
* @return
*/
public String getUrl()
{
return url;
}
/** /**
* Method description * Method description
* *
@@ -343,9 +288,8 @@ public class PluginInformation
* *
* @return * @return
*/ */
public String getWiki() public List<String> getLinks() {
{ return links;
return wiki;
} }
/** /**
@@ -362,7 +306,6 @@ public class PluginInformation
//~--- set methods ---------------------------------------------------------- //~--- set methods ----------------------------------------------------------
/** /**
* Method description * Method description
* *
@@ -419,17 +362,6 @@ public class PluginInformation
this.name = name; this.name = name;
} }
/**
* Method description
*
*
* @param screenshots
*/
public void setScreenshots(List<String> screenshots)
{
this.screenshots = screenshots;
}
/** /**
* Method description * Method description
* *
@@ -441,28 +373,6 @@ public class PluginInformation
this.state = state; this.state = state;
} }
/**
* Method description
*
*
* @param tags
*/
public void setTags(List<String> tags)
{
this.tags = tags;
}
/**
* Method description
*
*
* @param url
*/
public void setUrl(String url)
{
this.url = url;
}
/** /**
* Method description * Method description
* *
@@ -474,15 +384,15 @@ public class PluginInformation
this.version = version; this.version = version;
} }
/** /**
* Method description * Method description
* *
* *
* @param wiki * @param links
*/ */
public void setWiki(String wiki) public void setLinks(List<String> links) {
{ this.links = links;
this.wiki = wiki;
} }
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
@@ -502,25 +412,13 @@ public class PluginInformation
/** Field description */ /** Field description */
private String name; private String name;
/** Field description */
@XmlElement(name = "screenshot")
@XmlElementWrapper(name = "screenshots")
private List<String> screenshots;
/** Field description */ /** Field description */
private PluginState state; private PluginState state;
/** Field description */
@XmlElement(name = "tag")
@XmlElementWrapper(name = "tags")
private List<String> tags;
/** Field description */
private String url;
/** Field description */ /** Field description */
private String version; private String version;
/** Field description */ /** Field description */
private String wiki; private List<String> links;
} }

View File

@@ -648,7 +648,6 @@ public class DefaultPluginManager implements PluginManager
pluginInformation.setCategory(plugin.getCategory()); pluginInformation.setCategory(plugin.getCategory());
pluginInformation.setVersion(plugin.getVersion()); pluginInformation.setVersion(plugin.getVersion());
pluginInformation.setDescription(plugin.getDescription()); pluginInformation.setDescription(plugin.getDescription());
pluginInformation.setUrl(plugin.getLinks().getDownload());
if (plugin.getConditions() != null) { if (plugin.getConditions() != null) {
PluginCenterDto.Condition condition = plugin.getConditions(); PluginCenterDto.Condition condition = plugin.getConditions();

View File

@@ -318,10 +318,7 @@ public final class PluginProcessor
{ {
for (Path parent : parentStream) for (Path parent : parentStream)
{ {
try (DirectoryStream<Path> direcotries = stream(parent, filter)) paths.add(parent);
{
paths.addAll(direcotries);
}
} }
} }
@@ -333,7 +330,6 @@ public final class PluginProcessor
* *
* *
* @param parentClassLoader * @param parentClassLoader
* @param directory
* @param smp * @param smp
* *
* @return * @return
@@ -472,7 +468,6 @@ public final class PluginProcessor
* *
* *
* @param classLoader * @param classLoader
* @param directory
* @param smp * @param smp
* *
* @return * @return
@@ -511,7 +506,6 @@ public final class PluginProcessor
* *
* *
* @param classLoader * @param classLoader
* @param smps
* @param rootNodes * @param rootNodes
* *
* @return * @return

View File

@@ -36,6 +36,8 @@ public class ResourceLinksMock {
when(resourceLinks.modifications()).thenReturn(new ResourceLinks.ModificationsLinks(uriInfo)); when(resourceLinks.modifications()).thenReturn(new ResourceLinks.ModificationsLinks(uriInfo));
when(resourceLinks.repositoryType()).thenReturn(new ResourceLinks.RepositoryTypeLinks(uriInfo)); when(resourceLinks.repositoryType()).thenReturn(new ResourceLinks.RepositoryTypeLinks(uriInfo));
when(resourceLinks.repositoryTypeCollection()).thenReturn(new ResourceLinks.RepositoryTypeCollectionLinks(uriInfo)); when(resourceLinks.repositoryTypeCollection()).thenReturn(new ResourceLinks.RepositoryTypeCollectionLinks(uriInfo));
when(resourceLinks.pluginCollection()).thenReturn(new ResourceLinks.PluginCollectionLinks(uriInfo));
when(resourceLinks.plugin()).thenReturn(new ResourceLinks.PluginLinks(uriInfo));
when(resourceLinks.uiPluginCollection()).thenReturn(new ResourceLinks.UIPluginCollectionLinks(uriInfo)); when(resourceLinks.uiPluginCollection()).thenReturn(new ResourceLinks.UIPluginCollectionLinks(uriInfo));
when(resourceLinks.uiPlugin()).thenReturn(new ResourceLinks.UIPluginLinks(uriInfo)); when(resourceLinks.uiPlugin()).thenReturn(new ResourceLinks.UIPluginLinks(uriInfo));
when(resourceLinks.authentication()).thenReturn(new ResourceLinks.AuthenticationLinks(uriInfo)); when(resourceLinks.authentication()).thenReturn(new ResourceLinks.AuthenticationLinks(uriInfo));

View File

@@ -60,12 +60,12 @@ public class ExplodedSmpTest
@Test @Test
public void testCompareTo() public void testCompareTo()
{ {
ExplodedSmp e1 = create("a", "c", "1", "a:a"); ExplodedSmp e1 = create("a", "c", "1", "a");
ExplodedSmp e3 = create("a", "a", "1"); ExplodedSmp e3 = create("a", "a", "1");
ExplodedSmp e2 = create("a", "b", "1"); ExplodedSmp e2 = create("a", "b", "1");
List<ExplodedSmp> es = list(e1, e2, e3); List<ExplodedSmp> es = list(e1, e2, e3);
is(es, 2, "c"); is(es, 2, "a");
} }
/** /**
@@ -75,9 +75,9 @@ public class ExplodedSmpTest
@Test(expected = PluginCircularDependencyException.class) @Test(expected = PluginCircularDependencyException.class)
public void testCompareToCyclicDependency() public void testCompareToCyclicDependency()
{ {
ExplodedSmp e1 = create("a", "a", "1", "a:c"); ExplodedSmp e1 = create("a", "1", "c");
ExplodedSmp e2 = create("a", "b", "1"); ExplodedSmp e2 = create("b", "1");
ExplodedSmp e3 = create("a", "c", "1", "a:a"); ExplodedSmp e3 = create("c", "1", "a");
list(e1, e2, e3); list(e1, e2, e3);
} }
@@ -89,9 +89,9 @@ public class ExplodedSmpTest
@Test @Test
public void testCompareToTransitiveDependencies() public void testCompareToTransitiveDependencies()
{ {
ExplodedSmp e1 = create("a", "a", "1", "a:b"); ExplodedSmp e1 = create("a", "1", "b");
ExplodedSmp e2 = create("a", "b", "1"); ExplodedSmp e2 = create("b", "1");
ExplodedSmp e3 = create("a", "c", "1", "a:a"); ExplodedSmp e3 = create("c", "1", "a");
List<ExplodedSmp> es = list(e1, e2, e3); List<ExplodedSmp> es = list(e1, e2, e3);
@@ -107,9 +107,9 @@ public class ExplodedSmpTest
@Test @Test
public void testMultipleDependencies() public void testMultipleDependencies()
{ {
ExplodedSmp e1 = create("a", "a", "1", "a:b", "a:c"); ExplodedSmp e1 = create("a", "1", "b", "c");
ExplodedSmp e2 = create("a", "b", "1", "a:c"); ExplodedSmp e2 = create("b", "1", "c");
ExplodedSmp e3 = create("a", "c", "1"); ExplodedSmp e3 = create("c", "1");
List<ExplodedSmp> es = list(e1, e2, e3); List<ExplodedSmp> es = list(e1, e2, e3);
is(es, 2, "a"); is(es, 2, "a");
@@ -119,20 +119,18 @@ public class ExplodedSmpTest
* Method description * Method description
* *
* *
* @param groupId * @param name
* @param artifactId
* @param version * @param version
* @param dependencies * @param dependencies
* *
* @return * @return
*/ */
private ExplodedSmp create(String groupId, String artifactId, String version, private ExplodedSmp create(String name, String version,
String... dependencies) String... dependencies)
{ {
PluginInformation info = new PluginInformation(); PluginInformation info = new PluginInformation();
info.setGroupId(groupId); info.setName(name);
info.setArtifactId(artifactId);
info.setVersion(version); info.setVersion(version);
Plugin plugin = new Plugin(2, info, null, null, false, Plugin plugin = new Plugin(2, info, null, null, false,
@@ -170,6 +168,6 @@ public class ExplodedSmpTest
*/ */
private void is(List<ExplodedSmp> es, int p, String a) private void is(List<ExplodedSmp> es, int p, String a)
{ {
assertEquals(a, es.get(p).getPlugin().getInformation().getArtifactId()); assertEquals(a, es.get(p).getPlugin().getInformation().getName());
} }
} }

View File

@@ -71,37 +71,37 @@ public class PluginProcessorTest
/** Field description */ /** Field description */
private static final PluginResource PLUGIN_A = private static final PluginResource PLUGIN_A =
new PluginResource("sonia/scm/plugin/scm-a-plugin.smp", "scm-a-plugin.smp", new PluginResource("sonia/scm/plugin/scm-a-plugin.smp", "scm-a-plugin.smp",
"sonia.scm.plugins:scm-a-plugin:1.0.0-SNAPSHOT"); "scm-a-plugin:1.0.0-SNAPSHOT");
/** Field description */ /** Field description */
private static final PluginResource PLUGIN_B = private static final PluginResource PLUGIN_B =
new PluginResource("sonia/scm/plugin/scm-b-plugin.smp", "scm-b-plugin.smp", new PluginResource("sonia/scm/plugin/scm-b-plugin.smp", "scm-b-plugin.smp",
"sonia.scm.plugins:scm-b-plugin:1.0.0-SNAPSHOT"); "scm-b-plugin:1.0.0-SNAPSHOT");
/** Field description */ /** Field description */
private static final PluginResource PLUGIN_C = private static final PluginResource PLUGIN_C =
new PluginResource("sonia/scm/plugin/scm-c-plugin.smp", "scm-c-plugin.smp", new PluginResource("sonia/scm/plugin/scm-c-plugin.smp", "scm-c-plugin.smp",
"sonia.scm.plugins:scm-c-plugin:1.0.0-SNAPSHOT"); "scm-c-plugin:1.0.0-SNAPSHOT");
/** Field description */ /** Field description */
private static final PluginResource PLUGIN_D = private static final PluginResource PLUGIN_D =
new PluginResource("sonia/scm/plugin/scm-d-plugin.smp", "scm-d-plugin.smp", new PluginResource("sonia/scm/plugin/scm-d-plugin.smp", "scm-d-plugin.smp",
"sonia.scm.plugins:scm-d-plugin:1.0.0-SNAPSHOT"); "scm-d-plugin:1.0.0-SNAPSHOT");
/** Field description */ /** Field description */
private static final PluginResource PLUGIN_E = private static final PluginResource PLUGIN_E =
new PluginResource("sonia/scm/plugin/scm-e-plugin.smp", "scm-e-plugin.smp", new PluginResource("sonia/scm/plugin/scm-e-plugin.smp", "scm-e-plugin.smp",
"sonia.scm.plugins:scm-e-plugin:1.0.0-SNAPSHOT"); "scm-e-plugin:1.0.0-SNAPSHOT");
/** Field description */ /** Field description */
private static final PluginResource PLUGIN_F_1_0_0 = private static final PluginResource PLUGIN_F_1_0_0 =
new PluginResource("sonia/scm/plugin/scm-f-plugin-1.0.0.smp", new PluginResource("sonia/scm/plugin/scm-f-plugin-1.0.0.smp",
"scm-f-plugin.smp", "sonia.scm.plugins:scm-f-plugin:1.0.0"); "scm-f-plugin.smp", "scm-f-plugin:1.0.0");
/** Field description */ /** Field description */
private static final PluginResource PLUGIN_F_1_0_1 = private static final PluginResource PLUGIN_F_1_0_1 =
new PluginResource("sonia/scm/plugin/scm-f-plugin-1.0.1.smp", new PluginResource("sonia/scm/plugin/scm-f-plugin-1.0.1.smp",
"scm-f-plugin.smp", "sonia.scm.plugins:scm-f-plugin:1.0.1"); "scm-f-plugin.smp", "scm-f-plugin:1.0.1");
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------

View File

@@ -71,7 +71,7 @@ public class PluginTreeTest
{ {
PluginCondition condition = new PluginCondition("999", PluginCondition condition = new PluginCondition("999",
new ArrayList<String>(), "hit"); new ArrayList<String>(), "hit");
Plugin plugin = new Plugin(2, createInfo("a", "b", "1"), null, condition, Plugin plugin = new Plugin(2, createInfo("a", "1"), null, condition,
false, null); false, null);
ExplodedSmp smp = createSmp(plugin); ExplodedSmp smp = createSmp(plugin);
@@ -102,7 +102,7 @@ public class PluginTreeTest
List<ExplodedSmp> smps = createSmps("a", "b", "c"); List<ExplodedSmp> smps = createSmps("a", "b", "c");
List<String> nodes = unwrapIds(new PluginTree(smps).getRootNodes()); List<String> nodes = unwrapIds(new PluginTree(smps).getRootNodes());
assertThat(nodes, containsInAnyOrder("a:a", "b:b", "c:c")); assertThat(nodes, containsInAnyOrder("a", "b", "c"));
} }
/** /**
@@ -114,7 +114,7 @@ public class PluginTreeTest
@Test(expected = PluginException.class) @Test(expected = PluginException.class)
public void testScmVersion() throws IOException public void testScmVersion() throws IOException
{ {
Plugin plugin = new Plugin(1, createInfo("a", "b", "1"), null, null, false, Plugin plugin = new Plugin(1, createInfo("a", "1"), null, null, false,
null); null);
ExplodedSmp smp = createSmp(plugin); ExplodedSmp smp = createSmp(plugin);
@@ -141,34 +141,32 @@ public class PluginTreeTest
PluginTree tree = new PluginTree(smps); PluginTree tree = new PluginTree(smps);
List<PluginNode> rootNodes = tree.getRootNodes(); List<PluginNode> rootNodes = tree.getRootNodes();
assertThat(unwrapIds(rootNodes), containsInAnyOrder("a:a")); assertThat(unwrapIds(rootNodes), containsInAnyOrder("a"));
PluginNode a = rootNodes.get(0); PluginNode a = rootNodes.get(0);
assertThat(unwrapIds(a.getChildren()), containsInAnyOrder("b:b", "c:c")); assertThat(unwrapIds(a.getChildren()), containsInAnyOrder("b", "c"));
PluginNode b = a.getChild("b:b"); PluginNode b = a.getChild("b");
assertThat(unwrapIds(b.getChildren()), containsInAnyOrder("c:c")); assertThat(unwrapIds(b.getChildren()), containsInAnyOrder("c"));
} }
/** /**
* Method description * Method description
* *
* *
* @param groupId * @param name
* @param artifactId
* @param version * @param version
* *
* @return * @return
*/ */
private PluginInformation createInfo(String groupId, String artifactId, private PluginInformation createInfo(String name,
String version) String version)
{ {
PluginInformation info = new PluginInformation(); PluginInformation info = new PluginInformation();
info.setGroupId(groupId); info.setName(name);
info.setArtifactId(artifactId);
info.setVersion(version); info.setVersion(version);
return info; return info;
@@ -201,7 +199,7 @@ public class PluginTreeTest
*/ */
private ExplodedSmp createSmp(String name) throws IOException private ExplodedSmp createSmp(String name) throws IOException
{ {
return createSmp(new Plugin(2, createInfo(name, name, "1.0.0"), null, null, return createSmp(new Plugin(2, createInfo(name, "1.0.0"), null, null,
false, null)); false, null));
} }
@@ -224,10 +222,10 @@ public class PluginTreeTest
for (String d : dependencies) for (String d : dependencies)
{ {
dependencySet.add(d.concat(":").concat(d)); dependencySet.add(d);
} }
Plugin plugin = new Plugin(2, createInfo(name, name, "1"), null, null, Plugin plugin = new Plugin(2, createInfo(name, "1"), null, null,
false, dependencySet); false, dependencySet);
return createSmp(plugin); return createSmp(plugin);