diff options
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java | 7 | ||||
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ImageWidget.java | 4 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetScope.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetGlobal.java) | 16 | ||||
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java | 24 | ||||
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java | 5 |
5 files changed, 37 insertions, 19 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java index 654b568f6d1..067ead594eb 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java @@ -19,17 +19,16 @@ */ package org.sonar.plugins.core.widgets; -import org.sonar.api.web.WidgetCategory; - import org.sonar.api.web.AbstractRubyTemplate; import org.sonar.api.web.RubyRailsWidget; -import org.sonar.api.web.WidgetGlobal; +import org.sonar.api.web.WidgetCategory; import org.sonar.api.web.WidgetProperties; import org.sonar.api.web.WidgetProperty; import org.sonar.api.web.WidgetPropertyType; +import org.sonar.api.web.WidgetScope; @WidgetCategory({"Filters", "Global"}) -@WidgetGlobal +@WidgetScope("GLOBAL") @WidgetProperties({ @WidgetProperty(key = "filter", type = WidgetPropertyType.FILTER, optional = false) }) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ImageWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ImageWidget.java index c92c9af89dd..5ac2599ee75 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ImageWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ImageWidget.java @@ -22,13 +22,13 @@ package org.sonar.plugins.core.widgets; import org.sonar.api.web.AbstractRubyTemplate; import org.sonar.api.web.RubyRailsWidget; import org.sonar.api.web.WidgetCategory; -import org.sonar.api.web.WidgetGlobal; import org.sonar.api.web.WidgetProperties; import org.sonar.api.web.WidgetProperty; import org.sonar.api.web.WidgetPropertyType; +import org.sonar.api.web.WidgetScope; @WidgetCategory({"Global", "Misc"}) -@WidgetGlobal +@WidgetScope("GLOBAL") @WidgetProperties( { @WidgetProperty(key = "imageUrl", type = WidgetPropertyType.STRING, defaultValue = "http://www.sonarsource.org/wp-content/themes/sonarsource.org/images/sonar.png"), diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetGlobal.java b/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetScope.java index d515f778d62..afee3f127b8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetGlobal.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetScope.java @@ -19,19 +19,19 @@ */ package org.sonar.api.web; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +import java.lang.annotation.*; /** - * A widget is global when it can only be displayed on Global Dashboards. - * It doesn't display information from a projet but rather more general information. - * <p>Before version 3.1 no widget was global.</p> + * Depending on its scope, a widget can be available for project dashboards <code>(value = "PROJECT")</code>, + * global dashboards <code>(value = "GLOBAL")</code> or both <code>(value = {"PROJECT", "GLOBAL"})</code>. + * + * <p>Before version 3.1 all widget had a scope <code>"PROJECT"</code>. If a widget is not annotated with {@WidgetScope}, + * then is is assumed project scoped.</p> * * @since 3.1 */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -public @interface WidgetGlobal { +public @interface WidgetScope { + String[] value() default "PROJECT"; } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java index 85a74b45912..80b43da841a 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java @@ -19,6 +19,7 @@ */ package org.sonar.server.ui; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; @@ -26,7 +27,23 @@ import org.apache.commons.lang.builder.CompareToBuilder; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.utils.AnnotationUtils; -import org.sonar.api.web.*; +import org.sonar.api.web.DefaultTab; +import org.sonar.api.web.Description; +import org.sonar.api.web.GwtPage; +import org.sonar.api.web.NavigationSection; +import org.sonar.api.web.RequiredMeasures; +import org.sonar.api.web.ResourceLanguage; +import org.sonar.api.web.ResourceQualifier; +import org.sonar.api.web.ResourceScope; +import org.sonar.api.web.UserRole; +import org.sonar.api.web.View; +import org.sonar.api.web.Widget; +import org.sonar.api.web.WidgetCategory; +import org.sonar.api.web.WidgetLayout; +import org.sonar.api.web.WidgetLayoutType; +import org.sonar.api.web.WidgetProperties; +import org.sonar.api.web.WidgetProperty; +import org.sonar.api.web.WidgetScope; import java.util.Collection; import java.util.Map; @@ -93,7 +110,10 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> { } private void initWidgetGlobal(final V view) { - isGlobal = null != AnnotationUtils.getClassAnnotation(view, WidgetGlobal.class); + WidgetScope scopeAnnotation = AnnotationUtils.getClassAnnotation(view, WidgetScope.class); + if (scopeAnnotation != null) { + isGlobal = ImmutableSet.copyOf(scopeAnnotation.value()).contains("GLOBAL"); + } } private void initWidgetProperties(final V view) { diff --git a/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java b/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java index 64771b1a834..1571cac05e5 100644 --- a/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java +++ b/sonar-server/src/test/java/org/sonar/server/ui/ViewProxyTest.java @@ -19,8 +19,6 @@ */ package org.sonar.server.ui; -import org.sonar.api.web.WidgetGlobal; - import org.junit.Test; import org.sonar.api.web.DefaultTab; import org.sonar.api.web.NavigationSection; @@ -31,6 +29,7 @@ import org.sonar.api.web.Widget; import org.sonar.api.web.WidgetProperties; import org.sonar.api.web.WidgetProperty; import org.sonar.api.web.WidgetPropertyType; +import org.sonar.api.web.WidgetScope; import static org.fest.assertions.Assertions.assertThat; import static org.hamcrest.CoreMatchers.is; @@ -251,7 +250,7 @@ class EditableWidget implements Widget { } } -@WidgetGlobal +@WidgetScope("GLOBAL") class GlobalWidget implements Widget { public String getId() { return "global"; |