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
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());
}
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;
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() {
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;
}
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,
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;
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);
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;
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
upsert
.setString(1, "installation.version")
.setBoolean(2, false)
- .setString(3, sonarRuntime.getApiVersion().toString())
+ .setString(3, sonarQubeVersion.get().toString())
.setLong(4, now)
.addBatch();
upsert
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;
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
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;
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
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;
}
/**
@Override
public String getVersion() {
- return runtime.getApiVersion().toString();
+ return version.get().toString();
}
@Override
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;
*/
@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);
// 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();
}
}
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() {
@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());
}
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
@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);
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);
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;
}
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);
}
}
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;
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;
}
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;
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;
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(
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;
@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"));
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'");
}
@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())
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;
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);
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));
}
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;
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,
--- /dev/null
+/*
+ * 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();
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
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) {
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);
}
}
@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
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);
}
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");
}
}
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;
}
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,
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(),
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;
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
@Override
public String getVersion() {
- return runtime.getApiVersion().toString();
+ return sonarQubeVersion.get().toString();
}
@Override
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;
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");