From: Julien Lancelot Date: Mon, 22 Aug 2016 13:05:17 +0000 (+0200) Subject: SONAR-7969 Property with fields is considered as a PROPERTY_SET X-Git-Tag: 6.1-RC1~312 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8aa475de8bfa06cd991f02589c03a65df7bb397f;p=sonarqube.git SONAR-7969 Property with fields is considered as a PROPERTY_SET --- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index 4c61be59fa0..0100cf61d36 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -19,7 +19,6 @@ */ package org.sonar.api.config; -import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -38,6 +37,9 @@ import org.sonar.api.resources.Qualifiers; import org.sonar.api.server.ServerSide; import org.sonarsource.api.sonarlint.SonarLintSide; +import static com.google.common.base.Preconditions.checkArgument; +import static org.sonar.api.PropertyType.PROPERTY_SET; + /** * Declare a plugin property. Values are available at runtime through the component {@link Settings}. *
@@ -506,13 +508,16 @@ public final class PropertyDefinition { } public PropertyDefinition build() { - Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Key must be set"); + checkArgument(!Strings.isNullOrEmpty(key), "Key must be set"); fixType(key, type); - Preconditions.checkArgument(onQualifiers.isEmpty() || onlyOnQualifiers.isEmpty(), "Cannot define both onQualifiers and onlyOnQualifiers"); - Preconditions.checkArgument(!hidden || (onQualifiers.isEmpty() && onlyOnQualifiers.isEmpty()), "Cannot be hidden and defining qualifiers on which to display"); + checkArgument(onQualifiers.isEmpty() || onlyOnQualifiers.isEmpty(), "Cannot define both onQualifiers and onlyOnQualifiers"); + checkArgument(!hidden || (onQualifiers.isEmpty() && onlyOnQualifiers.isEmpty()), "Cannot be hidden and defining qualifiers on which to display"); if (hidden) { global = false; } + if (!fields.isEmpty()) { + type = PROPERTY_SET; + } return new PropertyDefinition(this); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java index 8133bbcc876..cb4b67f242f 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java @@ -152,6 +152,7 @@ public class PropertyDefinitionTest { PropertyFieldDefinition.build("second").name("Second").type(PropertyType.INTEGER).indicativeSize(5).build()) .build(); + assertThat(def.type()).isEqualTo(PropertyType.PROPERTY_SET); assertThat(def.fields()).hasSize(2); assertThat(def.fields().get(0).key()).isEqualTo("first"); assertThat(def.fields().get(0).name()).isEqualTo("First"); @@ -173,6 +174,7 @@ public class PropertyDefinitionTest { PropertyDefinition def = PropertyDefinition.create(prop); + assertThat(def.type()).isEqualTo(PropertyType.PROPERTY_SET); assertThat(def.fields()).hasSize(2); assertThat(def.fields().get(0).key()).isEqualTo("first"); assertThat(def.fields().get(0).name()).isEqualTo("First");