public Optional<String> get(String key) {
String effectiveKey = definitions.validKey(key);
PropertyDefinition def = definitions.get(effectiveKey);
- if (def != null && def.multiValues()) {
- LOG.warn("Access to the multi-valued property '{}' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.", key);
+ if (def != null && (def.multiValues() || !def.fields().isEmpty())) {
+ LOG.warn("Access to the multi-values/property set property '{}' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.",
+ key);
}
return getInternal(effectiveKey);
}
public String[] getStringArray(String key) {
String effectiveKey = definitions.validKey(key);
PropertyDefinition def = definitions.get(effectiveKey);
- if (def != null && !def.multiValues()) {
- LOG.warn("Property '{}' is not declared as multi-valued but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.", key);
+ if (def != null && !def.multiValues() && def.fields().isEmpty()) {
+ LOG.warn(
+ "Property '{}' is not declared as multi-values/property set but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.",
+ key);
}
Optional<String> value = getInternal(effectiveKey);
if (value.isPresent()) {
import org.sonar.api.config.Encryption;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.PropertyFieldDefinition;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
assertThat(config.get("multiA")).hasValue("a,b");
assertThat(logTester.logs(LoggerLevel.WARN))
- .contains("Access to the multi-valued property 'multiA' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
+ .contains(
+ "Access to the multi-values/property set property 'multiA' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
logTester.clear();
assertThat(config.getStringArray("single")).containsExactly("foo");
assertThat(logTester.logs(LoggerLevel.WARN))
- .contains("Property 'single' is not declared as multi-valued but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.");
+ .contains(
+ "Property 'single' is not declared as multi-values/property set but was read using 'getStringArray' method. The SonarQube plugin declaring this property should be updated.");
logTester.clear();
assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
}
+ @Test
+ public void accessingPropertySetPropertiesShouldBeConsistentWithDeclaration() {
+ Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(
+ PropertyDefinition.builder("props").fields(PropertyFieldDefinition.build("foo1").name("Foo1").build(), PropertyFieldDefinition.build("foo2").name("Foo2").build()).build())),
+ new Encryption(null),
+ mock(AnalysisMode.class),
+ ImmutableMap.of("props", "1,2", "props.1.foo1", "a", "props.1.foo2", "b")) {
+ };
+
+ assertThat(config.get("props")).hasValue("1,2");
+ assertThat(logTester.logs(LoggerLevel.WARN))
+ .contains(
+ "Access to the multi-values/property set property 'props' should be made using 'getStringArray' method. The SonarQube plugin using this property should be updated.");
+
+ logTester.clear();
+
+ assertThat(config.getStringArray("props")).containsExactly("1", "2");
+ assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
+ }
+
@Test
public void getDefaultValues() {
Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList(