use of org.sonar.api.config.PropertyDefinition in project sonarqube by SonarSource.
the class SettingsMonitor method attributes.
@Override
public SortedMap<String, Object> attributes() {
PropertyDefinitions definitions = settings.getDefinitions();
ImmutableSortedMap.Builder<String, Object> builder = ImmutableSortedMap.naturalOrder();
for (Map.Entry<String, String> prop : settings.getProperties().entrySet()) {
String key = prop.getKey();
PropertyDefinition def = definitions.get(key);
if (def == null || def.type() != PropertyType.PASSWORD) {
builder.put(key, abbreviate(prop.getValue(), MAX_VALUE_LENGTH));
}
}
return builder.build();
}
use of org.sonar.api.config.PropertyDefinition in project sonarqube by SonarSource.
the class SetAction method doHandle.
private void doHandle(DbSession dbSession, SetRequest request) {
Optional<ComponentDto> component = searchComponent(dbSession, request);
checkPermissions(component);
PropertyDefinition definition = propertyDefinitions.get(request.getKey());
String value;
commonChecks(request, component);
if (!request.getFieldValues().isEmpty()) {
value = doHandlePropertySet(dbSession, request, definition, component);
} else {
validate(request);
PropertyDto property = toProperty(request, component);
value = property.getValue();
dbClient.propertiesDao().saveProperty(dbSession, property);
}
dbSession.commit();
if (!component.isPresent()) {
settingsChangeNotifier.onGlobalPropertyChange(persistedKey(request), value);
}
}
use of org.sonar.api.config.PropertyDefinition in project sonarqube by SonarSource.
the class SetAction method validate.
private void validate(SetRequest request) {
PropertyDefinition definition = propertyDefinitions.get(request.getKey());
if (definition == null) {
return;
}
checkSingleOrMultiValue(request, definition);
}
use of org.sonar.api.config.PropertyDefinition in project sonarqube by SonarSource.
the class SetAction method checkFieldType.
private static void checkFieldType(SetRequest request, PropertyDefinition definition, ListMultimap<String, String> valuesByFieldKeys) {
for (PropertyFieldDefinition fieldDefinition : definition.fields()) {
for (String value : valuesByFieldKeys.get(fieldDefinition.key())) {
PropertyDefinition.Result result = fieldDefinition.validate(value);
checkRequest(result.isValid(), "Error when validating setting with key '%s'. Field '%s' has incorrect value '%s'.", request.getKey(), fieldDefinition.key(), value);
}
}
}
use of org.sonar.api.config.PropertyDefinition in project sonarqube by SonarSource.
the class SettingsFinderTest method return_global_settings.
@Test
public void return_global_settings() throws Exception {
PropertyDefinition definition = PropertyDefinition.builder("foo").build();
addDefinitions(definition);
insertProperties(newGlobalPropertyDto().setKey("foo").setValue("one"));
List<Setting> settings = underTest.loadGlobalSettings(dbSession, newHashSet("foo"));
assertThat(settings).hasSize(1);
assertSetting(settings.get(0), "foo", "one", null, true);
assertThat(underTest.loadGlobalSettings(dbSession, newHashSet("unknown"))).isEmpty();
}
Aggregations