aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-09-24 18:45:21 +0200
committerDavid Gageot <david@gageot.net>2012-09-24 18:46:23 +0200
commitdffab878ddf772d36f56b94ee1a739bc3fc1a984 (patch)
treede90d3509137ca1956e8f124b4c45aac2ea44c5e /sonar-plugin-api
parent0b846718dbf09e45d7b07b530d7e92f77ca15822 (diff)
downloadsonarqube-dffab878ddf772d36f56b94ee1a739bc3fc1a984.tar.gz
sonarqube-dffab878ddf772d36f56b94ee1a739bc3fc1a984.zip
SONAR-3529 API: ability to define property sets.
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/Property.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java9
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java18
3 files changed, 33 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/Property.java b/sonar-plugin-api/src/main/java/org/sonar/api/Property.java
index d76dc019a88..64037142ac2 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/Property.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/Property.java
@@ -98,4 +98,11 @@ public @interface Property {
* @since 3.3
*/
boolean multiValues() default false;
+
+ /**
+ * Name of the property set. Used only when type = <code>PropertyType.PROPERTY_SET</code>.
+ *
+ * @since 3.3
+ */
+ String property_set_name() default "";
}
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 69a8f16c879..5464b2f3cdd 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
@@ -67,6 +67,7 @@ public final class PropertyDefinition {
private boolean onModule = false;
private boolean isGlobal = true;
private boolean multiValues;
+ private String property_set_name;
private PropertyDefinition(Property annotation) {
this.key = annotation.key();
@@ -80,6 +81,7 @@ public final class PropertyDefinition {
this.type = fixType(annotation.key(), annotation.type());
this.options = annotation.options();
this.multiValues = annotation.multiValues();
+ this.property_set_name = annotation.property_set_name();
}
private static PropertyType fixType(String key, PropertyType type) {
@@ -180,4 +182,11 @@ public final class PropertyDefinition {
public boolean isMultiValues() {
return multiValues;
}
+
+ /**
+ * @since 3.3
+ */
+ public String getProperty_set_name() {
+ return property_set_name;
+ }
}
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 d65d3af3c86..061bb99a575 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
@@ -47,6 +47,7 @@ public class PropertyDefinitionTest {
assertThat(def.isOnProject()).isTrue();
assertThat(def.isOnModule()).isTrue();
assertThat(def.isMultiValues()).isTrue();
+ assertThat(def.getProperty_set_name()).isEmpty();
}
@Properties(@Property(key = "hello", name = "Hello", defaultValue = "world", description = "desc",
@@ -74,6 +75,21 @@ public class PropertyDefinitionTest {
assertThat(def.isMultiValues()).isFalse();
}
+ @Properties(@Property(key = "hello", name = "Hello", type = PropertyType.PROPERTY_SET, property_set_name = "set1"))
+ static class WithPropertySet {
+ }
+
+ @Test
+ public void should_support_property_sets() {
+ Properties props = AnnotationUtils.getAnnotation(WithPropertySet.class, Properties.class);
+ Property prop = props.value()[0];
+
+ PropertyDefinition def = PropertyDefinition.create(prop);
+
+ assertThat(def.getType()).isEqualTo(PropertyType.PROPERTY_SET);
+ assertThat(def.getProperty_set_name()).isEqualTo("set1");
+ }
+
@Properties(@Property(key = "hello", name = "Hello"))
static class DefaultValues {
}
@@ -131,7 +147,7 @@ public class PropertyDefinitionTest {
@Test
public void validate_single_select_list() {
- PropertyDefinition def = PropertyDefinition.create("foo", PropertyType.SINGLE_SELECT_LIST, new String[] {"de", "en"});
+ PropertyDefinition def = PropertyDefinition.create("foo", PropertyType.SINGLE_SELECT_LIST, new String[]{"de", "en"});
assertThat(def.validate(null).isValid()).isTrue();
assertThat(def.validate("").isValid()).isTrue();