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"));
}
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"));
}
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"));
}
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));
}
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));
}
Aggregations