aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-api
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2021-03-03 16:55:59 +0100
committersonartech <sonartech@sonarsource.com>2021-03-08 20:07:54 +0000
commit45b11acbe0116d6781f0d4d5a4e035837e2ba54a (patch)
treebed8bb785e90f9caad0f0ccfb37773dd214291bb /server/sonar-webserver-api
parent129ca5f3534a69799f5ea95975c3f0a49fbb2804 (diff)
downloadsonarqube-45b11acbe0116d6781f0d4d5a4e035837e2ba54a.tar.gz
sonarqube-45b11acbe0116d6781f0d4d5a4e035837e2ba54a.zip
SONAR-14523 implemented splitting plugins into two
Diffstat (limited to 'server/sonar-webserver-api')
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java8
-rw-r--r--server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java70
2 files changed, 70 insertions, 8 deletions
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
index 91ec5940a75..ace04fd1a0a 100644
--- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
+++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
@@ -84,6 +84,14 @@ public class ServerPluginRepository implements PluginRepository {
return Optional.ofNullable(pluginByKey.get(key));
}
+ public Collection<PluginInfo> getPluginsInfoByType(PluginType type){
+ return pluginByKey.values()
+ .stream()
+ .filter(p -> p.getType() == type)
+ .map(ServerPlugin::getPluginInfo)
+ .collect(Collectors.toList());
+ }
+
@Override
public Plugin getPluginInstance(String key) {
ServerPlugin plugin = pluginByKey.get(key);
diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
index 18fecba6258..2eebec65185 100644
--- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
+++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
@@ -20,7 +20,10 @@
package org.sonar.server.plugins;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
+import java.util.stream.Collectors;
+
import org.junit.Assert;
import org.junit.Test;
import org.sonar.api.Plugin;
@@ -30,6 +33,7 @@ import org.sonar.server.plugins.PluginFilesAndMd5.FileAndMd5;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.server.plugins.PluginType.BUNDLED;
import static org.sonar.server.plugins.PluginType.EXTERNAL;
public class ServerPluginRepositoryTest {
@@ -37,8 +41,8 @@ public class ServerPluginRepositoryTest {
@Test
public void get_plugin_data() {
- ServerPlugin plugin1 = newPlugin("plugin1");
- ServerPlugin plugin2 = newPlugin("plugin2");
+ ServerPlugin plugin1 = newPlugin("plugin1", EXTERNAL);
+ ServerPlugin plugin2 = newPlugin("plugin2", EXTERNAL);
repository.addPlugins(Collections.singletonList(plugin1));
repository.addPlugin(plugin2);
@@ -56,8 +60,8 @@ public class ServerPluginRepositoryTest {
@Test
public void fail_getPluginInstance_if_plugin_doesnt_exist() {
- ServerPlugin plugin1 = newPlugin("plugin1");
- ServerPlugin plugin2 = newPlugin("plugin2");
+ ServerPlugin plugin1 = newPlugin("plugin1", EXTERNAL);
+ ServerPlugin plugin2 = newPlugin("plugin2", EXTERNAL);
repository.addPlugins(Arrays.asList(plugin1, plugin2));
Assert.assertThrows("asd", IllegalArgumentException.class, () -> repository.getPluginInstance("plugin3"));
@@ -65,20 +69,70 @@ public class ServerPluginRepositoryTest {
@Test
public void fail_getPluginInfo_if_plugin_doesnt_exist() {
- ServerPlugin plugin1 = newPlugin("plugin1");
- ServerPlugin plugin2 = newPlugin("plugin2");
+ ServerPlugin plugin1 = newPlugin("plugin1", EXTERNAL);
+ ServerPlugin plugin2 = newPlugin("plugin2", EXTERNAL);
repository.addPlugins(Arrays.asList(plugin1, plugin2));
Assert.assertThrows("asd", IllegalArgumentException.class, () -> repository.getPluginInfo("plugin3"));
}
+ @Test
+ public void getPluginsInfoByTypeExternal_given1ExternalPlugin_return1ExternalPlugin(){
+ //given
+ ServerPlugin externalPlugin = newPlugin("plugin1", EXTERNAL);
+ repository.addPlugin(externalPlugin);
+
+ PluginInfo expectedPluginInfo = externalPlugin.getPluginInfo();
+
+ //when
+ Collection<PluginInfo> pluginInfos = repository.getPluginsInfoByType(EXTERNAL);
+
+ //then
+ assertThat(pluginInfos).containsOnly(expectedPluginInfo);
+ }
+
+ @Test
+ public void getPluginsInfoByTypeExternal_given1ExternalAnd1BundledPlugin_return1ExternalPlugin(){
+ //given
+ ServerPlugin externalPlugin = newPlugin("plugin1", EXTERNAL);
+ ServerPlugin bundledPlugin = newPlugin("plugin2", BUNDLED);
+ repository.addPlugin(externalPlugin);
+ repository.addPlugin(bundledPlugin);
+
+ PluginInfo expectedPluginInfo = externalPlugin.getPluginInfo();
+
+ //when
+ Collection<PluginInfo> pluginInfos = repository.getPluginsInfoByType(EXTERNAL);
+
+ //then
+ assertThat(pluginInfos).containsOnly(expectedPluginInfo);
+ }
+
+ @Test
+ public void getPluginsInfoByTypeBundled_given2BundledPlugins_return2BundledPlugins(){
+ //given
+ ServerPlugin bundledPlugin = newPlugin("plugin1", BUNDLED);
+ ServerPlugin bundledPlugin2 = newPlugin("plugin2", BUNDLED);
+ repository.addPlugin(bundledPlugin);
+ repository.addPlugin(bundledPlugin2);
+
+ PluginInfo expectedPluginInfo = bundledPlugin.getPluginInfo();
+ PluginInfo expectedPluginInfo2 = bundledPlugin2.getPluginInfo();
+
+ //when
+ Collection<PluginInfo> pluginInfos = repository.getPluginsInfoByType(BUNDLED);
+
+ //then
+ assertThat(pluginInfos).containsOnly(expectedPluginInfo, expectedPluginInfo2);
+ }
+
private PluginInfo newPluginInfo(String key) {
PluginInfo pluginInfo = mock(PluginInfo.class);
when(pluginInfo.getKey()).thenReturn(key);
return pluginInfo;
}
- private ServerPlugin newPlugin(String key) {
- return new ServerPlugin(newPluginInfo(key), EXTERNAL, mock(Plugin.class), mock(FileAndMd5.class), mock(FileAndMd5.class), mock(ClassLoader.class));
+ private ServerPlugin newPlugin(String key, PluginType type) {
+ return new ServerPlugin(newPluginInfo(key), type, mock(Plugin.class), mock(FileAndMd5.class), mock(FileAndMd5.class), mock(ClassLoader.class));
}
}