Search in sources :

Example 1 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class SettingsDownloaderTest method testFetchProjectSettings.

@Test
public void testFetchProjectSettings() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    Settings.FieldValues.Value.Builder valuesBuilder = Value.newBuilder();
    valuesBuilder.getMutableValue().put("filepattern", "**/*.xml");
    valuesBuilder.getMutableValue().put("rulepattern", "*:S12345");
    Value value1 = valuesBuilder.build();
    valuesBuilder.clear();
    valuesBuilder.getMutableValue().put("filepattern", "**/*.java");
    valuesBuilder.getMutableValue().put("rulepattern", "*:S456");
    Value value2 = valuesBuilder.build();
    ValuesWsResponse response = ValuesWsResponse.newBuilder().addSettings(Setting.newBuilder().setKey("sonar.inclusions").setValues(Values.newBuilder().addValues("**/*.java"))).addSettings(Setting.newBuilder().setKey("sonar.java.fileSuffixes").setValue("*.java")).addSettings(Setting.newBuilder().setKey("sonar.issue.exclusions.multicriteria").setFieldValues(FieldValues.newBuilder().addFieldValues(value1).addFieldValues(value2)).build()).build();
    PipedInputStream in = new PipedInputStream();
    final PipedOutputStream out = new PipedOutputStream(in);
    response.writeTo(out);
    out.close();
    WsClientTestUtils.addResponse(wsClient, "/api/settings/values.protobuf?component=foo", in);
    Builder builder = ModuleConfiguration.newBuilder();
    new SettingsDownloader(wsClient).fetchProjectSettings("6.3", "foo", null, builder);
    assertThat(builder.getPropertiesMap()).containsOnly(entry("sonar.inclusions", "**/*.java"), entry("sonar.java.fileSuffixes", "*.java"), entry("sonar.issue.exclusions.multicriteria", "1,2"), entry("sonar.issue.exclusions.multicriteria.1.filepattern", "**/*.xml"), entry("sonar.issue.exclusions.multicriteria.1.rulepattern", "*:S12345"), entry("sonar.issue.exclusions.multicriteria.2.filepattern", "**/*.java"), entry("sonar.issue.exclusions.multicriteria.2.rulepattern", "*:S456"));
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) Value(org.sonarqube.ws.Settings.FieldValues.Value) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Settings(org.sonarqube.ws.Settings) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 2 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class SettingsDownloaderTest method testFetchProjectProperties_exclude_global_props.

@Test
public void testFetchProjectProperties_exclude_global_props() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithReaderResponse("/api/properties?format=json&resource=foo", new StringReader("[{\"key\": \"sonar.inclusions\",\"value\": \"**/*.java\"}," + "{\"key\": \"sonar.java.fileSuffixes\",\"value\": \"*.java\"}]"));
    Builder builder = ModuleConfiguration.newBuilder();
    new SettingsDownloader(wsClient).fetchProjectSettings("6.2", "foo", GlobalProperties.newBuilder().putProperties("sonar.inclusions", "**/*.java").build(), builder);
    assertThat(builder.getPropertiesMap()).containsOnly(entry("sonar.java.fileSuffixes", "*.java"));
}
Also used : Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) StringReader(java.io.StringReader) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 3 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class IssueStoreReaderTest method testMultiModule.

@Test
public void testMultiModule() {
    // setup module hierarchy
    Map<String, String> modulePaths = new HashMap<>();
    modulePaths.put(MODULE_KEY, "");
    modulePaths.put("root:module1", "module1/src");
    modulePaths.put("root:module2", "module2");
    Builder moduleConfigBuilder = ModuleConfiguration.newBuilder();
    moduleConfigBuilder.getMutableModulePathByKey().putAll(modulePaths);
    when(storage.readModuleConfig(MODULE_KEY)).thenReturn(moduleConfigBuilder.build());
    // setup issues
    issueStore.save(Arrays.asList(createServerIssue("root:module1", "path1"), createServerIssue("root:module1", "path2"), createServerIssue("root:module2", "path1"), createServerIssue("root:module2", "path2")));
    // test
    // matches module1 path
    assertThat(issueStoreReader.getServerIssues(MODULE_KEY, "module1/src/path1")).usingElementComparator(simpleComparator).containsOnly(createApiIssue(MODULE_KEY, "module1/src/path1"));
    // matches module2
    assertThat(issueStoreReader.getServerIssues(MODULE_KEY, "module2/path2")).usingElementComparator(simpleComparator).containsOnly(createApiIssue(MODULE_KEY, "module2/path2"));
    // no file found
    assertThat(issueStoreReader.getServerIssues(MODULE_KEY, "module1/src/path3")).isEmpty();
    // module not in storage
    exception.expect(IllegalStateException.class);
    exception.expectMessage("module not in storage");
    assertThat(issueStoreReader.getServerIssues("root:module1", "path2")).usingElementComparator(simpleComparator).containsOnly(createApiIssue("module1", "path2"));
}
Also used : HashMap(java.util.HashMap) Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) Test(org.junit.Test)

Example 4 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class ConnectedFileExclusionsMediumTest method updateModuleConfig.

private void updateModuleConfig(StoragePaths storagePaths, ModuleConfiguration originalModuleConfig, Map<String, String> props) {
    Builder newBuilder = ModuleConfiguration.newBuilder(originalModuleConfig);
    newBuilder.putAllProperties(props);
    ProtobufUtil.writeToFile(newBuilder.build(), storagePaths.getModuleConfigurationPath(MODULE_KEY));
}
Also used : Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder)

Example 5 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class ConnectedIssueExclusionsMediumTest method updateModuleConfig.

private void updateModuleConfig(StoragePaths storagePaths, ModuleConfiguration originalModuleConfig, Map<String, String> props) {
    Builder newBuilder = ModuleConfiguration.newBuilder(originalModuleConfig);
    newBuilder.getMutableProperties().putAll(props);
    ProtobufUtil.writeToFile(newBuilder.build(), storagePaths.getModuleConfigurationPath(JAVA_MODULE_KEY));
}
Also used : Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder)

Aggregations

Builder (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder)9 Test (org.junit.Test)7 HashMap (java.util.HashMap)4 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)3 StringReader (java.io.StringReader)2 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 ScannerInput (org.sonar.scanner.protocol.input.ScannerInput)1 Settings (org.sonarqube.ws.Settings)1 Value (org.sonarqube.ws.Settings.FieldValues.Value)1 ValuesWsResponse (org.sonarqube.ws.Settings.ValuesWsResponse)1 ServerIssue (org.sonarsource.sonarlint.core.client.api.connected.ServerIssue)1 DefaultServerIssue (org.sonarsource.sonarlint.core.container.model.DefaultServerIssue)1