]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7969 Property with fields is considered as a PROPERTY_SET
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 22 Aug 2016 13:05:17 +0000 (15:05 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 25 Aug 2016 08:03:39 +0000 (10:03 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java
sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java

index 4c61be59fa046e8fce124c711a6fc1e7cd972d63..0100cf61d360b4c4f3310ff4bf481ac1ed72ce36 100644 (file)
@@ -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}.
  * <br>
@@ -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);
     }
 
index 8133bbcc876f800e60a2934f0a9ce82b16fe4f51..cb4b67f242f5a7bed66f7c25be71de0e127c6edf 100644 (file)
@@ -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");