From 51a54e747245ac047cab3aa36f91b026f04fa36d Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 6 Dec 2012 21:54:42 +0100 Subject: [PATCH] Refactor core widgets in order to add some unit tests --- .../org/sonar/plugins/core/CorePlugin.java | 2 +- .../core/widgets/ActionPlansWidget.java} | 29 +---- .../plugins/core/widgets/AlertsWidget.java | 16 +-- .../widgets/CommentsDuplicationsWidget.java | 18 +-- .../core/widgets/ComplexityWidget.java | 18 +-- ...ActionPlansWidget.java => CoreWidget.java} | 22 ++-- .../plugins/core/widgets/CoverageWidget.java | 16 +-- .../core/widgets/CustomMeasuresWidget.java | 40 +++---- .../core/widgets/DescriptionWidget.java | 17 +-- .../plugins/core/widgets/EventsWidget.java | 18 +-- .../core/widgets/HotspotMetricWidget.java | 23 +--- .../HotspotMostViolatedResourcesWidget.java | 27 ++--- .../HotspotMostViolatedRulesWidget.java | 20 ++-- .../core/widgets/ItCoverageWidget.java | 16 +-- .../core/widgets/MeasureFilterListWidget.java | 21 +--- .../widgets/MeasureFilterTreemapWidget.java | 20 +--- .../plugins/core/widgets/RulesWidget.java | 19 +--- .../plugins/core/widgets/SizeWidget.java | 18 +-- .../core/widgets/TimeMachineWidget.java | 37 +++--- .../plugins/core/widgets/TimelineWidget.java | 23 +--- .../plugins/core/widgets/TreemapWidget.java | 23 ++-- .../plugins/core/widgets/WelcomeWidget.java | 17 +-- ...etsConstants.java => WidgetConstants.java} | 2 +- .../reviews/FalsePositiveReviewsWidget.java | 30 ++--- .../core/widgets/reviews/MyReviewsWidget.java | 30 ++--- .../widgets/reviews/PlannedReviewsWidget.java | 30 ++--- .../widgets/reviews/ProjectReviewsWidget.java | 30 ++--- .../widgets/reviews/ReviewsMetricsWidget.java | 20 +--- .../reviews/ReviewsPerDeveloperWidget.java | 20 +--- .../reviews/UnplannedReviewsWidget.java | 30 ++--- .../sonar/plugins/core/CorePluginTest.java | 14 +-- .../plugins/core/widgets/CoreWidgetsTest.java | 107 ++++++++++++++++++ .../core/widgets/CoverageWidgetTest.java | 46 -------- .../core/widgets/ItCoverageWidgetTest.java | 47 -------- .../core/widgets/TreemapWidgetTest.java | 46 -------- 35 files changed, 285 insertions(+), 627 deletions(-) rename plugins/sonar-core-plugin/src/{test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java => main/java/org/sonar/plugins/core/widgets/ActionPlansWidget.java} (56%) rename plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/{actionPlans/ActionPlansWidget.java => CoreWidget.java} (73%) rename plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/{WidgetsConstants.java => WidgetConstants.java} (97%) create mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoreWidgetsTest.java delete mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java delete mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java delete mode 100644 plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index baedbbfb19c..a695539aa2f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -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/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ActionPlansWidget.java similarity index 56% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java rename to plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ActionPlansWidget.java index dbe5d45e85e..6964ec72987 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ActionPlansWidget.java @@ -19,28 +19,11 @@ */ package org.sonar.plugins.core.widgets; -import org.junit.Test; -import org.sonar.plugins.core.CorePlugin; +import org.sonar.api.web.WidgetCategory; -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); +@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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AlertsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AlertsWidget.java index 62b8594de9f..eb374e4a7e6 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AlertsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/AlertsWidget.java @@ -19,24 +19,14 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CommentsDuplicationsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CommentsDuplicationsWidget.java index 281a6195feb..be66b24980e 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CommentsDuplicationsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CommentsDuplicationsWidget.java @@ -19,21 +19,9 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ComplexityWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ComplexityWidget.java index e63d61b11f9..7c1598f32ce 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ComplexityWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ComplexityWidget.java @@ -19,21 +19,9 @@ */ 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/actionPlans/ActionPlansWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoreWidget.java similarity index 73% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/actionPlans/ActionPlansWidget.java rename to plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoreWidget.java index 1c12b9718da..98cdb1de160 100644 --- 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/CoreWidget.java @@ -17,24 +17,30 @@ * 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; +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({ "Action plans", "Reviews" }) -public class ActionPlansWidget extends AbstractRubyTemplate implements 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 "action_plans"; + return id; } public String getTitle() { - return "Action plans"; + return title; } @Override protected String getTemplatePath() { - return "/org/sonar/plugins/core/widgets/actionPlans/action_plans.html.erb"; + return templatePath; } -} \ No newline at end of file +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java index 64c7718d62c..2b04b7b17c3 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CoverageWidget.java @@ -19,24 +19,14 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java index 5ef27cdb110..e2a03c0b903 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/CustomMeasuresWidget.java @@ -19,36 +19,24 @@ */ 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"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/DescriptionWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/DescriptionWidget.java index c1f1a1da1fe..8ba1024f02a 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/DescriptionWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/DescriptionWidget.java @@ -19,24 +19,13 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/EventsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/EventsWidget.java index 8964a8ccfe9..b9146305451 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/EventsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/EventsWidget.java @@ -19,21 +19,9 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMetricWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMetricWidget.java index f69f6ad46bb..408b0b194da 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMetricWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMetricWidget.java @@ -19,32 +19,19 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedResourcesWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedResourcesWidget.java index 6c78fb9c14c..fd9d40cc478 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedResourcesWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedResourcesWidget.java @@ -19,31 +19,18 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedRulesWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedRulesWidget.java index b58ed0cd89a..6551fcc96ab 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedRulesWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/HotspotMostViolatedRulesWidget.java @@ -19,7 +19,10 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java index 20219bcb9c2..1e344d9a665 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/ItCoverageWidget.java @@ -19,24 +19,14 @@ */ 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"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java index 2c4615362e7..a5f4e4612c5 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java @@ -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"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java index ff41d441dca..dc0256edd4b 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterTreemapWidget.java @@ -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"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/RulesWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/RulesWidget.java index cc14b78be67..b5f516a62ba 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/RulesWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/RulesWidget.java @@ -19,23 +19,12 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/SizeWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/SizeWidget.java index 62d055368c4..627ead574a3 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/SizeWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/SizeWidget.java @@ -19,21 +19,9 @@ */ 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"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java index 362a1437b83..c43c2cd6463 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimeMachineWidget.java @@ -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"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java index aa540fb8859..25d19a9f740 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java @@ -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"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java index 05774d5c705..c1beb2258df 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java @@ -20,24 +20,17 @@ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WelcomeWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WelcomeWidget.java index 5b3f4684e23..15492330e59 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WelcomeWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WelcomeWidget.java @@ -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/WidgetsConstants.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetConstants.java similarity index 97% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetsConstants.java rename to plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/WidgetConstants.java index 6f44845d316..f9705655f94 100644 --- 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/WidgetConstants.java @@ -22,7 +22,7 @@ package org.sonar.plugins.core.widgets; /** * Constants shared accross multiple widgets */ -interface WidgetsConstants { +interface WidgetConstants { /** * Widget property option used to filter out all the metrics which keys start with "new_". diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/FalsePositiveReviewsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/FalsePositiveReviewsWidget.java index f973ab6bf36..514f2c75f39 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/FalsePositiveReviewsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/FalsePositiveReviewsWidget.java @@ -19,31 +19,19 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/MyReviewsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/MyReviewsWidget.java index 0e3a385576a..64d6828c5d2 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/MyReviewsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/MyReviewsWidget.java @@ -19,31 +19,19 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/PlannedReviewsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/PlannedReviewsWidget.java index eb1abe18dc0..094f3bba94a 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/PlannedReviewsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/PlannedReviewsWidget.java @@ -19,31 +19,19 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ProjectReviewsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ProjectReviewsWidget.java index 1551e84233e..0dc6a863479 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ProjectReviewsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ProjectReviewsWidget.java @@ -19,31 +19,19 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsMetricsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsMetricsWidget.java index c54478c445b..3ced5b2337a 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsMetricsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsMetricsWidget.java @@ -19,22 +19,12 @@ */ 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"); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsPerDeveloperWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsPerDeveloperWidget.java index 7a8abde808a..94b61cca381 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsPerDeveloperWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/ReviewsPerDeveloperWidget.java @@ -19,22 +19,12 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/UnplannedReviewsWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/UnplannedReviewsWidget.java index 83660e87af3..5b88866befb 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/UnplannedReviewsWidget.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/reviews/UnplannedReviewsWidget.java @@ -19,31 +19,19 @@ */ 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 diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java index 4d58ccd358d..c1331829fa0 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/CorePluginTest.java @@ -20,24 +20,12 @@ 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> 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 index 00000000000..19393c20e11 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoreWidgetsTest.java @@ -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 widgets = widgets(); + Collection widgetIds = Collections2.transform(widgets, new Function() { + 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 widgets = widgets(); + Collection templates = Collections2.transform(widgets, new Function() { + 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 widgets = widgets(); + Collection templates = Collections2.transform(widgets, new Function() { + 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> widgetClasses() { + String[] packages = {"org.sonar.plugins.core.widgets", "org.sonar.plugins.core.widgets.reviews"}; + return new Reflections(packages).getSubTypesOf(CoreWidget.class); + } + + private Collection widgets() { + return Collections2.transform(widgetClasses(), new Function, CoreWidget>() { + public CoreWidget apply(@Nullable Class 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 index 5c666d2d58b..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java +++ /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 index ffde53f41a8..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java +++ /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 index 5337fae9fd0..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java +++ /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); - } -} -- 2.39.5