@Test(expected = IllegalArgumentException.class) public void sonarqube_requires_side() throws Exception { SonarRuntimeImpl.forSonarQube(A_VERSION, null); }
@Test public void sonarLint_environment() { SonarRuntime apiVersion = SonarRuntimeImpl.forSonarLint(A_VERSION); assertThat(apiVersion.getApiVersion()).isEqualTo(A_VERSION); assertThat(apiVersion.getProduct()).isEqualTo(SonarProduct.SONARLINT); try { apiVersion.getSonarQubeSide(); Assertions.fail("Expected exception"); } catch (Exception e) { assertThat(e).isInstanceOf(UnsupportedOperationException.class); } }
/** * Create an instance for SonarQube runtime environment. */ public static SonarRuntime forSonarQube(Version version, SonarQubeSide side) { return new SonarRuntimeImpl(version, SonarProduct.SONARQUBE, side); }
@Test public void sonarQube_environment() { SonarRuntime apiVersion = SonarRuntimeImpl.forSonarQube(A_VERSION, SonarQubeSide.SCANNER); assertThat(apiVersion.getApiVersion()).isEqualTo(A_VERSION); assertThat(apiVersion.getProduct()).isEqualTo(SonarProduct.SONARQUBE); assertThat(apiVersion.getSonarQubeSide()).isEqualTo(SonarQubeSide.SCANNER); }
@Test public void provide_extensions_for_5_6() { SonarRuntime runtime = SonarRuntimeImpl.forSonarLint(Version.parse("5.4")); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(48) .doesNotContain(XooBuiltInQualityProfilesDefinition.class); }
/** * Create an instance for SonarLint runtime environment. */ public static SonarRuntime forSonarLint(Version version) { return new SonarRuntimeImpl(version, SonarProduct.SONARLINT, null); }
private SensorContextTester(Path moduleBaseDir) { this.settings = new MapSettings(); this.fs = new DefaultFileSystem(moduleBaseDir).setEncoding(Charset.defaultCharset()); this.activeRules = new ActiveRulesBuilder().build(); 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(ApiVersion.load(System2.INSTANCE), SonarQubeSide.SCANNER); }
static SonarComponents sonarComponents(File file) { SensorContextTester context = SensorContextTester.create(new File("")).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7))); context.setSettings(new MapSettings().setProperty("sonar.java.failOnException", true)); SonarComponents sonarComponents = new SonarComponents(null, context.fileSystem(), null, null, null) { @Override public boolean reportAnalysisError(RecognitionException re, File file) { return false; } }; sonarComponents.setSensorContext(context); context.fileSystem().add(new TestInputFileBuilder("", file.getPath()).setCharset(StandardCharsets.UTF_8).build()); return sonarComponents; }
/** * Create an instance for SonarQube runtime environment. */ public static SonarRuntime forSonarQube(Version version, SonarQubeSide side) { return new SonarRuntimeImpl(version, SonarProduct.SONARQUBE, side); }
@Test public void load_from_database_if_server_is_startup_follower() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER); when(webServer.isStartupLeader()).thenReturn(false); testLoadingFromDatabase(runtime, false); }
@Override protected void doBeforeStart() { Version version = ApiVersion.load(System2.INSTANCE); add( StandalonePluginIndex.class, PluginRepository.class, PluginVersionChecker.class, PluginCacheLoader.class, PluginLoader.class, PluginClassloaderFactory.class, DefaultPluginJarExploder.class, GlobalSettings.class, new GlobalConfigurationProvider(), ExtensionInstaller.class, new SonarQubeVersion(version), SonarRuntimeImpl.forSonarLint(version), new GlobalTempFolderProvider(), UriReader.class, new PluginCacheProvider(), System2.INSTANCE); }
/** * Create an instance for SonarLint runtime environment. */ public static SonarRuntime forSonarLint(Version version) { return new SonarRuntimeImpl(version, SonarProduct.SONARLINT, null); }
@Test public void load_from_database_if_compute_engine_of_startup_follower_server() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE); testLoadingFromDatabase(runtime, false); }
new SonarQubeRulesProvider(), new SonarQubeVersion(version), SonarRuntimeImpl.forSonarLint(version), System2.INSTANCE);
@Test public void generate_SERVER_STARTIME_but_do_not_persist_it_if_server_is_startup_leader() { when(system.now()).thenReturn(A_DATE); SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER); when(webServer.isStartupLeader()).thenReturn(true); StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(metadata.getStartedAt()).isEqualTo(A_DATE); assertNotPersistedProperty(CoreProperties.SERVER_STARTTIME); // keep a cache StartupMetadata secondMetadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(secondMetadata).isSameAs(metadata); }
private void test(SonarQubeSide side) { underTest = new ServerIdManager(serverIdChecksum, serverIdFactory, dbClient, SonarRuntimeImpl.forSonarQube(Version.create(6, 7), side), webServer); underTest.start(); } }
@Test public void load_from_database_if_compute_engine_of_startup_leader_server() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE); testLoadingFromDatabase(runtime, true); }
@Test public void shouldLoadServerProperties() { Settings settings = new MapSettings(); settings.setProperty(CoreProperties.SERVER_ID, "123"); settings.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000"); ScannerWsClient client = mock(ScannerWsClient.class); when(client.baseUrl()).thenReturn("http://foo.com"); DefaultServer metadata = new DefaultServer(((MapSettings) settings).asConfig(), client, SonarRuntimeImpl.forSonarQube(Version.parse("2.2"), SonarQubeSide.SCANNER)); assertThat(metadata.getId()).isEqualTo("123"); assertThat(metadata.getVersion()).isEqualTo("2.2"); assertThat(metadata.getStartedAt()).isNotNull(); assertThat(metadata.getURL()).isEqualTo("http://foo.com"); assertThat(metadata.getPermanentServerId()).isEqualTo("123"); assertThat(metadata.getRootDir()).isNull(); assertThat(metadata.getContextPath()).isNull(); assertThat(metadata.isDev()).isFalse(); assertThat(metadata.isSecured()).isFalse(); }
@Test public void fail_to_load_from_database_if_properties_are_not_persisted() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE); when(webServer.isStartupLeader()).thenReturn(false); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Property sonar.core.startTime is missing in database"); underTest.provide(system, runtime, webServer, dbTester.getDbClient()); }
@Test public void provide_extensions_for_7_2() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.2"), SonarQubeSide.SCANNER); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(55) .contains(OneExternalIssuePerLineSensor.class); }