summaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-03-27 12:41:49 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-03-27 12:41:49 +0100
commiteb01b4fe84116ca103c1f5009307c145e9d44148 (patch)
tree4cf41390df2efb3041b99c7eef888d20a9176460 /sonar-plugin-api
parent062a80a47a10f6b4066d731cf7989f1271688819 (diff)
downloadsonarqube-eb01b4fe84116ca103c1f5009307c145e9d44148.tar.gz
sonarqube-eb01b4fe84116ca103c1f5009307c145e9d44148.zip
SONAR-3891 Make it possible for the Views and Developers plugin to decide if the Settings must be displayed on a View and a Developer
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java55
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java1
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java18
4 files changed, 24 insertions, 56 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 be4ee0527e2..3738f665c27 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
@@ -24,10 +24,10 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
-import org.sonar.api.BatchComponent;
+import org.sonar.api.BatchExtension;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
-import org.sonar.api.ServerComponent;
+import org.sonar.api.ServerExtension;
import org.sonar.api.resources.Qualifiers;
import javax.annotation.Nullable;
@@ -53,7 +53,7 @@ import static com.google.common.collect.Lists.newArrayList;
*
* @since 3.0
*/
-public final class PropertyDefinition implements BatchComponent, ServerComponent {
+public final class PropertyDefinition implements BatchExtension, ServerExtension {
private String key;
private String defaultValue;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java
index e7e2fb96c64..a705894c359 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java
@@ -69,7 +69,7 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
}
public PropertyDefinitions addComponent(Object component, String defaultCategory) {
- addComponentFromAnnotationPropety(component, defaultCategory);
+ addComponentFromAnnotationProperty(component, defaultCategory);
if (component instanceof PropertyDefinition) {
PropertyDefinition propertyDefinition = (PropertyDefinition) component;
add(propertyDefinition, defaultCategory);
@@ -77,7 +77,7 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
return this;
}
- private PropertyDefinitions addComponentFromAnnotationPropety(Object component, String defaultCategory){
+ private PropertyDefinitions addComponentFromAnnotationProperty(Object component, String defaultCategory){
Properties annotations = AnnotationUtils.getAnnotation(component, Properties.class);
if (annotations != null) {
for (Property property : annotations.value()) {
@@ -119,34 +119,14 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
return StringUtils.defaultString(deprecatedKeys.get(key), key);
}
- static enum PropertyDefinitionFilter {
- GLOBAL {
- @Override
- boolean accept(PropertyDefinition propertyDefinition) {
- return propertyDefinition.global();
- }
- },
- PROJECT {
- @Override
- boolean accept(PropertyDefinition propertyDefinition) {
- return propertyDefinition.project();
- }
- },
- MODULE {
- @Override
- boolean accept(PropertyDefinition propertyDefinition) {
- return propertyDefinition.module();
- }
- };
-
- abstract boolean accept(PropertyDefinition propertyDefinition);
- }
-
- private Map<String, Collection<PropertyDefinition>> getPropertiesByCategory(PropertyDefinitionFilter filter) {
+ /**
+ * @since 3.6
+ */
+ public Map<String, Collection<PropertyDefinition>> getPropertiesByCategory(String qualifier) {
Multimap<String, PropertyDefinition> byCategory = ArrayListMultimap.create();
for (PropertyDefinition definition : getAll()) {
- if (filter.accept(definition)) {
+ if (qualifier == null ? definition.global() : definition.qualifiers().contains(qualifier)) {
byCategory.put(getCategory(definition.key()), definition);
}
}
@@ -154,25 +134,8 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
return byCategory.asMap();
}
- /**
- * since 3.3
- */
- public Map<String, Collection<PropertyDefinition>> getGlobalPropertiesByCategory() {
- return getPropertiesByCategory(PropertyDefinitionFilter.GLOBAL);
- }
-
- /**
- * since 3.3
- */
- public Map<String, Collection<PropertyDefinition>> getProjectPropertiesByCategory() {
- return getPropertiesByCategory(PropertyDefinitionFilter.PROJECT);
- }
-
- /**
- * since 3.3
- */
- public Map<String, Collection<PropertyDefinition>> getModulePropertiesByCategory() {
- return getPropertiesByCategory(PropertyDefinitionFilter.MODULE);
+ public Map<String, Collection<PropertyDefinition>> getPropertiesByCategory() {
+ return getPropertiesByCategory(null);
}
public String getDefaultValue(String key) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java
index 4abc4619252..319174e3305 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceType.java
@@ -46,6 +46,7 @@ import java.util.Map;
* <li>"supportsGlobalDashboards" (since 3.2): if true, this resource can be displayed in global dashboards</li>
* <li>"hasRolePolicy" : if true, roles configuration is available in sidebar</li>
* <li>"comparable" (since 3.4) : if true, the resource can be compared to other resources</li>
+ * <li>"configurable" (since 3.6) : if true, the settings page can be displayed on the resource</li>
* </ul>
*
* @see DefaultResourceTypes in Sonar Core Plugin to see the default resource types
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java
index fbc5045b586..0837af1bd1a 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java
@@ -22,6 +22,7 @@ package org.sonar.api.config;
import org.junit.Test;
import org.sonar.api.Properties;
import org.sonar.api.Property;
+import org.sonar.api.resources.Qualifiers;
import static org.fest.assertions.Assertions.assertThat;
@@ -96,21 +97,24 @@ public class PropertyDefinitionsTest {
PropertyDefinition.build("global2").name("Global2").category("catGlobal1").global(true).project(false).module(false).build(),
PropertyDefinition.build("global3").name("Global3").category("catGlobal2").global(true).project(false).module(false).build(),
PropertyDefinition.build("project").name("Project").category("catProject").global(false).project(true).module(false).build(),
- PropertyDefinition.build("module").name("Module").category("catModule").global(false).project(false).module(true).build()
+ PropertyDefinition.build("module").name("Module").category("catModule").global(false).project(false).module(true).build(),
+ PropertyDefinition.build("view").name("View").category("catView").global(false).qualifiers(Qualifiers.VIEW).build()
);
- assertThat(def.getGlobalPropertiesByCategory().keySet()).containsOnly("catGlobal1", "catGlobal2");
- assertThat(def.getProjectPropertiesByCategory().keySet()).containsOnly("catProject");
- assertThat(def.getModulePropertiesByCategory().keySet()).containsOnly("catModule");
+ assertThat(def.getPropertiesByCategory(null).keySet()).containsOnly("catGlobal1", "catGlobal2");
+ assertThat(def.getPropertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly("catProject");
+ assertThat(def.getPropertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly("catModule");
+ assertThat(def.getPropertiesByCategory(Qualifiers.VIEW).keySet()).containsOnly("catView");
+ assertThat(def.getPropertiesByCategory("Unkown").keySet()).isEmpty();
}
@Test
public void should_group_by_category_on_annotation_plugin() {
PropertyDefinitions def = new PropertyDefinitions(ByCategory.class);
- assertThat(def.getGlobalPropertiesByCategory().keySet()).containsOnly("catGlobal1", "catGlobal2");
- assertThat(def.getProjectPropertiesByCategory().keySet()).containsOnly("catProject");
- assertThat(def.getModulePropertiesByCategory().keySet()).containsOnly("catModule");
+ assertThat(def.getPropertiesByCategory().keySet()).containsOnly("catGlobal1", "catGlobal2");
+ assertThat(def.getPropertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly("catProject");
+ assertThat(def.getPropertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly("catModule");
}
private void assertProperties(PropertyDefinitions definitions) {