/** * Create an instance for SonarQube runtime environment. */ public static SonarRuntime forSonarQube(Version version, SonarQubeSide side) { return new SonarRuntimeImpl(version, SonarProduct.SONARQUBE, side); }
public Plugin.Context build() { return new PluginContextImpl(this); } }
@Test(expected = IllegalArgumentException.class) public void sonarqube_requires_side() throws Exception { SonarRuntimeImpl.forSonarQube(A_VERSION, null); }
@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); }
@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); }
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); }
@Test public void load_version_from_file_in_classpath() { Version version = ApiVersion.load(System2.INSTANCE); assertThat(version).isNotNull(); assertThat(version.major()).isGreaterThanOrEqualTo(5); }
@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); } }
@Test public void provide_extensions_for_6_6() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.6"), SonarQubeSide.SCANNER); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(51) .contains(XooBuiltInQualityProfilesDefinition.class); }
@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); }
/** * Create an instance for SonarLint runtime environment. */ public static SonarRuntime forSonarLint(Version version) { return new SonarRuntimeImpl(version, SonarProduct.SONARLINT, null); }
@Test public void provide_extensions_for_7_3() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.3"), SonarQubeSide.SCANNER); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(56) .contains(OneExternalIssuePerLineSensor.class); }
private void test(SonarQubeSide side) { underTest = new ServerIdManager(serverIdChecksum, serverIdFactory, dbClient, SonarRuntimeImpl.forSonarQube(Version.create(6, 7), side), webServer); underTest.start(); } }
@Test public void provide_extensions_for_7_6() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.6"), SonarQubeSide.SCANNER); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(58) .contains(GlobalProjectSensor.class) .contains(XooIgnoreCommand.class); }
@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); }
@Test public void test_context() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_5_6, SonarQubeSide.SERVER); MapSettings settings = new MapSettings().setProperty("foo", "bar"); Plugin.Context context = new PluginContextImpl.Builder() .setSonarRuntime(runtime) .setBootConfiguration(settings.asConfig()) .build(); assertThat(context.getSonarQubeVersion()).isEqualTo(VERSION_5_6); assertThat(context.getExtensions()).isEmpty(); context.addExtension("foo"); assertThat(context.getExtensions()).containsOnly("foo"); context.addExtensions(Arrays.asList("bar", "baz")); assertThat(context.getExtensions()).containsOnly("foo", "bar", "baz"); context.addExtensions("one", "two", "three", "four"); assertThat(context.getExtensions()).containsOnly("foo", "bar", "baz", "one", "two", "three", "four"); assertThat(context.getBootConfiguration().get("foo")).hasValue("bar"); } }
@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 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); }
@Before public void setUp() { XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SCANNER)); context = new RulesDefinition.Context(); def.define(context); }
private WebhookCaller newSender() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.2"), SonarQubeSide.SERVER); return new WebhookCallerImpl(system, new OkHttpClientProvider().provide(new MapSettings().asConfig(), runtime)); } }