aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorLéo Geoffroy <99647462+leo-geoffroy-sonarsource@users.noreply.github.com>2022-07-22 17:40:51 +0200
committersonartech <sonartech@sonarsource.com>2022-07-22 20:03:01 +0000
commit1220331cf405fb916a005284120b0ed02ea67ac2 (patch)
tree322bcb39923a31307e92117c641d719d43aa69c5 /server
parent7882b9fdb8436ae2cd0553104282cba968e02bb4 (diff)
downloadsonarqube-1220331cf405fb916a005284120b0ed02ea67ac2.tar.gz
sonarqube-1220331cf405fb916a005284120b0ed02ea67ac2.zip
SONAR-17081 - Minimal compatibility version should be compared with runtime API version
Diffstat (limited to 'server')
-rw-r--r--server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginJarLoader.java17
-rw-r--r--server/sonar-webserver-api/src/test/java/org/sonar/server/plugins/PluginJarLoaderTest.java14
2 files changed, 16 insertions, 15 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 d04845aaf78..19d14265082 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
@@ -34,11 +34,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 static java.lang.String.format;
@@ -60,17 +60,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 SonarQubeVersion sonarQubeVersion;
+ private final SonarRuntime sonarRuntime;
private final Set<String> blacklistedPluginKeys;
@Inject
- public PluginJarLoader(ServerFileSystem fs, SonarQubeVersion sonarQubeVersion) {
- this(fs, sonarQubeVersion, DEFAULT_BLACKLISTED_PLUGINS);
+ public PluginJarLoader(ServerFileSystem fs, SonarRuntime sonarRuntime) {
+ this(fs, sonarRuntime, DEFAULT_BLACKLISTED_PLUGINS);
}
- PluginJarLoader(ServerFileSystem fs, SonarQubeVersion sonarQubeVersion, Set<String> blacklistedPluginKeys) {
+ PluginJarLoader(ServerFileSystem fs, SonarRuntime sonarRuntime, Set<String> blacklistedPluginKeys) {
this.fs = fs;
- this.sonarQubeVersion = sonarQubeVersion;
+ this.sonarRuntime = sonarRuntime;
this.blacklistedPluginKeys = blacklistedPluginKeys;
}
@@ -211,8 +211,9 @@ public class PluginJarLoader {
return false;
}
- if (!info.isCompatibleWith(sonarQubeVersion.get().toString())) {
- throw MessageException.of(format("Plugin %s [%s] requires at least SonarQube %s", info.getName(), info.getKey(), info.getMinimalSqVersion()));
+ if (!info.isCompatibleWith(sonarRuntime.getApiVersion().toString())) {
+ throw MessageException.of(format("Plugin %s [%s] requires at least Sonar Plugin API version %s (current: %s)",
+ info.getName(), info.getKey(), info.getMinimalSonarPluginApiVersion(), sonarRuntime.getApiVersion()));
}
return true;
}
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 c8be970cc3d..36ce28aa56f 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;
@@ -56,12 +56,12 @@ public class PluginJarLoaderTest {
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);
+ private final SonarRuntime sonarRuntime = mock(SonarRuntime.class);
+ private final PluginJarLoader underTest = new PluginJarLoader(fs, sonarRuntime, blacklisted);
@Before
public void setUp() throws IOException {
- when(sonarQubeVersion.get()).thenReturn(org.sonar.api.utils.Version.parse("5.2"));
+ when(sonarRuntime.getApiVersion()).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"));
@@ -285,12 +285,12 @@ public class PluginJarLoaderTest {
}
@Test
- public void fail_if_plugin_does_not_support_sq_version() throws Exception {
- when(sonarQubeVersion.get()).thenReturn(org.sonar.api.utils.Version.parse("1.0"));
+ public void fail_if_plugin_does_not_support_plugin_api_version() throws Exception {
+ when(sonarRuntime.getApiVersion()).thenReturn(org.sonar.api.utils.Version.parse("1.0"));
copyTestPluginTo("test-base-plugin", fs.getInstalledExternalPluginsDir());
assertThatThrownBy(() -> underTest.loadPlugins())
- .hasMessage("Plugin Base Plugin [testbase] requires at least SonarQube 4.5.4");
+ .hasMessage("Plugin Base Plugin [testbase] requires at least Sonar Plugin API version 4.5.4 (current: 1.0)");
}
private static File copyTestPluginTo(String testPluginName, File toDir) throws IOException {