Search in sources :

Example 1 with PropertyDefinition

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();
}
Also used : PropertyDefinitions(org.sonar.api.config.PropertyDefinitions) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SortedMap(java.util.SortedMap) PropertyDefinition(org.sonar.api.config.PropertyDefinition)

Example 2 with PropertyDefinition

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);
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) PropertyDefinition(org.sonar.api.config.PropertyDefinition) PropertyDto(org.sonar.db.property.PropertyDto)

Example 3 with PropertyDefinition

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);
}
Also used : PropertyDefinition(org.sonar.api.config.PropertyDefinition)

Example 4 with PropertyDefinition

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);
        }
    }
}
Also used : PropertyFieldDefinition(org.sonar.api.config.PropertyFieldDefinition) PropertyDefinition(org.sonar.api.config.PropertyDefinition)

Example 5 with PropertyDefinition

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();
}
Also used : PropertyDefinition(org.sonar.api.config.PropertyDefinition) Test(org.junit.Test)

Aggregations

PropertyDefinition (org.sonar.api.config.PropertyDefinition)5 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 Test (org.junit.Test)1 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)1 PropertyFieldDefinition (org.sonar.api.config.PropertyFieldDefinition)1 ComponentDto (org.sonar.db.component.ComponentDto)1 PropertyDto (org.sonar.db.property.PropertyDto)1