use of org.sonarqube.ws.Settings 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.sonarqube.ws.Settings in project sonarqube by SonarSource.
the class AbstractSettingsLoader method load.
Map<String, String> load(@Nullable String componentKey) {
String url = "api/settings/values.protobuf";
Profiler profiler = Profiler.create(LOG);
if (componentKey != null) {
url += "?component=" + ScannerUtils.encodeForUrl(componentKey);
profiler.startInfo(String.format("Load project settings for component key: '%s'", componentKey));
} else {
profiler.startInfo("Load global settings");
}
try (InputStream is = wsClient.call(new GetRequest(url)).contentStream()) {
Settings.ValuesWsResponse values = Settings.ValuesWsResponse.parseFrom(is);
profiler.stopInfo();
return toMap(values.getSettingsList());
} catch (HttpException e) {
if (e.code() == HttpURLConnection.HTTP_NOT_FOUND) {
return Collections.emptyMap();
}
throw e;
} catch (IOException e) {
throw new IllegalStateException("Unable to load settings", e);
}
}
use of org.sonarqube.ws.Settings in project sonarqube by SonarSource.
the class ValuesAction method loadSettings.
private List<Setting> loadSettings(DbSession dbSession, Optional<ComponentDto> component, Set<String> keys) {
// List of settings must be kept in the following orders : default -> global -> component -> branch
List<Setting> settings = new ArrayList<>();
settings.addAll(loadDefaultValues(keys));
settings.addAll(loadGlobalSettings(dbSession, keys));
if (component.isPresent() && component.get().getBranch() != null && component.get().getMainBranchProjectUuid() != null) {
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, component.get().getMainBranchProjectUuid());
settings.addAll(loadComponentSettings(dbSession, keys, project).values());
}
component.ifPresent(componentDto -> settings.addAll(loadComponentSettings(dbSession, keys, componentDto).values()));
return settings.stream().filter(s -> settingsWsSupport.isVisible(s.getKey(), component)).collect(Collectors.toList());
}
Aggregations