summaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-22 15:05:17 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-08-25 10:03:39 +0200
commit8aa475de8bfa06cd991f02589c03a65df7bb397f (patch)
tree4fd8905dda0a814f370a766e7071772542d3447f /sonar-plugin-api
parent264564f203337c47d4bf7aded6d63f1cb0119468 (diff)
downloadsonarqube-8aa475de8bfa06cd991f02589c03a65df7bb397f.tar.gz
sonarqube-8aa475de8bfa06cd991f02589c03a65df7bb397f.zip
SONAR-7969 Property with fields is considered as a PROPERTY_SET
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java13
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java2
2 files changed, 11 insertions, 4 deletions
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}.
* <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);
}
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");