]> source.dussan.org Git - sonarqube.git/commitdiff
Refactor core widgets in order to add some unit tests
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 6 Dec 2012 20:54:42 +0000 (21:54 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 6 Dec 2012 20:54:42 +0000 (21:54 +0100)
38 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ActionPlansWidget.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AlertsWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CommentsDuplicationsWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ComplexityWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoreWidget.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/DescriptionWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/EventsWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMetricWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedResourcesWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedRulesWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/RulesWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/SizeWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WelcomeWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetConstants.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetsConstants.java [deleted file]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/actionPlans/ActionPlansWidget.java [deleted file]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/FalsePositiveReviewsWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/MyReviewsWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/PlannedReviewsWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ProjectReviewsWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsMetricsWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsPerDeveloperWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/UnplannedReviewsWidget.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoreWidgetsTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java [deleted file]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java [deleted file]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java [deleted file]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java [deleted file]

index baedbbfb19c50fbfac6e673328f1c325111a6aee..a695539aa2f326aecba1a6fff6d98c91bede321f 100644 (file)
@@ -104,7 +104,7 @@ import org.sonar.plugins.core.widgets.TimeMachineWidget;
 import org.sonar.plugins.core.widgets.TimelineWidget;
 import org.sonar.plugins.core.widgets.TreemapWidget;
 import org.sonar.plugins.core.widgets.WelcomeWidget;
-import org.sonar.plugins.core.widgets.actionPlans.ActionPlansWidget;
+import org.sonar.plugins.core.widgets.ActionPlansWidget;
 import org.sonar.plugins.core.widgets.reviews.FalsePositiveReviewsWidget;
 import org.sonar.plugins.core.widgets.reviews.MyReviewsWidget;
 import org.sonar.plugins.core.widgets.reviews.PlannedReviewsWidget;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ActionPlansWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ActionPlansWidget.java
new file mode 100644 (file)
index 0000000..6964ec7
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.core.widgets;
+
+import org.sonar.api.web.WidgetCategory;
+
+@WidgetCategory({"Action plans", "Reviews"})
+public class ActionPlansWidget extends CoreWidget {
+  public ActionPlansWidget() {
+    super("action_plans", "Action plans", "/org/sonar/plugins/core/widgets/actionPlans/action_plans.html.erb");
+  }
+}
\ No newline at end of file
index 62b8594de9f940253e40cebe9c79568c225af0cb..eb374e4a7e6bb52b6d0b510ec969119f7851e342 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 import org.sonar.api.web.WidgetLayout;
 import org.sonar.api.web.WidgetLayoutType;
 
 @WidgetLayout(WidgetLayoutType.NONE)
-public class AlertsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+public class AlertsWidget extends CoreWidget {
 
-  public String getId() {
-    return "alerts";
+  public AlertsWidget() {
+    super("alerts", "Alerts", "/org/sonar/plugins/core/widgets/alerts.html.erb");
   }
 
-  public String getTitle() {
-    return "Alerts";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/alerts.html.erb";
-  }
 }
\ No newline at end of file
index 281a6195feb715a80b7816cf8f682dbaa0505857..be66b24980e7b165e203d181700c4fcfc810f9dc 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
+public class CommentsDuplicationsWidget extends CoreWidget {
 
-public class CommentsDuplicationsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-
-  public String getId() {
-    return "comments_duplications";
-  }
-
-  public String getTitle() {
-    return "Comments & Duplications";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/comments_duplications.html.erb";
+  public CommentsDuplicationsWidget() {
+    super("comments_duplications", "Comments & Duplications", "/org/sonar/plugins/core/widgets/comments_duplications.html.erb");
   }
 }
\ No newline at end of file
index e63d61b11f91c7028e8feff7cb81fb2f623a7f7c..7c1598f32ce6cd926b45ef4d2e3851090bf4eb69 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
+public class ComplexityWidget extends CoreWidget {
 
-public class ComplexityWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-
-  public String getId() {
-    return "complexity";
-  }
-
-  public String getTitle() {
-    return "Complexity";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/complexity.html.erb";
+  public ComplexityWidget() {
+    super("complexity", "Complexity", "/org/sonar/plugins/core/widgets/complexity.html.erb");
   }
 }
\ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoreWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoreWidget.java
new file mode 100644 (file)
index 0000000..98cdb1d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.core.widgets;
+
+import org.sonar.api.web.AbstractRubyTemplate;
+import org.sonar.api.web.RubyRailsWidget;
+
+public abstract class CoreWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+  private String id, title, templatePath;
+
+  protected CoreWidget(String id, String title, String templatePath) {
+    this.id = id;
+    this.title = title;
+    this.templatePath = templatePath;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  @Override
+  protected String getTemplatePath() {
+    return templatePath;
+  }
+}
index 64c7718d62c1c245365aeb4c3fc1caea0ef5bc16..2b04b7b17c3db0b73ab36a31c3ebef5004ac1599 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 import org.sonar.api.web.UserRole;
 import org.sonar.api.web.WidgetCategory;
 
 @WidgetCategory("Tests")
 @UserRole(UserRole.USER)
-public class CoverageWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "code_coverage";
-  }
-
-  public String getTitle() {
-    return "Code coverage";
-  }
+public class CoverageWidget extends CoreWidget {
 
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/coverage.html.erb";
+  public CoverageWidget() {
+    super("code_coverage", "Code coverage", "/org/sonar/plugins/core/widgets/coverage.html.erb");
   }
 }
\ No newline at end of file
index 5ef27cdb110105039da85d08e52e7cd9958ace1b..e2a03c0b9034114b427fa8bbb28c9fb299e2d732 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 import org.sonar.api.web.WidgetProperties;
 import org.sonar.api.web.WidgetProperty;
 import org.sonar.api.web.WidgetPropertyType;
 
-@WidgetProperties(
-{
-  @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric4", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric5", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric6", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric7", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric8", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric9", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric10", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS})
+@WidgetProperties({
+  @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric4", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric5", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric6", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric7", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric8", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric9", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric10", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS})
 })
-public class CustomMeasuresWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "custom_measures";
-  }
-
-  public String getTitle() {
-    return "Custom Measures";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/custom_measures.html.erb";
+public class CustomMeasuresWidget extends CoreWidget {
+  public CustomMeasuresWidget() {
+    super("custom_measures", "Custom Measures", "/org/sonar/plugins/core/widgets/custom_measures.html.erb");
   }
 }
index c1f1a1da1fe2d5c11fc3f412a6d0970c4d714d12..8ba1024f02a9f539421c2ae8208cc84756547f91 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 import org.sonar.api.web.WidgetLayout;
 import org.sonar.api.web.WidgetLayoutType;
 
 @WidgetLayout(WidgetLayoutType.NONE)
-public class DescriptionWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+public class DescriptionWidget extends CoreWidget {
 
-  public String getId() {
-    return "description";
-  }
-
-  public String getTitle() {
-    return "Description";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/description.html.erb";
+  public DescriptionWidget() {
+    super("description", "Description", "/org/sonar/plugins/core/widgets/description.html.erb");
   }
 }
\ No newline at end of file
index 8964a8ccfe9cb695bb69f3225c83e6478ae42962..b9146305451b439c449bef28177c35d26316b5b2 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
+public class EventsWidget extends CoreWidget {
 
-public class EventsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-
-  public String getId() {
-    return "events";
-  }
-
-  public String getTitle() {
-    return "Events";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/events.html.erb";
+  public EventsWidget() {
+    super("events", "Events", "/org/sonar/plugins/core/widgets/events.html.erb");
   }
 }
\ No newline at end of file
index f69f6ad46bbbc1a7a553aca27fff717892c1d847..408b0b194daa887be6fe484a626eaeadb9db6804 100644 (file)
  */
 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.WidgetProperties;
 import org.sonar.api.web.WidgetProperty;
 import org.sonar.api.web.WidgetPropertyType;
 
 @WidgetCategory({ "Hotspots" })
-@WidgetProperties(
-    {
+@WidgetProperties({
         @WidgetProperty(key = "title", type = WidgetPropertyType.STRING),
         @WidgetProperty(key = "metric", type = WidgetPropertyType.METRIC, defaultValue = "ncloc"),
         @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5")
-    }
-)
-public class HotspotMetricWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "hotspot_metric";
-  }
-
-  public String getTitle() {
-    return "Metric hotspot";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb";
+})
+public class HotspotMetricWidget extends CoreWidget {
+  public HotspotMetricWidget() {
+    super("hotspot_metric", "Metric hotspot", "/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb");
   }
 }
\ No newline at end of file
index 6c78fb9c14cd9f5851eabfa4ef7951f5aa0a6e74..fd9d40cc4786306c278a2173277f84dc118ded3b 100644 (file)
  */
 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.WidgetProperties;
 import org.sonar.api.web.WidgetProperty;
 import org.sonar.api.web.WidgetPropertyType;
 
-@WidgetCategory({ "Hotspots" })
-@WidgetProperties(
-    {
-        @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5")
-    }
-)
-public class HotspotMostViolatedResourcesWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+@WidgetCategory({"Hotspots"})
+@WidgetProperties({
+  @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5")
+})
+public class HotspotMostViolatedResourcesWidget extends CoreWidget {
 
-  public String getId() {
-    return "hotspot_most_violated_resources";
-  }
-
-  public String getTitle() {
-    return "Most violated resources";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/hotspots/hotspot_most_violated_resources.html.erb";
+  public HotspotMostViolatedResourcesWidget() {
+    super("hotspot_most_violated_resources", "Most violated resources", "/org/sonar/plugins/core/widgets/hotspots/hotspot_most_violated_resources.html.erb");
   }
 }
\ No newline at end of file
index b58ed0cd89a98c34110174c103422e9865060bd8..6551fcc96abeecf58e003668917a63dbe71c8857 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.*;
+import org.sonar.api.web.WidgetCategory;
+import org.sonar.api.web.WidgetProperties;
+import org.sonar.api.web.WidgetProperty;
+import org.sonar.api.web.WidgetPropertyType;
 
 @WidgetCategory("Hotspots")
 @WidgetProperties(
@@ -28,17 +31,8 @@ import org.sonar.api.web.*;
     @WidgetProperty(key = "defaultSeverity", type = WidgetPropertyType.STRING, description = "Values: BLOCKER, CRITICAL, MAJOR, MINOR, INFO")
   }
 )
-public class HotspotMostViolatedRulesWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "hotspot_most_violated_rules";
-  }
-
-  public String getTitle() {
-    return "Most violated rules";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/hotspots/hotspot_most_violated_rules.html.erb";
+public class HotspotMostViolatedRulesWidget extends CoreWidget {
+  public HotspotMostViolatedRulesWidget() {
+    super("hotspot_most_violated_rules", "Most violated rules", "/org/sonar/plugins/core/widgets/hotspots/hotspot_most_violated_rules.html.erb");
   }
 }
\ No newline at end of file
index 20219bcb9c21a66ae6ab69cd9a71cb237b9eead3..1e344d9a665262fd95d1337f8c26d7372c8164a2 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 import org.sonar.api.web.UserRole;
 import org.sonar.api.web.WidgetCategory;
 
 @WidgetCategory("Tests")
 @UserRole(UserRole.USER)
-public class ItCoverageWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "it-coverage";
-  }
-
-  public String getTitle() {
-    return "Integration Test Coverage";
-  }
+public class ItCoverageWidget extends CoreWidget {
 
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/it_coverage.html.erb";
+  public ItCoverageWidget() {
+    super("it-coverage", "Integration Test Coverage", "/org/sonar/plugins/core/widgets/it_coverage.html.erb");
   }
 }
index 2c4615362e746f315f27fcc85a782530ed5ce81f..a5f4e4612c5ee54434304cb4e02edf8c66cbf343 100644 (file)
@@ -19,8 +19,6 @@
  */
 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.WidgetProperties;
 import org.sonar.api.web.WidgetProperty;
@@ -34,23 +32,14 @@ import static org.sonar.api.web.WidgetScope.GLOBAL;
 @WidgetProperties({
   @WidgetProperty(key = MeasureFilterListWidget.FILTER_PROPERTY, type = WidgetPropertyType.FILTER, optional = false),
   @WidgetProperty(key = MeasureFilterListWidget.PAGE_SIZE_PROPERTY, type = WidgetPropertyType.INTEGER, defaultValue = "30")
-}
-)
-public class MeasureFilterListWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+})
+public class MeasureFilterListWidget extends CoreWidget {
   public static final String FILTER_PROPERTY = "filter";
   public static final String PAGE_SIZE_PROPERTY = "pageSize";
   public static final String ID = "measure_filter_list";
 
-  public String getId() {
-    return ID;
-  }
-
-  public String getTitle() {
-    return "Measure Filter as List";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/measure_filter_list.html.erb";
+  public MeasureFilterListWidget() {
+    super(ID, "Measure Filter as List",
+      "/org/sonar/plugins/core/widgets/measure_filter_list.html.erb");
   }
 }
index ff41d441dcabea6bd0f028086845360c3123247d..dc0256edd4b9cb18e43d040ae5d42c6fedfdf2ce 100644 (file)
@@ -19,8 +19,6 @@
  */
 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.WidgetProperties;
 import org.sonar.api.web.WidgetProperty;
@@ -35,24 +33,14 @@ import static org.sonar.api.web.WidgetScope.GLOBAL;
   @WidgetProperty(key = MeasureFilterTreemapWidget.FILTER_PROPERTY, type = WidgetPropertyType.FILTER, optional = false),
   @WidgetProperty(key = MeasureFilterTreemapWidget.SIZE_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true),
   @WidgetProperty(key = MeasureFilterTreemapWidget.COLOR_METRIC_PROPERTY, type = WidgetPropertyType.METRIC, optional = true, options = "type:PERCENT")
-}
-)
-public class MeasureFilterTreemapWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+})
+public class MeasureFilterTreemapWidget extends CoreWidget {
   public static final String FILTER_PROPERTY = "filter";
   public static final String SIZE_METRIC_PROPERTY = "sizeMetric";
   public static final String COLOR_METRIC_PROPERTY = "colorMetric";
   public static final String ID = "measure_filter_treemap";
 
-  public String getId() {
-    return ID;
-  }
-
-  public String getTitle() {
-    return "Measure Filter as Treemap";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb";
+  public MeasureFilterTreemapWidget() {
+    super(ID, "Measure Filter as Treemap", "/org/sonar/plugins/core/widgets/measure_filter_treemap.html.erb");
   }
 }
index cc14b78be67e5fc1d007debacf73fc231296804c..b5f516a62ba902abd64b940e6ed97f3fb0b1880b 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 import org.sonar.api.web.WidgetCategory;
 
-@WidgetCategory({ "Rules" })
-public class RulesWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+@WidgetCategory({"Rules"})
+public class RulesWidget extends CoreWidget {
 
-  public String getId() {
-    return "rules";
-  }
-
-  public String getTitle() {
-    return "Rules Compliance";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/rules.html.erb";
+  public RulesWidget() {
+    super("rules", "Rules Compliance", "/org/sonar/plugins/core/widgets/rules.html.erb");
   }
 }
\ No newline at end of file
index 62d055368c480d4eb5b221696572bbde606d31e7..627ead574a3be2c58134e5b3d5f2b95b615e8cec 100644 (file)
  */
 package org.sonar.plugins.core.widgets;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
+public class SizeWidget extends CoreWidget {
 
-public class SizeWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-
-  public String getId() {
-    return "size";
-  }
-
-  public String getTitle() {
-    return "Size metrics";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/size.html.erb";
+  public SizeWidget() {
+    super("size", "Size metrics", "/org/sonar/plugins/core/widgets/size.html.erb");
   }
 }
index 362a1437b832fc1467f31b589b381e557dd7115a..c43c2cd646317428423ab908577cb9ef39882fe1 100644 (file)
@@ -19,8 +19,6 @@
  */
 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.WidgetProperties;
 import org.sonar.api.web.WidgetProperty;
@@ -31,28 +29,19 @@ import org.sonar.api.web.WidgetPropertyType;
   @WidgetProperty(key = "title", type = WidgetPropertyType.STRING),
   @WidgetProperty(key = "numberOfColumns", type = WidgetPropertyType.INTEGER, defaultValue = "3"),
   @WidgetProperty(key = "displaySparkLine", type = WidgetPropertyType.BOOLEAN),
-  @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, defaultValue = "ncloc", options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric4", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric5", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric6", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric7", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric8", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric9", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric10", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS})
+  @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, defaultValue = "ncloc", options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric4", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric5", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric6", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric7", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric8", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric9", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric10", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS})
 })
-public class TimeMachineWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "time_machine";
-  }
-
-  public String getTitle() {
-    return "History Table";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/time_machine.html.erb";
+public class TimeMachineWidget extends CoreWidget {
+  public TimeMachineWidget() {
+    super("time_machine", "History Table", "/org/sonar/plugins/core/widgets/time_machine.html.erb");
   }
 }
index aa540fb885960bfbce1632a8fddefd335488ad31..25d19a9f7405ba02754f4f719aebaa1c82709d72 100644 (file)
@@ -19,8 +19,6 @@
  */
 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.WidgetProperties;
 import org.sonar.api.web.WidgetProperty;
@@ -29,23 +27,14 @@ import org.sonar.api.web.WidgetPropertyType;
 @WidgetCategory("History")
 @WidgetProperties({
   @WidgetProperty(key = "chartTitle", type = WidgetPropertyType.STRING),
-  @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, defaultValue = "ncloc", options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
-  @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC, options = {WidgetsConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC, defaultValue = "ncloc", options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
+  @WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC, options = {WidgetConstants.FILTER_OUT_NEW_METRICS}),
   @WidgetProperty(key = "hideEvents", type = WidgetPropertyType.BOOLEAN),
   @WidgetProperty(key = "chartHeight", type = WidgetPropertyType.INTEGER, defaultValue = "80")
 })
-public class TimelineWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "timeline";
-  }
-
-  public String getTitle() {
-    return "Timeline";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/timeline.html.erb";
+public class TimelineWidget extends CoreWidget {
+  public TimelineWidget() {
+    super("timeline", "Timeline", "/org/sonar/plugins/core/widgets/timeline.html.erb");
   }
 }
index 05774d5c705db3118a7fcfcb84543b7eedcab4a4..c1beb2258df30b5c297ad47d2d5fd2edd8134f47 100644 (file)
 package org.sonar.plugins.core.widgets;
 
 import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.web.*;
+import org.sonar.api.web.WidgetProperties;
+import org.sonar.api.web.WidgetProperty;
+import org.sonar.api.web.WidgetPropertyType;
 
 @WidgetProperties({
-  @WidgetProperty(key = "sizeMetric", type= WidgetPropertyType.METRIC, defaultValue = CoreMetrics.NCLOC_KEY, description = "Default metric for size"),
-  @WidgetProperty(key = "colorMetric", type= WidgetPropertyType.METRIC, defaultValue = CoreMetrics.VIOLATIONS_DENSITY_KEY, description = "Default metric for color")
+  @WidgetProperty(key = "sizeMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.NCLOC_KEY, description = "Default metric for size"),
+  @WidgetProperty(key = "colorMetric", type = WidgetPropertyType.METRIC, defaultValue = CoreMetrics.VIOLATIONS_DENSITY_KEY, description = "Default metric for color")
 })
-public class TreemapWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
+public class TreemapWidget extends CoreWidget {
+  public TreemapWidget() {
     // do not use the id "treemap" to avoid conflict with the same CSS class
-    return "treemap-widget";
-  }
-
-  public String getTitle() {
-    return "Treemap of Components";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/treemap.html.erb";
+    super("treemap-widget", "Treemap of Components", "/org/sonar/plugins/core/widgets/treemap.html.erb");
   }
 }
\ No newline at end of file
index 5b3f4684e231597b5ee203bde42fc56e98b45c95..15492330e59b0237ec23405f48514f29ccb1dd3a 100644 (file)
@@ -19,8 +19,6 @@
  */
 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.WidgetScope;
 
@@ -28,20 +26,11 @@ import static org.sonar.api.web.WidgetScope.GLOBAL;
 
 @WidgetCategory({"Global"})
 @WidgetScope(GLOBAL)
-public class WelcomeWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+public class WelcomeWidget extends CoreWidget {
 
   public static final String ID = "welcome";
 
-  public String getId() {
-    return ID;
-  }
-
-  public String getTitle() {
-    return "Welcome";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/welcome.html.erb";
+  public WelcomeWidget() {
+    super(ID, "Welcome", "/org/sonar/plugins/core/widgets/welcome.html.erb");
   }
 }
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetConstants.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetConstants.java
new file mode 100644 (file)
index 0000000..f970565
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.core.widgets;
+
+/**
+ * Constants shared accross multiple widgets
+ */
+interface WidgetConstants {
+
+  /**
+   * Widget property option used to filter out all the metrics which keys start with "new_".
+   *
+   * @see org.sonar.api.web.WidgetProperty#options()
+   */
+  String FILTER_OUT_NEW_METRICS = "key:^(?!new_).*";
+}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetsConstants.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetsConstants.java
deleted file mode 100644 (file)
index 6f44845..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.core.widgets;
-
-/**
- * Constants shared accross multiple widgets
- */
-interface WidgetsConstants {
-
-  /**
-   * Widget property option used to filter out all the metrics which keys start with "new_".
-   *
-   * @see org.sonar.api.web.WidgetProperty#options()
-   */
-  String FILTER_OUT_NEW_METRICS = "key:^(?!new_).*";
-}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/actionPlans/ActionPlansWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/actionPlans/ActionPlansWidget.java
deleted file mode 100644 (file)
index 1c12b97..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.core.widgets.actionPlans;
-
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
-import org.sonar.api.web.WidgetCategory;
-
-@WidgetCategory({ "Action plans", "Reviews" })
-public class ActionPlansWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "action_plans";
-  }
-
-  public String getTitle() {
-    return "Action plans";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/actionPlans/action_plans.html.erb";
-  }
-}
\ No newline at end of file
index f973ab6bf36e245c9f5dd1e23f23f6b97511bb56..514f2c75f398dbd4f637427c8e6f6932a48f79a2 100644 (file)
  */
 package org.sonar.plugins.core.widgets.reviews;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 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.plugins.core.widgets.CoreWidget;
 
-@WidgetCategory({ "Reviews" })
-@WidgetProperties(
-    {
-        @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5", 
-                        description="Maximum number of reviews displayed at the same time.")
-    }
-)
-public class FalsePositiveReviewsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "false_positive_reviews";
-  }
-
-  public String getTitle() {
-    return "False positive open reviews";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/reviews/false_positive_reviews.html.erb";
+@WidgetCategory({"Reviews"})
+@WidgetProperties({
+  @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5",
+    description = "Maximum number of reviews displayed at the same time.")
+})
+public class FalsePositiveReviewsWidget extends CoreWidget {
+  public FalsePositiveReviewsWidget() {
+    super("false_positive_reviews", "False positive open reviews", "/org/sonar/plugins/core/widgets/reviews/false_positive_reviews.html.erb");
   }
 }
\ No newline at end of file
index 0e3a385576a93c6f27f187c8a410a0d2efba97b3..64d6828c5d24c8bc99f7f94ab27a85df393ab7be 100644 (file)
  */
 package org.sonar.plugins.core.widgets.reviews;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 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.plugins.core.widgets.CoreWidget;
 
-@WidgetCategory({ "Reviews" })
-@WidgetProperties(
-    {
-        @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5", 
-                        description="Maximum number of reviews displayed at the same time.")
-    }
-)
-public class MyReviewsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "my_reviews";
-  }
-
-  public String getTitle() {
-    return "My active reviews";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/reviews/my_reviews.html.erb";
+@WidgetCategory({"Reviews"})
+@WidgetProperties({
+  @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5",
+    description = "Maximum number of reviews displayed at the same time.")
+})
+public class MyReviewsWidget extends CoreWidget {
+  public MyReviewsWidget() {
+    super("my_reviews", "My active reviews", "/org/sonar/plugins/core/widgets/reviews/my_reviews.html.erb");
   }
 }
\ No newline at end of file
index eb1abe18dc0f3a08f97695660fd93007fff36843..094f3bba94a1011e9e746bd9afe256ac719723f3 100644 (file)
  */
 package org.sonar.plugins.core.widgets.reviews;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 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.plugins.core.widgets.CoreWidget;
 
-@WidgetCategory({ "Action plans", "Reviews" })
-@WidgetProperties(
-    {
-        @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5", 
-                        description="Maximum number of reviews displayed at the same time.")
-    }
-)
-public class PlannedReviewsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "planned_reviews";
-  }
-
-  public String getTitle() {
-    return "Planned reviews";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/reviews/planned_reviews.html.erb";
+@WidgetCategory({"Action plans", "Reviews"})
+@WidgetProperties({
+  @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5",
+    description = "Maximum number of reviews displayed at the same time.")
+})
+public class PlannedReviewsWidget extends CoreWidget {
+  public PlannedReviewsWidget() {
+    super("planned_reviews", "Planned reviews", "/org/sonar/plugins/core/widgets/reviews/planned_reviews.html.erb");
   }
 }
\ No newline at end of file
index 1551e84233ee5edd5a4907f2ce366aa330ebad17..0dc6a863479fd7d3116cdeaeeff831fe2e01d920 100644 (file)
  */
 package org.sonar.plugins.core.widgets.reviews;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 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.plugins.core.widgets.CoreWidget;
 
-@WidgetCategory({ "Reviews" })
-@WidgetProperties(
-    {
-        @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5", 
-                        description="Maximum number of reviews displayed at the same time.")
-    }
-)
-public class ProjectReviewsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "project_reviews";
-  }
-
-  public String getTitle() {
-    return "Project active reviews";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/reviews/project_reviews.html.erb";
+@WidgetCategory({"Reviews"})
+@WidgetProperties({
+  @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5",
+    description = "Maximum number of reviews displayed at the same time.")
+})
+public class ProjectReviewsWidget extends CoreWidget {
+  public ProjectReviewsWidget() {
+    super("project_reviews", "Project active reviews", "/org/sonar/plugins/core/widgets/reviews/project_reviews.html.erb");
   }
 }
\ No newline at end of file
index c54478c445b9394d66dec29930bde4048a2ab840..3ced5b2337a760af951dba89280c07570c4e7404 100644 (file)
  */
 package org.sonar.plugins.core.widgets.reviews;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 import org.sonar.api.web.WidgetCategory;
+import org.sonar.plugins.core.widgets.CoreWidget;
 
-@WidgetCategory({ "Reviews" })
-public class ReviewsMetricsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "reviews_metrics";
-  }
-
-  public String getTitle() {
-    return "Review Activity";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/reviews/reviews_metrics.html.erb";
+@WidgetCategory({"Reviews"})
+public class ReviewsMetricsWidget extends CoreWidget {
+  public ReviewsMetricsWidget() {
+    super("reviews_metrics", "Review Activity", "/org/sonar/plugins/core/widgets/reviews/reviews_metrics.html.erb");
   }
 }
index 7a8abde808ab9a67e0d6deb689f23dda2a758312..94b61cca381dc48e7bba518e8e8c37393b10792e 100644 (file)
  */
 package org.sonar.plugins.core.widgets.reviews;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 import org.sonar.api.web.WidgetCategory;
+import org.sonar.plugins.core.widgets.CoreWidget;
 
-@WidgetCategory({ "Reviews" })
-public class ReviewsPerDeveloperWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "reviews_per_developer";
-  }
-
-  public String getTitle() {
-    return "Active reviews per developer";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/reviews/reviews_per_developer.html.erb";
+@WidgetCategory({"Reviews"})
+public class ReviewsPerDeveloperWidget extends CoreWidget {
+  public ReviewsPerDeveloperWidget() {
+    super("reviews_per_developer", "Active reviews per developer", "/org/sonar/plugins/core/widgets/reviews/reviews_per_developer.html.erb");
   }
 }
\ No newline at end of file
index 83660e87af3f01f8829e47abc576350f07846424..5b88866befb4292cbc3a7374b4d6bc91043249e7 100644 (file)
  */
 package org.sonar.plugins.core.widgets.reviews;
 
-import org.sonar.api.web.AbstractRubyTemplate;
-import org.sonar.api.web.RubyRailsWidget;
 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.plugins.core.widgets.CoreWidget;
 
-@WidgetCategory({ "Action plans", "Reviews" })
-@WidgetProperties(
-    {
-        @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5", 
-                        description="Maximum number of reviews displayed at the same time.")
-    }
-)
-public class UnplannedReviewsWidget extends AbstractRubyTemplate implements RubyRailsWidget {
-  public String getId() {
-    return "unplanned_reviews";
-  }
-
-  public String getTitle() {
-    return "Unplanned reviews";
-  }
-
-  @Override
-  protected String getTemplatePath() {
-    return "/org/sonar/plugins/core/widgets/reviews/unplanned_reviews.html.erb";
+@WidgetCategory({"Action plans", "Reviews"})
+@WidgetProperties({
+  @WidgetProperty(key = "numberOfLines", type = WidgetPropertyType.INTEGER, defaultValue = "5",
+    description = "Maximum number of reviews displayed at the same time.")
+})
+public class UnplannedReviewsWidget extends CoreWidget {
+  public UnplannedReviewsWidget() {
+    super("unplanned_reviews", "Unplanned reviews", "/org/sonar/plugins/core/widgets/reviews/unplanned_reviews.html.erb");
   }
 }
\ No newline at end of file
index 4d58ccd358dffef60efdf320b6941cf614831700..c1331829fa04a1a94009afc9d12ae8af23505af3 100644 (file)
 package org.sonar.plugins.core;
 
 import org.junit.Test;
-import org.reflections.Reflections;
-import org.sonar.api.web.AbstractRubyTemplate;
-
-import java.util.Set;
 
 import static org.fest.assertions.Assertions.assertThat;
 
 public class CorePluginTest {
   @Test
-  public void should_define_many_extensions() {
+  public void should_define_extensions() {
     assertThat(new CorePlugin().getExtensions().size()).isGreaterThan(10);
   }
-
-  @Test
-  public void should_contain_all_core_widgets() {
-    Set<Class<? extends AbstractRubyTemplate>> widgets = new Reflections("org.sonar.plugins.core.widgets").getSubTypesOf(AbstractRubyTemplate.class);
-
-    assertThat(widgets).isNotEmpty();
-    assertThat(new CorePlugin().getExtensions()).contains(widgets.toArray());
-  }
 }
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoreWidgetsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoreWidgetsTest.java
new file mode 100644 (file)
index 0000000..19393c2
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.core.widgets;
+
+import com.google.common.base.Function;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Sets;
+import org.junit.Test;
+import org.reflections.Reflections;
+import org.sonar.plugins.core.CorePlugin;
+
+import javax.annotation.Nullable;
+
+import java.util.Collection;
+import java.util.Set;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class CoreWidgetsTest {
+
+  @Test
+  public void widget_ids_should_be_unique() {
+    Collection<CoreWidget> widgets = widgets();
+    Collection<String> widgetIds = Collections2.transform(widgets, new Function<CoreWidget, String>() {
+      public String apply(@Nullable CoreWidget widget) {
+        return widget.getId();
+      }
+    });
+    assertThat(widgetIds).hasSize(Sets.newHashSet(widgetIds).size());
+  }
+
+  @Test
+  public void widget_templates_should_be_unique() {
+    Collection<CoreWidget> widgets = widgets();
+    Collection<String> templates = Collections2.transform(widgets, new Function<CoreWidget, String>() {
+      public String apply(@Nullable CoreWidget widget) {
+        return widget.getTemplatePath();
+      }
+    });
+    assertThat(templates).hasSize(Sets.newHashSet(templates).size());
+  }
+
+  @Test
+  public void widget_titles_should_be_unique() {
+    Collection<CoreWidget> widgets = widgets();
+    Collection<String> templates = Collections2.transform(widgets, new Function<CoreWidget, String>() {
+      public String apply(@Nullable CoreWidget widget) {
+        return widget.getTitle();
+      }
+    });
+    assertThat(templates).hasSize(Sets.newHashSet(templates).size());
+  }
+
+  @Test
+  public void should_find_templates() {
+    for (CoreWidget widget : widgets()) {
+      assertThat(widget.getClass().getResource(widget.getTemplatePath())).isNotNull();
+    }
+  }
+
+  @Test
+  public void should_be_registered_as_an_extension() {
+    for (CoreWidget widget : widgets()) {
+      assertThat(new CorePlugin().getExtensions()).contains(widget.getClass());
+    }
+  }
+
+  @Test
+  public void should_find_core_widgets() {
+    assertThat(widgets().size()).isGreaterThan(25);
+  }
+
+  private Set<Class<? extends CoreWidget>> widgetClasses() {
+    String[] packages = {"org.sonar.plugins.core.widgets", "org.sonar.plugins.core.widgets.reviews"};
+    return new Reflections(packages).getSubTypesOf(CoreWidget.class);
+  }
+
+  private Collection<CoreWidget> widgets() {
+    return Collections2.transform(widgetClasses(), new Function<Class<? extends CoreWidget>, CoreWidget>() {
+      public CoreWidget apply(@Nullable Class<? extends CoreWidget> aClass) {
+        try {
+          return aClass.newInstance();
+        } catch (Exception e) {
+          throw Throwables.propagate(e);
+        }
+      }
+    });
+  }
+}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java
deleted file mode 100644 (file)
index 5c666d2..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.core.widgets;
-
-import org.junit.Test;
-import org.sonar.plugins.core.CorePlugin;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class CoverageWidgetTest {
-  @Test
-  public void should_define_widget() {
-    CoverageWidget widget = new CoverageWidget();
-
-    assertThat(widget.getId()).isEqualTo("code_coverage");
-    assertThat(widget.getTitle()).isEqualTo("Code coverage");
-  }
-
-  @Test
-  public void should_find_template() {
-    CoverageWidget widget = new CoverageWidget();
-    assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull();
-  }
-
-  @Test
-  public void should_be_registered_as_an_extension() {
-    assertThat(new CorePlugin().getExtensions()).contains(CoverageWidget.class);
-  }
-}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java
deleted file mode 100644 (file)
index ffde53f..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.core.widgets;
-
-import com.google.common.io.Resources;
-import org.junit.Test;
-import org.sonar.plugins.core.CorePlugin;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class ItCoverageWidgetTest {
-  @Test
-  public void should_define_widget() {
-    ItCoverageWidget widget = new ItCoverageWidget();
-
-    assertThat(widget.getId()).isEqualTo("it-coverage");
-    assertThat(widget.getTitle()).isEqualTo("Integration Test Coverage");
-  }
-
-  @Test
-  public void should_find_template() {
-    ItCoverageWidget widget = new ItCoverageWidget();
-    assertThat(ItCoverageWidget.class.getResource(widget.getTemplatePath())).isNotNull();
-  }
-
-  @Test
-  public void should_be_registered_as_an_extension() {
-    assertThat(new CorePlugin().getExtensions()).contains(ItCoverageWidget.class);
-  }
-}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java
deleted file mode 100644 (file)
index 5337fae..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.core.widgets;
-
-import org.junit.Test;
-import org.sonar.plugins.core.CorePlugin;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class TreemapWidgetTest {
-  @Test
-  public void should_define_widget() {
-    TreemapWidget widget = new TreemapWidget();
-
-    assertThat(widget.getId()).isEqualTo("treemap-widget");
-    assertThat(widget.getTitle()).isEqualTo("Treemap of Components");
-  }
-
-  @Test
-  public void should_find_template() {
-    TreemapWidget widget = new TreemapWidget();
-    assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull();
-  }
-
-  @Test
-  public void should_be_registered_as_an_extension() {
-    assertThat(new CorePlugin().getExtensions()).contains(TreemapWidget.class);
-  }
-}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java
deleted file mode 100644 (file)
index dbe5d45..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.core.widgets;
-
-import org.junit.Test;
-import org.sonar.plugins.core.CorePlugin;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class WelcomeWidgetTest {
-  @Test
-  public void should_define_widget() {
-    WelcomeWidget widget = new WelcomeWidget();
-
-    assertThat(widget.getId()).isEqualTo("welcome");
-    assertThat(widget.getTitle()).isEqualTo("Welcome");
-  }
-
-  @Test
-  public void should_find_template() {
-    WelcomeWidget widget = new WelcomeWidget();
-    assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull();
-  }
-
-  @Test
-  public void should_be_registered_as_an_extension() {
-    assertThat(new CorePlugin().getExtensions()).contains(WelcomeWidget.class);
-  }
-}