diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2023-12-22 10:28:22 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-12-22 20:03:01 +0000 |
commit | 6c6de5ad4fac7a44abcc6a0ae7d9cb5c7a53da51 (patch) | |
tree | 43710bdc5975d01b9336c229d0aa68a0fa66f4e2 /sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap | |
parent | 83fe248f66dcc3a909eb411f917795c054445723 (diff) | |
download | sonarqube-6c6de5ad4fac7a44abcc6a0ae7d9cb5c7a53da51.tar.gz sonarqube-6c6de5ad4fac7a44abcc6a0ae7d9cb5c7a53da51.zip |
Revert "SONAR-21195 Enhance scanner engine to download only required plugins"
This reverts commit 981e6b85954f413666e8608a4e2f46fa2e4089cc.
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap')
2 files changed, 18 insertions, 82 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java index 60e8acbdbf8..4e51f4d1b2f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java @@ -23,8 +23,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; -import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Optional; import java.util.jar.Attributes; @@ -53,36 +51,11 @@ public class ScannerPluginInstallerTest { @Test public void download_installed_plugins() throws IOException { - WsTestUtil.mockReader(wsClient, "api/plugins/installed", - new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json"))); - enqueueDownload("scmgit", "abc"); - enqueueDownload("java", "def"); - - Map<String, ScannerPlugin> result = underTest.installRequiredPlugins(); - - assertThat(result.keySet()).containsExactlyInAnyOrder("scmgit"); - ScannerPlugin gitPlugin = result.get("scmgit"); - assertThat(gitPlugin.getKey()).isEqualTo("scmgit"); - assertThat(gitPlugin.getInfo().getNonNullJarFile()).exists().isFile(); - assertThat(gitPlugin.getUpdatedAt()).isEqualTo(100L); - - Map<String, ScannerPlugin> result2 = underTest.installPluginsForLanguages(new HashSet<>(List.of("java"))); - - assertThat(result2.keySet()).containsExactlyInAnyOrder("java"); - ScannerPlugin javaPlugin = result2.get("java"); - assertThat(javaPlugin.getKey()).isEqualTo("java"); - assertThat(javaPlugin.getInfo().getNonNullJarFile()).exists().isFile(); - assertThat(javaPlugin.getUpdatedAt()).isEqualTo(200L); - } - - @Test - public void download_all_plugins() throws IOException { - WsTestUtil.mockReader(wsClient, "api/plugins/installed", - new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json"))); + WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json"))); enqueueDownload("scmgit", "abc"); enqueueDownload("java", "def"); - Map<String, ScannerPlugin> result = underTest.installAllPlugins(); + Map<String, ScannerPlugin> result = underTest.installRemotes(); assertThat(result.keySet()).containsExactlyInAnyOrder("scmgit", "java"); ScannerPlugin gitPlugin = result.get("scmgit"); @@ -100,7 +73,7 @@ public class ScannerPluginInstallerTest { public void fail_if_json_of_installed_plugins_is_not_valid() { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new StringReader("not json")); - assertThatThrownBy(() -> underTest.installRequiredPlugins()) + assertThatThrownBy(() -> underTest.installRemotes()) .isInstanceOf(IllegalStateException.class) .hasMessage("Fail to parse response of api/plugins/installed"); } @@ -114,7 +87,7 @@ public class ScannerPluginInstallerTest { enqueueDownload("java", "def"); enqueueDownload("cobol", "ghi"); - Map<String, ScannerPlugin> result = underTest.installRequiredPlugins(); + Map<String, ScannerPlugin> result = underTest.installRemotes(); assertThat(result.keySet()).containsExactlyInAnyOrder("java", "cobol"); } @@ -128,7 +101,7 @@ public class ScannerPluginInstallerTest { enqueueDownload("cobol", "ghi"); enqueueNotFoundDownload("java", "def"); - assertThatThrownBy(() -> underTest.installRequiredPlugins()) + assertThatThrownBy(() -> underTest.installRemotes()) .isInstanceOf(IllegalStateException.class) .hasMessage("Fail to download plugin [java]. Not found."); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java index 5fdb95cae22..7950dda8040 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginRepositoryTest.java @@ -21,16 +21,9 @@ package org.sonar.scanner.bootstrap; import com.google.common.collect.ImmutableMap; import java.io.File; -import java.util.Collection; import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; import org.junit.Test; import org.sonar.api.Plugin; -import org.sonar.api.config.Configuration; import org.sonar.core.platform.ExplodedPlugin; import org.sonar.core.platform.PluginClassLoader; import org.sonar.core.platform.PluginInfo; @@ -39,12 +32,9 @@ import org.sonar.core.plugin.PluginType; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.anyMap; -import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -53,58 +43,31 @@ public class ScannerPluginRepositoryTest { PluginInstaller installer = mock(PluginInstaller.class); PluginClassLoader loader = mock(PluginClassLoader.class); PluginJarExploder exploder = new FakePluginJarExploder(); - Configuration properties = mock(Configuration.class); - ScannerPluginRepository underTest = new ScannerPluginRepository(installer, exploder, loader, properties); + ScannerPluginRepository underTest = new ScannerPluginRepository(installer, exploder, loader); @Test public void install_and_load_plugins() { - PluginInfo squidInfo = new PluginInfo("squid"); - PluginInfo javaInfo = new PluginInfo("java"); - Map<String, ScannerPlugin> globalPlugins = Map.of("squid", new ScannerPlugin("squid", 1L, PluginType.BUNDLED, squidInfo)); - Map<String, ScannerPlugin> languagePlugins = Map.of("java", new ScannerPlugin("java", 1L, PluginType.EXTERNAL, javaInfo)); - Plugin squidInstance = mock(Plugin.class); - Plugin javaInstance = mock(Plugin.class); - when(loader.load(anyMap())) - .thenReturn(ImmutableMap.of("squid", squidInstance)) - .thenReturn(ImmutableMap.of("java", javaInstance)); - - when(installer.installRequiredPlugins()).thenReturn(globalPlugins); - when(installer.installPluginsForLanguages(anySet())).thenReturn(languagePlugins); + PluginInfo info = new PluginInfo("java"); + ImmutableMap<String, ScannerPlugin> plugins = ImmutableMap.of("java", new ScannerPlugin("java", 1L, PluginType.EXTERNAL, info)); + Plugin instance = mock(Plugin.class); + when(loader.load(anyMap())).thenReturn(ImmutableMap.of("java", instance)); + when(installer.installRemotes()).thenReturn(plugins); underTest.start(); - assertThat(underTest.getPluginInfos()).containsOnly(squidInfo); - assertThat(underTest.getPluginsByKey()).isEqualTo(globalPlugins); - assertThat(underTest.getPluginInfo("squid")).isSameAs(squidInfo); - assertThat(underTest.getPluginInstance("squid")).isSameAs(squidInstance); - - Collection<PluginInfo> result = underTest.installPluginsForLanguages(new HashSet<>(List.of("java"))); - - assertThat(result).containsOnly(javaInfo); - assertThat(underTest.getPluginInfos()).containsExactlyInAnyOrder(squidInfo, javaInfo); - assertThat(underTest.getExternalPluginsInfos()).containsExactlyInAnyOrder(javaInfo); - assertThat(underTest.getPluginsByKey().values()).containsExactlyInAnyOrder(globalPlugins.get("squid"), languagePlugins.get("java")); + assertThat(underTest.getPluginInfos()).containsOnly(info); + assertThat(underTest.getPluginsByKey()).isEqualTo(plugins); + assertThat(underTest.getPluginInfo("java")).isSameAs(info); + assertThat(underTest.getPluginInstance("java")).isSameAs(instance); + assertThat(underTest.getPluginInstances()).containsOnly(instance); + assertThat(underTest.getBundledPluginsInfos()).isEmpty(); + assertThat(underTest.getExternalPluginsInfos()).isEqualTo(underTest.getPluginInfos()); underTest.stop(); verify(loader).unload(anyCollection()); } @Test - public void should_install_all_plugins_when_loadall_flag_is_set() { - when(properties.getBoolean("sonar.plugins.loadAll")).thenReturn(Optional.of(true)); - - underTest.start(); - - verify(installer).installAllPlugins(); - verify(installer, never()).installRequiredPlugins(); - - Collection<PluginInfo> result = underTest.installPluginsForLanguages(Set.of("java")); - - assertThat(result).isEmpty(); - verify(installer, never()).installPluginsForLanguages(any()); - } - - @Test public void fail_if_requesting_missing_plugin() { underTest.start(); |