diff options
author | Jacek <jacek.poreda@sonarsource.com> | 2022-05-30 18:50:42 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-05-31 20:02:50 +0000 |
commit | 9097b10693f9c4fe2c7bde4bccdbca151ebfa452 (patch) | |
tree | 10eb71dfd890e5725f4f085386812eeb65c53197 /server/sonar-webserver-api | |
parent | cdeca9bf6ccd0cb1a3b2d397efa8ace1ef4789c2 (diff) | |
download | sonarqube-9097b10693f9c4fe2c7bde4bccdbca151ebfa452.tar.gz sonarqube-9097b10693f9c4fe2c7bde4bccdbca151ebfa452.zip |
SONAR-16232 Use plugin api version for SonarRuntime impl
- introduce internal SonarQubeVersion
Diffstat (limited to 'server/sonar-webserver-api')
4 files changed, 22 insertions, 22 deletions
diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java index a39998be132..a7402600556 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java @@ -36,11 +36,11 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.inject.Inject; import org.apache.commons.io.FileUtils; -import org.sonar.api.SonarRuntime; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.server.platform.ServerFileSystem; import org.sonar.updatecenter.common.Version; @@ -63,17 +63,17 @@ public class PluginJarLoader { private static final String LOAD_ERROR_GENERIC_MESSAGE = "Startup failed: Plugins can't be loaded. See web logs for more information"; private final ServerFileSystem fs; - private final SonarRuntime runtime; + private final SonarQubeVersion sonarQubeVersion; private final Set<String> blacklistedPluginKeys; @Inject - public PluginJarLoader(ServerFileSystem fs, SonarRuntime runtime) { - this(fs, runtime, DEFAULT_BLACKLISTED_PLUGINS); + public PluginJarLoader(ServerFileSystem fs, SonarQubeVersion sonarQubeVersion) { + this(fs, sonarQubeVersion, DEFAULT_BLACKLISTED_PLUGINS); } - PluginJarLoader(ServerFileSystem fs, SonarRuntime runtime, Set<String> blacklistedPluginKeys) { + PluginJarLoader(ServerFileSystem fs, SonarQubeVersion sonarQubeVersion, Set<String> blacklistedPluginKeys) { this.fs = fs; - this.runtime = runtime; + this.sonarQubeVersion = sonarQubeVersion; this.blacklistedPluginKeys = blacklistedPluginKeys; } @@ -261,7 +261,7 @@ public class PluginJarLoader { return false; } - if (!info.isCompatibleWith(runtime.getApiVersion().toString())) { + if (!info.isCompatibleWith(sonarQubeVersion.get().toString())) { throw MessageException.of(format("Plugin %s [%s] requires at least SonarQube %s", info.getName(), info.getKey(), info.getMinimalSqVersion())); } return true; diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterMatrixFactory.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterMatrixFactory.java index d9c6262e58b..a7c40bc1659 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterMatrixFactory.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/UpdateCenterMatrixFactory.java @@ -20,7 +20,7 @@ package org.sonar.server.plugins; import java.util.Optional; -import org.sonar.api.SonarRuntime; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.updatecenter.common.UpdateCenter; import org.sonar.updatecenter.common.Version; @@ -30,20 +30,20 @@ import org.sonar.updatecenter.common.Version; public class UpdateCenterMatrixFactory { private final UpdateCenterClient centerClient; - private final SonarRuntime sonarRuntime; + private final SonarQubeVersion sonarQubeVersion; private final InstalledPluginReferentialFactory installedPluginReferentialFactory; - public UpdateCenterMatrixFactory(UpdateCenterClient centerClient, SonarRuntime runtime, + public UpdateCenterMatrixFactory(UpdateCenterClient centerClient, SonarQubeVersion sonarQubeVersion, InstalledPluginReferentialFactory installedPluginReferentialFactory) { this.centerClient = centerClient; - this.sonarRuntime = runtime; + this.sonarQubeVersion = sonarQubeVersion; this.installedPluginReferentialFactory = installedPluginReferentialFactory; } public Optional<UpdateCenter> getUpdateCenter(boolean refreshUpdateCenter) { Optional<UpdateCenter> updateCenter = centerClient.getUpdateCenter(refreshUpdateCenter); if (updateCenter.isPresent()) { - org.sonar.api.utils.Version fullVersion = sonarRuntime.getApiVersion(); + org.sonar.api.utils.Version fullVersion = sonarQubeVersion.get(); org.sonar.api.utils.Version semanticVersion = org.sonar.api.utils.Version.create(fullVersion.major(), fullVersion.minor(), fullVersion.patch()); return Optional.of(updateCenter.get().setInstalledSonarVersion(Version.create(semanticVersion.toString())).registerInstalledPlugins( diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java index a5105eefd6b..c8be970cc3d 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java @@ -35,10 +35,10 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.SonarRuntime; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.LogTester; import org.sonar.core.platform.PluginInfo; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.server.platform.ServerFileSystem; import org.sonar.updatecenter.common.PluginManifest; @@ -54,14 +54,14 @@ public class PluginJarLoaderTest { @Rule public LogTester logs = new LogTester(); - private ServerFileSystem fs = mock(ServerFileSystem.class); - private Set<String> blacklisted = new HashSet<>(); - private SonarRuntime runtime = mock(SonarRuntime.class); - private PluginJarLoader underTest = new PluginJarLoader(fs, runtime, blacklisted); + private final ServerFileSystem fs = mock(ServerFileSystem.class); + private final Set<String> blacklisted = new HashSet<>(); + private final SonarQubeVersion sonarQubeVersion = mock(SonarQubeVersion.class); + private final PluginJarLoader underTest = new PluginJarLoader(fs, sonarQubeVersion, blacklisted); @Before public void setUp() throws IOException { - when(runtime.getApiVersion()).thenReturn(org.sonar.api.utils.Version.parse("5.2")); + when(sonarQubeVersion.get()).thenReturn(org.sonar.api.utils.Version.parse("5.2")); when(fs.getDeployedPluginsDir()).thenReturn(temp.newFolder("deployed")); when(fs.getDownloadedPluginsDir()).thenReturn(temp.newFolder("downloaded")); when(fs.getHomeDir()).thenReturn(temp.newFolder("home")); @@ -270,7 +270,7 @@ public class PluginJarLoaderTest { public void fail_when_report_is_installed() throws Exception { copyTestPluginTo("fake-report-plugin", fs.getInstalledExternalPluginsDir()); - assertThatThrownBy(() -> underTest.loadPlugins()) + assertThatThrownBy(() -> underTest.loadPlugins()) .isInstanceOf(MessageException.class) .hasMessage("The following plugin is no longer compatible with this version of SonarQube: 'report'"); } @@ -286,7 +286,7 @@ public class PluginJarLoaderTest { @Test public void fail_if_plugin_does_not_support_sq_version() throws Exception { - when(runtime.getApiVersion()).thenReturn(org.sonar.api.utils.Version.parse("1.0")); + when(sonarQubeVersion.get()).thenReturn(org.sonar.api.utils.Version.parse("1.0")); copyTestPluginTo("test-base-plugin", fs.getInstalledExternalPluginsDir()); assertThatThrownBy(() -> underTest.loadPlugins()) diff --git a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/UpdateCenterMatrixFactoryTest.java b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/UpdateCenterMatrixFactoryTest.java index 56865125f6c..a3992ff03d7 100644 --- a/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/UpdateCenterMatrixFactoryTest.java +++ b/server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/UpdateCenterMatrixFactoryTest.java @@ -21,7 +21,7 @@ package org.sonar.server.plugins; import java.util.Optional; import org.junit.Test; -import org.sonar.api.SonarRuntime; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.updatecenter.common.UpdateCenter; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +38,7 @@ public class UpdateCenterMatrixFactoryTest { UpdateCenterClient updateCenterClient = mock(UpdateCenterClient.class); when(updateCenterClient.getUpdateCenter(anyBoolean())).thenReturn(Optional.empty()); - underTest = new UpdateCenterMatrixFactory(updateCenterClient, mock(SonarRuntime.class), mock(InstalledPluginReferentialFactory.class)); + underTest = new UpdateCenterMatrixFactory(updateCenterClient, mock(SonarQubeVersion.class), mock(InstalledPluginReferentialFactory.class)); Optional<UpdateCenter> updateCenter = underTest.getUpdateCenter(false); |