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

View File

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

View File

@@ -36,6 +36,8 @@ public class ResourceLinksMock {
when(resourceLinks.modifications()).thenReturn(new ResourceLinks.ModificationsLinks(uriInfo));
when(resourceLinks.repositoryType()).thenReturn(new ResourceLinks.RepositoryTypeLinks(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.uiPlugin()).thenReturn(new ResourceLinks.UIPluginLinks(uriInfo));
when(resourceLinks.authentication()).thenReturn(new ResourceLinks.AuthenticationLinks(uriInfo));

View File

@@ -60,12 +60,12 @@ public class ExplodedSmpTest
@Test
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 e2 = create("a", "b", "1");
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)
public void testCompareToCyclicDependency()
{
ExplodedSmp e1 = create("a", "a", "1", "a:c");
ExplodedSmp e2 = create("a", "b", "1");
ExplodedSmp e3 = create("a", "c", "1", "a:a");
ExplodedSmp e1 = create("a", "1", "c");
ExplodedSmp e2 = create("b", "1");
ExplodedSmp e3 = create("c", "1", "a");
list(e1, e2, e3);
}
@@ -89,9 +89,9 @@ public class ExplodedSmpTest
@Test
public void testCompareToTransitiveDependencies()
{
ExplodedSmp e1 = create("a", "a", "1", "a:b");
ExplodedSmp e2 = create("a", "b", "1");
ExplodedSmp e3 = create("a", "c", "1", "a:a");
ExplodedSmp e1 = create("a", "1", "b");
ExplodedSmp e2 = create("b", "1");
ExplodedSmp e3 = create("c", "1", "a");
List<ExplodedSmp> es = list(e1, e2, e3);
@@ -107,9 +107,9 @@ public class ExplodedSmpTest
@Test
public void testMultipleDependencies()
{
ExplodedSmp e1 = create("a", "a", "1", "a:b", "a:c");
ExplodedSmp e2 = create("a", "b", "1", "a:c");
ExplodedSmp e3 = create("a", "c", "1");
ExplodedSmp e1 = create("a", "1", "b", "c");
ExplodedSmp e2 = create("b", "1", "c");
ExplodedSmp e3 = create("c", "1");
List<ExplodedSmp> es = list(e1, e2, e3);
is(es, 2, "a");
@@ -119,20 +119,18 @@ public class ExplodedSmpTest
* Method description
*
*
* @param groupId
* @param artifactId
* @param name
* @param version
* @param dependencies
*
* @return
*/
private ExplodedSmp create(String groupId, String artifactId, String version,
private ExplodedSmp create(String name, String version,
String... dependencies)
{
PluginInformation info = new PluginInformation();
info.setGroupId(groupId);
info.setArtifactId(artifactId);
info.setName(name);
info.setVersion(version);
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)
{
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 */
private static final PluginResource PLUGIN_A =
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 */
private static final PluginResource PLUGIN_B =
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 */
private static final PluginResource PLUGIN_C =
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 */
private static final PluginResource PLUGIN_D =
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 */
private static final PluginResource PLUGIN_E =
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 */
private static final PluginResource PLUGIN_F_1_0_0 =
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 */
private static final PluginResource PLUGIN_F_1_0_1 =
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 --------------------------------------------------------------

View File

@@ -71,7 +71,7 @@ public class PluginTreeTest
{
PluginCondition condition = new PluginCondition("999",
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);
ExplodedSmp smp = createSmp(plugin);
@@ -102,7 +102,7 @@ public class PluginTreeTest
List<ExplodedSmp> smps = createSmps("a", "b", "c");
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)
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);
ExplodedSmp smp = createSmp(plugin);
@@ -141,34 +141,32 @@ public class PluginTreeTest
PluginTree tree = new PluginTree(smps);
List<PluginNode> rootNodes = tree.getRootNodes();
assertThat(unwrapIds(rootNodes), containsInAnyOrder("a:a"));
assertThat(unwrapIds(rootNodes), containsInAnyOrder("a"));
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
*
*
* @param groupId
* @param artifactId
* @param name
* @param version
*
* @return
*/
private PluginInformation createInfo(String groupId, String artifactId,
private PluginInformation createInfo(String name,
String version)
{
PluginInformation info = new PluginInformation();
info.setGroupId(groupId);
info.setArtifactId(artifactId);
info.setName(name);
info.setVersion(version);
return info;
@@ -201,7 +199,7 @@ public class PluginTreeTest
*/
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));
}
@@ -224,10 +222,10 @@ public class PluginTreeTest
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);
return createSmp(plugin);