]> source.dussan.org Git - sonarqube.git/commitdiff
Now there are PROJECT and GLOBAL constants in WidgetScope
authorDavid Gageot <david@gageot.net>
Mon, 21 May 2012 12:58:05 +0000 (14:58 +0200)
committerDavid Gageot <david@gageot.net>
Mon, 21 May 2012 13:19:35 +0000 (15:19 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java
sonar-plugin-api/src/main/java/org/sonar/api/web/WidgetScope.java
sonar-server/src/main/java/org/sonar/server/ui/ViewProxy.java

index 067ead594eb0ed1ff9121755e8a8087adbb03c7c..76beef5339fdb74c925615829f8bd17d7eda8d97 100644 (file)
@@ -27,8 +27,10 @@ import org.sonar.api.web.WidgetProperty;
 import org.sonar.api.web.WidgetPropertyType;
 import org.sonar.api.web.WidgetScope;
 
+import static org.sonar.api.web.WidgetScope.*;
+
 @WidgetCategory({"Filters", "Global"})
-@WidgetScope("GLOBAL")
+@WidgetScope(GLOBAL)
 @WidgetProperties({
   @WidgetProperty(key = "filter", type = WidgetPropertyType.FILTER, optional = false)
 })
index afee3f127b815f639dc2cce4810fae2bd458cf08..5dd02fdb2800cfb1c00f728ffb0d8e4c2342b295 100644 (file)
@@ -33,5 +33,8 @@ import java.lang.annotation.*;
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.TYPE)
 public @interface WidgetScope {
-  String[] value() default "PROJECT";
+  String PROJECT = "PROJECT";
+  String GLOBAL = "GLOBAL";
+
+  String[] value() default PROJECT;
 }
index 82bc76adf9eea8c24e4f5271a6e0e40d96b174f4..29d869e050a34500e8ea96fd3c6e18f0753c9425 100644 (file)
@@ -113,13 +113,13 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
     WidgetScope scopeAnnotation = AnnotationUtils.getClassAnnotation(view, WidgetScope.class);
     if (scopeAnnotation != null) {
       checkValidScope(view, scopeAnnotation);
-      isGlobal = ImmutableSet.copyOf(scopeAnnotation.value()).contains("GLOBAL");
+      isGlobal = ImmutableSet.copyOf(scopeAnnotation.value()).contains(WidgetScope.GLOBAL);
     }
   }
 
   private static <V> void checkValidScope(V view, WidgetScope scopeAnnotation) {
     for (String scope : scopeAnnotation.value()) {
-      if (!scope.equals("PROJECT") && !scope.equalsIgnoreCase("GLOBAL")) {
+      if (!scope.equals(WidgetScope.PROJECT) && !scope.equalsIgnoreCase(WidgetScope.GLOBAL)) {
         throw new IllegalArgumentException(String.format("Invalid widget scope %s for widget %s", scope, view.getClass().getSimpleName()));
       }
     }