diff options
27 files changed, 210 insertions, 112 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/WriteMetadataStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/WriteMetadataStep.java index 7c20196cc43..f7516b7de5f 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/WriteMetadataStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectexport/steps/WriteMetadataStep.java @@ -20,22 +20,22 @@ package org.sonar.ce.task.projectexport.steps; import com.sonarsource.governance.projectdump.protobuf.ProjectDump; -import org.sonar.api.SonarRuntime; import org.sonar.api.utils.System2; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.core.platform.SonarQubeVersion; public class WriteMetadataStep implements ComputationStep { private final System2 system2; private final DumpWriter dumpWriter; private final ProjectHolder projectHolder; - private final SonarRuntime sonarRuntime; + private final SonarQubeVersion sonarQubeVersion; - public WriteMetadataStep(System2 system2, DumpWriter dumpWriter, ProjectHolder projectHolder, SonarRuntime sonarRuntime) { + public WriteMetadataStep(System2 system2, DumpWriter dumpWriter, ProjectHolder projectHolder, SonarQubeVersion sonarQubeVersion) { this.system2 = system2; this.dumpWriter = dumpWriter; this.projectHolder = projectHolder; - this.sonarRuntime = sonarRuntime; + this.sonarQubeVersion = sonarQubeVersion; } @Override @@ -43,7 +43,7 @@ public class WriteMetadataStep implements ComputationStep { dumpWriter.write(ProjectDump.Metadata.newBuilder() .setProjectKey(projectHolder.projectDto().getKey()) .setProjectUuid(projectHolder.projectDto().getUuid()) - .setSonarqubeVersion(sonarRuntime.getApiVersion().toString()) + .setSonarqubeVersion(sonarQubeVersion.get().toString()) .setDumpDate(system2.now()) .build()); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/WriteMetadataStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/WriteMetadataStepTest.java index 20f09ee3c08..557ce07137f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/WriteMetadataStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/steps/WriteMetadataStepTest.java @@ -21,12 +21,10 @@ package org.sonar.ce.task.projectexport.steps; import com.sonarsource.governance.projectdump.protobuf.ProjectDump; import org.junit.Test; -import org.sonar.api.SonarEdition; -import org.sonar.api.SonarQubeSide; -import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.System2; import org.sonar.api.utils.Version; import org.sonar.ce.task.step.TestComputationStepContext; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.db.project.ProjectDto; import static org.assertj.core.api.Assertions.assertThat; @@ -44,7 +42,7 @@ public class WriteMetadataStepTest { MutableProjectHolderImpl projectHolder = new MutableProjectHolderImpl(); Version sqVersion = Version.create(6, 0); WriteMetadataStep underTest = new WriteMetadataStep(system2, dumpWriter, projectHolder, - SonarRuntimeImpl.forSonarQube(sqVersion, SonarQubeSide.SERVER, SonarEdition.COMMUNITY)); + new SonarQubeVersion(sqVersion)); @Test public void write_metadata() { diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java index 8193be28b65..3a30af5138a 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java @@ -25,7 +25,6 @@ import java.util.List; import javax.annotation.CheckForNull; import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; -import org.sonar.api.SonarQubeVersion; import org.sonar.api.config.EmailSettings; import org.sonar.api.internal.MetadataLoader; import org.sonar.api.internal.SonarRuntimeImpl; @@ -270,13 +269,15 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer { } private static void populateLevel1(Container container, Props props, ComputeEngineStatus computeEngineStatus) { - Version apiVersion = MetadataLoader.loadVersion(System2.INSTANCE); + Version apiVersion = MetadataLoader.loadApiVersion(System2.INSTANCE); + Version sqVersion = MetadataLoader.loadSQVersion(System2.INSTANCE); SonarEdition edition = MetadataLoader.loadEdition(System2.INSTANCE); container.add( props.rawProperties(), ThreadLocalSettings.class, new ConfigurationProvider(), - new SonarQubeVersion(apiVersion), + new org.sonar.api.SonarQubeVersion(sqVersion), + new org.sonar.core.platform.SonarQubeVersion(sqVersion), SonarRuntimeImpl.forSonarQube(apiVersion, SonarQubeSide.COMPUTE_ENGINE, edition), CeProcessLogging.class, UuidFactoryImpl.INSTANCE, diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java index dc515bfcd4f..9cee679c359 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java @@ -27,15 +27,13 @@ import javax.sql.DataSource; import org.apache.commons.io.output.NullWriter; import org.apache.ibatis.io.Resources; import org.apache.ibatis.jdbc.ScriptRunner; -import org.sonar.api.SonarEdition; -import org.sonar.api.SonarQubeSide; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.config.internal.Settings; -import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.System2; import org.sonar.api.utils.Version; import org.sonar.api.utils.log.Loggers; import org.sonar.core.platform.Container; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.core.platform.SpringComponentContainer; import org.sonar.core.util.UuidFactoryFast; import org.sonar.core.util.logs.Profiler; @@ -147,7 +145,7 @@ public class SQDatabase extends DefaultDatabase { migrationConfigurationModule.configure(container); // dependencies required by DB migrations - container.add(SonarRuntimeImpl.forSonarQube(Version.create(8, 0), SonarQubeSide.SERVER, SonarEdition.COMMUNITY)); + container.add(new SonarQubeVersion(Version.create(8, 0))); container.add(UuidFactoryFast.getInstance()); container.add(System2.INSTANCE); container.add(MapSettings.class); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchema.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchema.java index 74cf229a2f7..762a1c14213 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchema.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchema.java @@ -23,8 +23,8 @@ import java.sql.SQLException; import java.util.Arrays; import java.util.Date; import java.util.List; -import org.sonar.api.SonarRuntime; import org.sonar.api.utils.System2; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.core.util.UuidFactory; import org.sonar.db.Database; import org.sonar.server.platform.db.migration.step.DataChange; @@ -46,13 +46,13 @@ public class PopulateInitialSchema extends DataChange { private final System2 system2; private final UuidFactory uuidFactory; - private final SonarRuntime sonarRuntime; + private final SonarQubeVersion sonarQubeVersion; - public PopulateInitialSchema(Database db, System2 system2, UuidFactory uuidFactory, SonarRuntime sonarRuntime) { + public PopulateInitialSchema(Database db, System2 system2, UuidFactory uuidFactory, SonarQubeVersion sonarQubeVersion) { super(db); this.system2 = system2; this.uuidFactory = uuidFactory; - this.sonarRuntime = sonarRuntime; + this.sonarQubeVersion = sonarQubeVersion; } @Override @@ -108,7 +108,7 @@ public class PopulateInitialSchema extends DataChange { upsert .setString(1, "installation.version") .setBoolean(2, false) - .setString(3, sonarRuntime.getApiVersion().toString()) + .setString(3, sonarQubeVersion.get().toString()) .setLong(4, now) .addBatch(); upsert diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java index 81a8ff02d38..ad8bc02f549 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v00/PopulateInitialSchemaTest.java @@ -28,9 +28,9 @@ import java.util.stream.Stream; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.SonarRuntime; import org.sonar.api.utils.System2; import org.sonar.api.utils.Version; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.core.util.UuidFactory; import org.sonar.core.util.UuidFactoryFast; import org.sonar.core.util.stream.MoreCollectors; @@ -48,16 +48,16 @@ public class PopulateInitialSchemaTest { private final Version version = Version.create(1 + random.nextInt(10), 1 + random.nextInt(10), random.nextInt(10)); private final UuidFactory uuidFactory = UuidFactoryFast.getInstance(); private final System2 system2 = mock(System2.class); - private final SonarRuntime sonarRuntime = mock(SonarRuntime.class); + private final SonarQubeVersion sonarQubeVersion = mock(SonarQubeVersion.class); @Rule public final CoreDbTester db = CoreDbTester.createForSchema(PopulateInitialSchemaTest.class, "v89.sql"); - private final PopulateInitialSchema underTest = new PopulateInitialSchema(db.database(), system2, uuidFactory, sonarRuntime); + private final PopulateInitialSchema underTest = new PopulateInitialSchema(db.database(), system2, uuidFactory, sonarQubeVersion); @Before public void setUp() { - when(sonarRuntime.getApiVersion()).thenReturn(version); + when(sonarQubeVersion.get()).thenReturn(version); } @Test diff --git a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java index c28f501eac3..a613120d694 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/command/CommandFactoryImpl.java @@ -71,7 +71,7 @@ public class CommandFactoryImpl implements CommandFactory { SOCKS_PROXY_HOST.getKey(), SOCKS_PROXY_PORT.getKey()}; - private static final Version SQ_VERSION = MetadataLoader.loadVersion(org.sonar.api.utils.System2.INSTANCE); + private static final Version SQ_VERSION = MetadataLoader.loadSQVersion(org.sonar.api.utils.System2.INSTANCE); private final Props props; private final File tempDir; private final System2 system2; diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java index df10f62ee95..3b493e0ae60 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/platform/ServerImpl.java @@ -22,11 +22,11 @@ package org.sonar.server.platform; import java.util.Date; import javax.annotation.CheckForNull; import org.sonar.api.CoreProperties; -import org.sonar.api.SonarRuntime; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.config.Configuration; import org.sonar.api.platform.Server; import org.sonar.api.server.ServerSide; +import org.sonar.core.platform.SonarQubeVersion; @ComputeEngineSide @ServerSide @@ -34,13 +34,13 @@ public class ServerImpl extends Server { private final Configuration config; private final StartupMetadata state; private final UrlSettings urlSettings; - private final SonarRuntime runtime; + private final SonarQubeVersion version; - public ServerImpl(Configuration config, StartupMetadata state, UrlSettings urlSettings, SonarRuntime runtime) { + public ServerImpl(Configuration config, StartupMetadata state, UrlSettings urlSettings, SonarQubeVersion version) { this.config = config; this.state = state; this.urlSettings = urlSettings; - this.runtime = runtime; + this.version = version; } /** @@ -59,7 +59,7 @@ public class ServerImpl extends Server { @Override public String getVersion() { - return runtime.getApiVersion().toString(); + return version.get().toString(); } @Override diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/util/OkHttpClientProvider.java b/server/sonar-server-common/src/main/java/org/sonar/server/util/OkHttpClientProvider.java index 3a50f78a28e..487e555d677 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/util/OkHttpClientProvider.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/util/OkHttpClientProvider.java @@ -20,10 +20,10 @@ package org.sonar.server.util; import okhttp3.OkHttpClient; -import org.sonar.api.SonarRuntime; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.config.Configuration; import org.sonar.api.server.ServerSide; +import org.sonar.core.platform.SonarQubeVersion; import org.sonarqube.ws.client.OkHttpClientBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; @@ -54,7 +54,7 @@ public class OkHttpClientProvider { */ @Primary @Bean("OkHttpClient") - public OkHttpClient provide(Configuration config, SonarRuntime runtime) { + public OkHttpClient provide(Configuration config, SonarQubeVersion version) { OkHttpClientBuilder builder = new OkHttpClientBuilder(); builder.setConnectTimeoutMs(DEFAULT_CONNECT_TIMEOUT_IN_MS); builder.setReadTimeoutMs(DEFAULT_READ_TIMEOUT_IN_MS); @@ -62,7 +62,7 @@ public class OkHttpClientProvider { // configured by bootstrap process. builder.setProxyLogin(config.get(HTTP_PROXY_USER.getKey()).orElse(null)); builder.setProxyPassword(config.get(HTTP_PROXY_PASSWORD.getKey()).orElse(null)); - builder.setUserAgent(format("SonarQube/%s", runtime.getApiVersion().toString())); + builder.setUserAgent(format("SonarQube/%s", version)); return builder.build(); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java index 6c1650191d2..a13376863e5 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/platform/ServerImplTest.java @@ -21,20 +21,20 @@ package org.sonar.server.platform; import org.junit.Test; import org.sonar.api.CoreProperties; -import org.sonar.api.SonarRuntime; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.Version; +import org.sonar.core.platform.SonarQubeVersion; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class ServerImplTest { - private MapSettings settings = new MapSettings(); - private StartupMetadata state = mock(StartupMetadata.class); - private UrlSettings urlSettings = mock(UrlSettings.class); - private SonarRuntime runtime = mock(SonarRuntime.class); - private ServerImpl underTest = new ServerImpl(settings.asConfig(), state, urlSettings, runtime); + private final MapSettings settings = new MapSettings(); + private final StartupMetadata state = mock(StartupMetadata.class); + private final UrlSettings urlSettings = mock(UrlSettings.class); + private final SonarQubeVersion sonarQubeVersion = mock(SonarQubeVersion.class); + private final ServerImpl underTest = new ServerImpl(settings.asConfig(), state, urlSettings, sonarQubeVersion); @Test public void test_url_information() { @@ -66,7 +66,7 @@ public class ServerImplTest { @Test public void test_getVersion() { Version version = Version.create(6, 1); - when(runtime.getApiVersion()).thenReturn(version); + when(sonarQubeVersion.get()).thenReturn(version); assertThat(underTest.getVersion()).isEqualTo(version.toString()); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java index 01879d1053a..98fffedd18c 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/util/OkHttpClientProviderTest.java @@ -30,19 +30,16 @@ import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.SonarEdition; -import org.sonar.api.SonarQubeSide; -import org.sonar.api.SonarRuntime; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; +import org.sonar.core.platform.SonarQubeVersion; import static org.assertj.core.api.Assertions.assertThat; public class OkHttpClientProviderTest { private final MapSettings settings = new MapSettings(); - private final SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.2"), SonarQubeSide.SERVER, SonarEdition.COMMUNITY); + private final SonarQubeVersion sonarQubeVersion = new SonarQubeVersion(Version.parse("6.2")); private final OkHttpClientProvider underTest = new OkHttpClientProvider(); @Rule @@ -50,7 +47,7 @@ public class OkHttpClientProviderTest { @Test public void get_returns_a_OkHttpClient_with_default_configuration() throws Exception { - OkHttpClient client = underTest.provide(settings.asConfig(), runtime); + OkHttpClient client = underTest.provide(settings.asConfig(), sonarQubeVersion); assertThat(client.connectTimeoutMillis()).isEqualTo(10_000); assertThat(client.readTimeoutMillis()).isEqualTo(10_000); @@ -66,7 +63,7 @@ public class OkHttpClientProviderTest { settings.setProperty("http.proxyUser", "the-login"); settings.setProperty("http.proxyPassword", "the-password"); - OkHttpClient client = underTest.provide(settings.asConfig(), runtime); + OkHttpClient client = underTest.provide(settings.asConfig(), sonarQubeVersion); Response response = new Response.Builder().protocol(Protocol.HTTP_1_1).request(new Request.Builder().url("http://foo").build()).code(407) .message("").build(); Request request = client.proxyAuthenticator().authenticate(null, response); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookCallerImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookCallerImplTest.java index 4aa96fba64a..a71d371cfc6 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookCallerImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookCallerImplTest.java @@ -33,15 +33,12 @@ import org.junit.rules.DisableOnDebug; import org.junit.rules.TestRule; import org.junit.rules.Timeout; import org.mockito.Mockito; -import org.sonar.api.SonarEdition; -import org.sonar.api.SonarQubeSide; -import org.sonar.api.SonarRuntime; import org.sonar.api.config.Configuration; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.impl.utils.TestSystem2; -import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.System2; import org.sonar.api.utils.Version; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.server.util.OkHttpClientProvider; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; @@ -284,10 +281,10 @@ public class WebhookCallerImplTest { } private WebhookCaller newSender(boolean validateWebhook) { - SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.2"), SonarQubeSide.SERVER, SonarEdition.COMMUNITY); + SonarQubeVersion version = new SonarQubeVersion(Version.parse("6.2")); when(configuration.getBoolean(SONAR_VALIDATE_WEBHOOKS_PROPERTY)) .thenReturn(Optional.of(validateWebhook)); WebhookCustomDns webhookCustomDns = new WebhookCustomDns(configuration, networkInterfaceProvider); - return new WebhookCallerImpl(system, new OkHttpClientProvider().provide(new MapSettings().asConfig(), runtime), webhookCustomDns); + return new WebhookCallerImpl(system, new OkHttpClientProvider().provide(new MapSettings().asConfig(), version), webhookCustomDns); } } 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); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/LogServerVersion.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/LogServerVersion.java index c9228750aab..abf95fbb6f9 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/LogServerVersion.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/LogServerVersion.java @@ -23,27 +23,27 @@ import com.google.common.base.Joiner; import java.io.IOException; import java.io.InputStream; import java.util.Properties; -import org.sonar.api.SonarRuntime; import org.sonar.api.Startable; import org.sonar.api.server.ServerSide; import org.sonar.api.utils.Version; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; +import org.sonar.core.platform.SonarQubeVersion; @ServerSide public class LogServerVersion implements Startable { private static final Logger LOG = Loggers.get(LogServerVersion.class); - private final SonarRuntime runtime; + private final SonarQubeVersion sonarQubeVersion; - public LogServerVersion(SonarRuntime runtime) { - this.runtime = runtime; + public LogServerVersion(SonarQubeVersion sonarQubeVersion) { + this.sonarQubeVersion = sonarQubeVersion; } @Override public void start() { String scmRevision = read("/build.properties").getProperty("Implementation-Build"); - Version version = runtime.getApiVersion(); + Version version = sonarQubeVersion.get(); LOG.info("SonarQube {}", Joiner.on(" / ").skipNulls().join("Server", version, scmRevision)); } diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index f3acfaccdcb..89ffe5944ec 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -23,7 +23,6 @@ import java.time.Clock; import java.util.Properties; import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; -import org.sonar.api.SonarQubeVersion; import org.sonar.api.internal.MetadataLoader; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.System2; @@ -88,11 +87,13 @@ public class PlatformLevel1 extends PlatformLevel { public void configureLevel() { add(platform, properties); addExtraRootComponents(); - Version apiVersion = MetadataLoader.loadVersion(System2.INSTANCE); + Version apiVersion = MetadataLoader.loadApiVersion(System2.INSTANCE); + Version sqVersion = MetadataLoader.loadSQVersion(System2.INSTANCE); SonarEdition edition = MetadataLoader.loadEdition(System2.INSTANCE); add( - new SonarQubeVersion(apiVersion), + new org.sonar.api.SonarQubeVersion(sqVersion), + new org.sonar.core.platform.SonarQubeVersion(sqVersion), SonarRuntimeImpl.forSonarQube(apiVersion, SonarQubeSide.SERVER, edition), ThreadLocalSettings.class, ConfigurationProvider.class, diff --git a/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersion.java b/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersion.java new file mode 100644 index 00000000000..322fcc372ff --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersion.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.platform; + +import javax.annotation.concurrent.Immutable; +import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.api.scanner.ScannerSide; +import org.sonar.api.server.ServerSide; +import org.sonar.api.utils.Version; + +import static java.util.Objects.requireNonNull; + +@ScannerSide +@ServerSide +@ComputeEngineSide +@Immutable +public class SonarQubeVersion { + + private final Version version; + + public SonarQubeVersion(Version version) { + requireNonNull(version); + this.version = version; + } + + public Version get() { + return this.version; + } + + public boolean isGreaterThanOrEqual(Version than) { + return this.version.isGreaterThanOrEqual(than); + } + + @Override + public String toString() { + return version.toString(); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionTest.java b/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionTest.java new file mode 100644 index 00000000000..5a457f05034 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionTest.java @@ -0,0 +1,39 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.platform; + +import org.junit.Test; +import org.sonar.api.utils.Version; + +import static org.assertj.core.api.Assertions.assertThat; + +public class SonarQubeVersionTest { + + @Test + public void verify_methods() { + var version = Version.create(9, 5); + SonarQubeVersion underTest = new SonarQubeVersion(version); + assertThat(underTest).extracting(SonarQubeVersion::toString, SonarQubeVersion::get) + .containsExactly("9.5", version); + + var otherVersion = Version.create(8, 5); + assertThat(underTest.isGreaterThanOrEqual(otherVersion)).isTrue(); + } +} diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java index dc5acf17136..98b48f12382 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java @@ -125,7 +125,7 @@ public class SensorContextTester implements SensorContext { this.sensorStorage = new InMemorySensorStorage(); this.project = new DefaultInputProject(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile())); this.module = new DefaultInputModule(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile())); - this.runtime = SonarRuntimeImpl.forSonarQube(MetadataLoader.loadVersion(System2.INSTANCE), SonarQubeSide.SCANNER, MetadataLoader.loadEdition(System2.INSTANCE)); + this.runtime = SonarRuntimeImpl.forSonarQube(MetadataLoader.loadApiVersion(System2.INSTANCE), SonarQubeSide.SCANNER, MetadataLoader.loadEdition(System2.INSTANCE)); } public static SensorContextTester create(File moduleBaseDir) { diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java index 33dae76c3f8..77fe9cc89b5 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/MetadataLoader.java @@ -38,20 +38,28 @@ import static org.apache.commons.lang.StringUtils.trimToEmpty; public class MetadataLoader { private static final String SQ_VERSION_FILE_PATH = "/sq-version.txt"; + private static final String SONAR_API_VERSION_FILE_PATH = "/sonar-api-version.txt"; private static final String EDITION_FILE_PATH = "/sonar-edition.txt"; private MetadataLoader() { // only static methods } - public static Version loadVersion(System2 system) { - URL url = system.getResource(SQ_VERSION_FILE_PATH); + public static Version loadApiVersion(System2 system) { + return getVersion(system, SONAR_API_VERSION_FILE_PATH); + } + public static Version loadSQVersion(System2 system) { + return getVersion(system, SQ_VERSION_FILE_PATH); + } + + private static Version getVersion(System2 system, String versionFilePath) { + URL url = system.getResource(versionFilePath); try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8.name())) { String versionInFile = scanner.nextLine(); return Version.parse(versionInFile); } catch (IOException e) { - throw new IllegalStateException("Can not load " + SQ_VERSION_FILE_PATH + " from classpath ", e); + throw new IllegalStateException("Can not load " + versionFilePath + " from classpath ", e); } } diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/SonarRuntimeImpl.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/SonarRuntimeImpl.java index 0b1a9b51225..051b567bc54 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/SonarRuntimeImpl.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/internal/SonarRuntimeImpl.java @@ -36,24 +36,24 @@ import static org.sonar.api.utils.Preconditions.checkArgument; @Immutable public class SonarRuntimeImpl implements SonarRuntime { - private final Version version; + private final Version apiVersion; private final SonarProduct product; private final SonarQubeSide sonarQubeSide; private final SonarEdition edition; - private SonarRuntimeImpl(Version version, SonarProduct product, @Nullable SonarQubeSide sonarQubeSide, @Nullable SonarEdition edition) { + private SonarRuntimeImpl(Version apiVersion, SonarProduct product, @Nullable SonarQubeSide sonarQubeSide, @Nullable SonarEdition edition) { this.edition = edition; requireNonNull(product); checkArgument((product == SonarProduct.SONARQUBE) == (sonarQubeSide != null), "sonarQubeSide should be provided only for SonarQube product"); checkArgument((product == SonarProduct.SONARQUBE) == (edition != null), "edition should be provided only for SonarQube product"); - this.version = requireNonNull(version); + this.apiVersion = requireNonNull(apiVersion); this.product = product; this.sonarQubeSide = sonarQubeSide; } @Override public Version getApiVersion() { - return version; + return apiVersion; } @Override diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java index e7f1e23021d..fc340b90d87 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/internal/MetadataLoaderTest.java @@ -33,11 +33,18 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class MetadataLoaderTest { - private System2 system = mock(System2.class); + private final System2 system = mock(System2.class); @Test - public void load_version_from_file_in_classpath() { - Version version = MetadataLoader.loadVersion(System2.INSTANCE); + public void load_api_version_from_file_in_classpath() { + Version version = MetadataLoader.loadApiVersion(System2.INSTANCE); + assertThat(version).isNotNull(); + assertThat(version.major()).isGreaterThanOrEqualTo(5); + } + + @Test + public void load_sq_version_from_file_in_classpath() { + Version version = MetadataLoader.loadSQVersion(System2.INSTANCE); assertThat(version).isNotNull(); assertThat(version.major()).isGreaterThanOrEqualTo(5); } @@ -66,9 +73,9 @@ public class MetadataLoaderTest { public void throw_ISE_if_fail_to_load_version() throws Exception { when(system.getResource(anyString())).thenReturn(new File("target/unknown").toURI().toURL()); - assertThatThrownBy(() -> MetadataLoader.loadVersion(system)) + assertThatThrownBy(() -> MetadataLoader.loadApiVersion(system)) .isInstanceOf(IllegalStateException.class) - .hasMessageContaining("Can not load /sq-version.txt from classpath"); + .hasMessageContaining("Can not load /sonar-api-version.txt from classpath"); } } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java index 4e85fc6c1cc..dca880238dc 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/SpringGlobalContainer.java @@ -28,7 +28,6 @@ import org.sonar.api.CoreProperties; import org.sonar.api.Plugin; import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; -import org.sonar.api.SonarQubeVersion; import org.sonar.api.internal.MetadataLoader; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.MessageException; @@ -79,10 +78,11 @@ public class SpringGlobalContainer extends SpringComponentContainer { } private void addBootstrapComponents() { - Version apiVersion = MetadataLoader.loadVersion(System2.INSTANCE); + Version apiVersion = MetadataLoader.loadApiVersion(System2.INSTANCE); + Version sqVersion = MetadataLoader.loadSQVersion(System2.INSTANCE); SonarEdition edition = MetadataLoader.loadEdition(System2.INSTANCE); DefaultAnalysisWarnings analysisWarnings = new DefaultAnalysisWarnings(System2.INSTANCE); - LOG.debug("{} {}", edition.getLabel(), apiVersion); + LOG.debug("{} {}", edition.getLabel(), sqVersion); add( // plugins ScannerPluginRepository.class, @@ -90,7 +90,8 @@ public class SpringGlobalContainer extends SpringComponentContainer { PluginClassloaderFactory.class, ScannerPluginJarExploder.class, ExtensionInstaller.class, - new SonarQubeVersion(apiVersion), + new org.sonar.api.SonarQubeVersion(sqVersion), + new org.sonar.core.platform.SonarQubeVersion(sqVersion), new GlobalServerSettingsProvider(), new GlobalConfigurationProvider(), new ScannerWsClientProvider(), diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java index e3b871d37c8..2d22dc26888 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java @@ -22,10 +22,10 @@ package org.sonar.scanner.platform; import java.util.Date; import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; -import org.sonar.api.SonarRuntime; import org.sonar.api.config.Configuration; import org.sonar.api.platform.Server; import org.sonar.api.utils.DateUtils; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; import static org.apache.commons.lang.StringUtils.trimToEmpty; @@ -34,12 +34,12 @@ public class DefaultServer extends Server { private final Configuration settings; private final DefaultScannerWsClient client; - private final SonarRuntime runtime; + private final SonarQubeVersion sonarQubeVersion; - public DefaultServer(Configuration settings, DefaultScannerWsClient client, SonarRuntime runtime) { + public DefaultServer(Configuration settings, DefaultScannerWsClient client, SonarQubeVersion sonarQubeVersion) { this.settings = settings; this.client = client; - this.runtime = runtime; + this.sonarQubeVersion = sonarQubeVersion; } @Override @@ -49,7 +49,7 @@ public class DefaultServer extends Server { @Override public String getVersion() { - return runtime.getApiVersion().toString(); + return sonarQubeVersion.get().toString(); } @Override diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java index c8979538a88..ee676ebbc0e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java @@ -21,12 +21,9 @@ package org.sonar.scanner.platform; import org.junit.Test; import org.sonar.api.CoreProperties; -import org.sonar.api.SonarEdition; -import org.sonar.api.SonarQubeSide; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.config.internal.Settings; -import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.utils.Version; +import org.sonar.core.platform.SonarQubeVersion; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; import static org.assertj.core.api.Assertions.assertThat; @@ -43,8 +40,7 @@ public class DefaultServerTest { DefaultScannerWsClient client = mock(DefaultScannerWsClient.class); when(client.baseUrl()).thenReturn("http://foo.com"); - DefaultServer metadata = new DefaultServer((settings).asConfig(), client, - SonarRuntimeImpl.forSonarQube(Version.parse("2.2"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY)); + DefaultServer metadata = new DefaultServer((settings).asConfig(), client, new SonarQubeVersion(Version.parse("2.2"))); assertThat(metadata.getId()).isEqualTo("123"); assertThat(metadata.getVersion()).isEqualTo("2.2"); |