mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 10:41:06 +01:00
Fix duplicate plugins in the plugin tree after update
This commit is contained in:
@@ -31,6 +31,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -105,6 +106,25 @@ public final class ExplodedSmp
|
|||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
ExplodedSmp that = (ExplodedSmp) o;
|
||||||
|
return path.equals(that.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
PluginInformation information = plugin.getInformation();
|
||||||
|
return information.getName() + "@" + information.getVersion() + " (" + path + ")";
|
||||||
|
}
|
||||||
|
|
||||||
//~--- inner classes --------------------------------------------------------
|
//~--- inner classes --------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -190,8 +190,14 @@ public final class PluginProcessor
|
|||||||
return ImmutableSet.copyOf(wrappers);
|
return ImmutableSet.copyOf(wrappers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableSet<ExplodedSmp> concat(Set<ExplodedSmp> installedPlugins, Set<ExplodedSmp> newlyInstalledPlugins) {
|
private Set<ExplodedSmp> concat(Set<ExplodedSmp> installedPlugins, Set<ExplodedSmp> newlyInstalledPlugins) {
|
||||||
return ImmutableSet.<ExplodedSmp>builder().addAll(installedPlugins).addAll(newlyInstalledPlugins).build();
|
// We first add all newly installed plugins,
|
||||||
|
// after that we add the missing plugins, which are already installed.
|
||||||
|
// ExplodedSmp is equal by its path, so duplicates (updates) are not in the result.
|
||||||
|
return ImmutableSet.<ExplodedSmp>builder()
|
||||||
|
.addAll(newlyInstalledPlugins)
|
||||||
|
.addAll(installedPlugins)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<ExplodedSmp> installPending(Set<ExplodedSmp> installedPlugins) throws IOException {
|
private Set<ExplodedSmp> installPending(Set<ExplodedSmp> installedPlugins) throws IOException {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import com.google.common.base.Charsets;
|
|||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -38,26 +37,22 @@ import org.junit.rules.TemporaryFolder;
|
|||||||
import sonia.scm.lifecycle.classloading.ClassLoaderLifeCycle;
|
import sonia.scm.lifecycle.classloading.ClassLoaderLifeCycle;
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -100,7 +95,7 @@ public class PluginProcessorTest
|
|||||||
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", "scm-f-plugin:1.0.1");
|
"scm-f-plugin.smp", "scm-f-plugin:1.0.1");
|
||||||
|
|
||||||
private static final String PLUGIN_G = "sonia/scm/plugin/scm-g-plugin.xml";
|
private static final String PLUGIN_G = "scm-g-plugin.xml";
|
||||||
private static final String PLUGIN_H = "sonia/scm/plugin/scm-h-plugin.xml";
|
private static final String PLUGIN_H = "sonia/scm/plugin/scm-h-plugin.xml";
|
||||||
private static final String PLUGIN_I = "sonia/scm/plugin/scm-i-plugin.xml";
|
private static final String PLUGIN_I = "sonia/scm/plugin/scm-i-plugin.xml";
|
||||||
|
|
||||||
@@ -108,21 +103,34 @@ public class PluginProcessorTest
|
|||||||
|
|
||||||
@Test(expected = PluginConditionFailedException.class)
|
@Test(expected = PluginConditionFailedException.class)
|
||||||
public void testFailedPluginCondition() throws IOException {
|
public void testFailedPluginCondition() throws IOException {
|
||||||
createPlugin(PLUGIN_G);
|
createPendingPluginInstallation(PLUGIN_G);
|
||||||
collectPlugins();
|
collectPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test(expected = DependencyVersionMismatchException.class)
|
@Test(expected = DependencyVersionMismatchException.class)
|
||||||
public void testWrongVersionOfDependency() throws IOException {
|
public void testWrongVersionOfDependency() throws IOException {
|
||||||
createPlugin(PLUGIN_H);
|
createPendingPluginInstallation(PLUGIN_H);
|
||||||
createPlugin(PLUGIN_I);
|
createPendingPluginInstallation(PLUGIN_I);
|
||||||
collectPlugins();
|
collectPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotContainDuplicatesOnUpdate() throws IOException {
|
||||||
|
createInstalledPlugin("scm-mail-plugin-2-0-0.xml");
|
||||||
|
createInstalledPlugin("scm-review-plugin-2-0-0.xml");
|
||||||
|
createPendingPluginInstallation("scm-mail-plugin-2-1-0.xml");
|
||||||
|
createPendingPluginInstallation("scm-review-plugin-2-1-0.xml");
|
||||||
|
|
||||||
|
Set<String> plugins = collectPlugins().stream()
|
||||||
|
.map(p -> p.getDescriptor().getInformation().getName(true))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
assertThat(plugins, containsInAnyOrder("scm-mail-plugin:2.1.0", "scm-review-plugin:2.1.0"));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnstableApiUsage")
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
private void createPlugin(String descriptorResource) throws IOException {
|
private void createPendingPluginInstallation(String descriptorResource) throws IOException {
|
||||||
URL resource = Resources.getResource(descriptorResource);
|
URL resource = Resources.getResource("sonia/scm/plugin/" +descriptorResource);
|
||||||
InstalledPluginDescriptor descriptor = JAXB.unmarshal(resource, InstalledPluginDescriptor.class);
|
InstalledPluginDescriptor descriptor = JAXB.unmarshal(resource, InstalledPluginDescriptor.class);
|
||||||
|
|
||||||
File file = new File(pluginDirectory, descriptor.getInformation().getName() + ".smp");
|
File file = new File(pluginDirectory, descriptor.getInformation().getName() + ".smp");
|
||||||
@@ -133,6 +141,20 @@ public class PluginProcessorTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
private void createInstalledPlugin(String descriptorResource) throws IOException {
|
||||||
|
URL resource = Resources.getResource("sonia/scm/plugin/" + descriptorResource);
|
||||||
|
InstalledPluginDescriptor descriptor = JAXB.unmarshal(resource, InstalledPluginDescriptor.class);
|
||||||
|
|
||||||
|
File directory = new File(pluginDirectory, descriptor.getInformation().getName());
|
||||||
|
File scmDirectory = new File(directory, "META-INF" + File.separator + "scm");
|
||||||
|
assertTrue(scmDirectory.mkdirs());
|
||||||
|
|
||||||
|
try (OutputStream output = new FileOutputStream(new File(scmDirectory, "plugin.xml"))) {
|
||||||
|
Resources.copy(resource, output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?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>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-mail-plugin</artifactId>
|
||||||
|
<version>2.0.0</version>
|
||||||
|
<name>scm-mail-plugin</name>
|
||||||
|
<description>The awesome mail plugin</description>
|
||||||
|
</information>
|
||||||
|
|
||||||
|
<packages>
|
||||||
|
<package>sonia.scm.plugins</package>
|
||||||
|
</packages>
|
||||||
|
|
||||||
|
</plugin>
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?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>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-mail-plugin</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
<name>scm-mail-plugin</name>
|
||||||
|
<description>The awesome mail plugin</description>
|
||||||
|
</information>
|
||||||
|
|
||||||
|
<packages>
|
||||||
|
<package>sonia.scm.plugins</package>
|
||||||
|
</packages>
|
||||||
|
|
||||||
|
</plugin>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?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>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-review-plugin</artifactId>
|
||||||
|
<version>2.0.0</version>
|
||||||
|
<name>scm-review-plugin</name>
|
||||||
|
<description>The awesome review plugin</description>
|
||||||
|
</information>
|
||||||
|
|
||||||
|
<packages>
|
||||||
|
<package>sonia.scm.plugins</package>
|
||||||
|
</packages>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency version="2.0.0">scm-mail-plugin</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</plugin>
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?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>
|
||||||
|
<groupId>sonia.scm.plugins</groupId>
|
||||||
|
<artifactId>scm-review-plugin</artifactId>
|
||||||
|
<version>2.1.0</version>
|
||||||
|
<name>scm-review-plugin</name>
|
||||||
|
<description>The awesome review plugin</description>
|
||||||
|
</information>
|
||||||
|
|
||||||
|
<packages>
|
||||||
|
<package>sonia.scm.plugins</package>
|
||||||
|
</packages>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency version="2.1.0">scm-mail-plugin</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</plugin>
|
||||||
Reference in New Issue
Block a user