adds versions to dependencies of the InstalledPluginDescriptor

This commit is contained in:
Sebastian Sdorra
2020-08-05 08:02:58 +02:00
parent 592282eb0f
commit c984844f25
4 changed files with 280 additions and 13 deletions

View File

@@ -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;
//~--- non-JDK imports --------------------------------------------------------
@@ -37,6 +37,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Set;
import java.util.stream.Collectors;
//~--- JDK imports ------------------------------------------------------------
@@ -67,7 +68,11 @@ public final class InstalledPluginDescriptor extends ScmModule implements Plugin
* @param condition
* @param childFirstClassLoader
* @param dependencies
*
* @deprecated this constructor uses dependencies with plain strings,
* this is deprecated because the version information is missing.
*/
@Deprecated
public InstalledPluginDescriptor(int scmVersion, PluginInformation information,
PluginResources resources, PluginCondition condition,
boolean childFirstClassLoader, Set<String> dependencies, Set<String> optionalDependencies)
@@ -77,8 +82,17 @@ public final class InstalledPluginDescriptor extends ScmModule implements Plugin
this.resources = resources;
this.condition = condition;
this.childFirstClassLoader = childFirstClassLoader;
this.dependencies = dependencies;
this.optionalDependencies = optionalDependencies;
this.dependencies = mapToNameAndVersionSet(dependencies);
this.optionalDependencies = mapToNameAndVersionSet(optionalDependencies);
}
private static Set<NameAndVersion> mapToNameAndVersionSet(Set<String> dependencies) {
if (dependencies == null){
return ImmutableSet.of();
}
return dependencies.stream()
.map(d -> new NameAndVersion(d, null))
.collect(Collectors.toSet());
}
//~--- methods --------------------------------------------------------------
@@ -173,13 +187,19 @@ public final class InstalledPluginDescriptor extends ScmModule implements Plugin
* @since 2.0.0
*/
@Override
public Set<String> getDependencies()
{
if (dependencies == null)
{
public Set<String> getDependencies() {
return mapToStringSet(getDependenciesWithVersion());
}
/**
* Returns name and versions of the plugins which are this plugin depends on.
* @return dependencies with their versions
* @since 2.4.0
*/
public Set<NameAndVersion> getDependenciesWithVersion() {
if (dependencies == null) {
dependencies = ImmutableSet.of();
}
return dependencies;
}
@@ -193,11 +213,18 @@ public final class InstalledPluginDescriptor extends ScmModule implements Plugin
*/
@Override
public Set<String> getOptionalDependencies() {
if (optionalDependencies == null)
{
return mapToStringSet(getOptionalDependenciesWithVersion());
}
/**
* Returns name and versions of the plugins which are this plugin optional depends on.
* @return optional dependencies with their versions
* @since 2.4.0
*/
public Set<NameAndVersion> getOptionalDependenciesWithVersion() {
if (optionalDependencies == null) {
optionalDependencies = ImmutableSet.of();
}
return optionalDependencies;
}
@@ -205,6 +232,12 @@ public final class InstalledPluginDescriptor extends ScmModule implements Plugin
return ImmutableSet.copyOf(Iterables.concat(getDependencies(), getOptionalDependencies()));
}
private Set<String> mapToStringSet(Set<NameAndVersion> dependencies) {
return dependencies.stream()
.map(NameAndVersion::getName)
.collect(Collectors.toSet());
}
/**
* Method description
*
@@ -263,12 +296,12 @@ public final class InstalledPluginDescriptor extends ScmModule implements Plugin
/** Field description */
@XmlElement(name = "dependency")
@XmlElementWrapper(name = "dependencies")
private Set<String> dependencies;
private Set<NameAndVersion> dependencies;
/** Field description */
@XmlElement(name = "dependency")
@XmlElementWrapper(name = "optional-dependencies")
private Set<String> optionalDependencies;
private Set<NameAndVersion> optionalDependencies;
/** Field description */
@XmlElement(name = "information")

View File

@@ -0,0 +1,97 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.plugin;
import com.google.common.base.Strings;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import sonia.scm.version.Version;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Optional;
/**
* @since 2.4.0
*/
@Getter
@EqualsAndHashCode
@XmlAccessorType(XmlAccessType.FIELD)
public class NameAndVersion {
@XmlValue
private String name;
@XmlAttribute(name = "version")
@XmlJavaTypeAdapter(VersionXmlAdapter.class)
private Version version;
NameAndVersion() {
// required for jaxb
}
public NameAndVersion(String name) {
this(name, null);
}
public NameAndVersion(String name, String version) {
this.name = name;
if (!Strings.isNullOrEmpty(version)) {
this.version = Version.parse(version);
}
}
public Optional<Version> getVersion() {
return Optional.ofNullable(version);
}
@Override
public String toString() {
return name + (version != null ? ":" + version.getParsedVersion() : "");
}
static class VersionXmlAdapter extends XmlAdapter<String, Version> {
@Override
public Version unmarshal(String v) {
if (Strings.isNullOrEmpty(v)) {
return null;
}
return Version.parse(v);
}
@Override
public String marshal(Version v) {
if (v != null) {
return v.getUnparsedVersion();
}
return null;
}
}
}

View File

@@ -0,0 +1,63 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.plugin;
import com.google.common.io.Resources;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javax.xml.bind.JAXB;
import java.net.URL;
import static org.assertj.core.api.Assertions.assertThat;
class InstalledPluginDescriptorTest {
private static InstalledPluginDescriptor descriptor;
@BeforeAll
@SuppressWarnings("UnstableApiUsage")
static void unmarshal() {
URL resource = Resources.getResource("sonia/scm/plugin/review-plugin.xml");
descriptor = JAXB.unmarshal(resource, InstalledPluginDescriptor.class);
}
@Test
void shouldUnmarshallDependencies() {
assertThat(descriptor.getDependencies()).containsOnly("scm-mail-plugin");
assertThat(descriptor.getOptionalDependencies()).containsOnly("scm-editor-plugin", "scm-landingpage-plugin");
assertThat(descriptor.getDependenciesInclusiveOptionals()).containsOnly("scm-mail-plugin", "scm-editor-plugin", "scm-landingpage-plugin");
}
@Test
void shouldUnmarshallDependenciesWithVersion() {
assertThat(descriptor.getDependenciesWithVersion()).containsOnly(new NameAndVersion("scm-mail-plugin", "2.1.0"));
assertThat(descriptor.getOptionalDependenciesWithVersion()).containsOnly(
new NameAndVersion("scm-landingpage-plugin", "1.0.0"),
new NameAndVersion("scm-editor-plugin")
);
}
}

View File

@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
MIT License
Copyright (c) 2020-present Cloudogu GmbH and Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<plugin>
<scm-version>2</scm-version>
<information>
<displayName>Review</displayName>
<author>Cloudogu GmbH</author>
<category>Workflow</category>
<name>scm-review-plugin</name>
<version>2.3.0-SNAPSHOT</version>
<description>Depict a review process with pull requests</description>
</information>
<conditions>
<min-version>2.4.0-SNAPSHOT</min-version>
</conditions>
<resources>
<script>assets/scm-review-plugin.bundle.js</script>
</resources>
<subscriber>
<class>com.cloudogu.scm.review.emailnotification.EmailNotificationHook</class>
<event>com.cloudogu.scm.review.pullrequest.service.PullRequestRejectedEvent</event>
</subscriber>
<extension-point>
<description>Each {@link Rule} class implementation defines a type of workflow rule.&lt;br&gt;
&lt;br&gt;
Rules applied to your repositories are represented by {@link AppliedRule}s&lt;br&gt;
to support multiple {@link Rule}s of the same type with distinct configuration.
</description>
<autoBind>true</autoBind>
<multi>true</multi>
<class>com.cloudogu.scm.review.workflow.Rule</class>
</extension-point>
<rest-resource>
<value>v2/pull-requests</value>
<class>com.cloudogu.scm.review.config.api.RepositoryConfigResource</class>
</rest-resource>
<event>
<class>com.cloudogu.scm.review.pullrequest.service.PullRequestEvent</class>
</event>
<extension>
<class>com.cloudogu.scm.review.ProcessChangedFilesHook</class>
</extension>
<dependencies>
<dependency version="2.1.0">scm-mail-plugin</dependency>
</dependencies>
<optional-dependencies>
<dependency>scm-editor-plugin</dependency>
<dependency version="1.0.0">scm-landingpage-plugin</dependency>
</optional-dependencies>
</plugin>