diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-12-15 18:44:21 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-12-15 18:44:21 +0100 |
commit | 16232e514c5b0d064a114906fb31441b97a480ae (patch) | |
tree | ffdea318d342f10e6396ae5120ea073d0acc1738 /plugins/sonar-core-plugin | |
parent | b84f33030464fcc3e6e70affb1680381516a19e6 (diff) | |
download | sonarqube-16232e514c5b0d064a114906fb31441b97a480ae.tar.gz sonarqube-16232e514c5b0d064a114906fb31441b97a480ae.zip |
SONAR-1929 refactor the extension point to define dashboards
Diffstat (limited to 'plugins/sonar-core-plugin')
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java | 4 | ||||
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/DefaultDashboard.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MainDashboard.java) | 34 | ||||
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java | 54 | ||||
-rw-r--r-- | plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb | 2 | ||||
-rw-r--r-- | plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java | 38 | ||||
-rw-r--r-- | plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java | 38 |
6 files changed, 131 insertions, 39 deletions
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 b56dd42f55c..58b343aeb46 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 @@ -34,7 +34,7 @@ import org.sonar.plugins.core.charts.DistributionBarChart; import org.sonar.plugins.core.charts.XradarChart; import org.sonar.plugins.core.colorizers.JavaColorizerFormat; import org.sonar.plugins.core.dashboards.HotspotsDashboard; -import org.sonar.plugins.core.dashboards.MainDashboard; +import org.sonar.plugins.core.dashboards.DefaultDashboard; import org.sonar.plugins.core.metrics.UserManagedMetrics; import org.sonar.plugins.core.security.ApplyProjectRolesDecorator; import org.sonar.plugins.core.sensors.*; @@ -250,7 +250,7 @@ public class CorePlugin extends SonarPlugin { extensions.add(ReviewsPerDeveloperWidget.class); // dashboards - extensions.add(MainDashboard.class); + extensions.add(DefaultDashboard.class); extensions.add(HotspotsDashboard.class); // chart diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MainDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/DefaultDashboard.java index 46d1a35e850..85f331b914a 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MainDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/DefaultDashboard.java @@ -28,24 +28,32 @@ import org.sonar.api.web.dashboard.DashboardTemplate; * * @since 2.13 */ -public final class MainDashboard extends DashboardTemplate { +public final class DefaultDashboard extends DashboardTemplate { @Override public Dashboard createDashboard() { - Dashboard dashboard = Dashboard.create("main", "Dashboard"); + Dashboard dashboard = Dashboard.create("dashboard", "Dashboard"); dashboard.setLayout(DashboardLayout.TWO_COLUMNS); - dashboard.addWidget("size", 1, 1); - dashboard.addWidget("comments_duplications", 1, 2); - dashboard.addWidget("complexity", 1, 3); - dashboard.addWidget("code_coverage", 1, 4); - dashboard.addWidget("events", 1, 5); - dashboard.addWidget("description", 1, 6); - dashboard.addWidget("rules", 2, 1); - dashboard.addWidget("alerts", 2, 2); - dashboard.addWidget("file_design", 2, 3); - dashboard.addWidget("package_design", 2, 4); - dashboard.addWidget("ckjm", 2, 5); + addFirstColumn(dashboard); + addSecondColumn(dashboard); return dashboard; } + private void addFirstColumn(Dashboard dashboard) { + dashboard.addWidget("size", 1); + dashboard.addWidget("comments_duplications", 1); + dashboard.addWidget("complexity", 1); + dashboard.addWidget("code_coverage", 1); + dashboard.addWidget("events", 1); + dashboard.addWidget("description", 1); + } + + private void addSecondColumn(Dashboard dashboard) { + dashboard.addWidget("rules", 2); + dashboard.addWidget("alerts", 2); + dashboard.addWidget("file_design", 2); + dashboard.addWidget("package_design", 2); + dashboard.addWidget("ckjm", 2); + } + }
\ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java index 5624cb34409..c8b9a4fb648 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/HotspotsDashboard.java @@ -20,8 +20,8 @@ package org.sonar.plugins.core.dashboards; import org.sonar.api.web.dashboard.Dashboard; +import org.sonar.api.web.dashboard.DashboardLayout; import org.sonar.api.web.dashboard.DashboardTemplate; -import org.sonar.api.web.dashboard.Widget; /** * Hotspot dashboard for Sonar @@ -36,37 +36,45 @@ public final class HotspotsDashboard extends DashboardTemplate { @Override public Dashboard createDashboard() { - Dashboard dashboard = Dashboard.create("hotspots", "Hotspots"); + Dashboard dashboard = Dashboard.createByName("Hotspots"); + dashboard.setLayout(DashboardLayout.TWO_COLUMNS); - Widget widget = dashboard.addWidget("hotspot_most_violated_rules", 1, 1); + addFirstColumn(dashboard); + addSecondColumn(dashboard); - widget = dashboard.addWidget(HOTSPOT_METRIC, 1, 2); - widget.addProperty(METRIC_PROPERTY, "test_execution_time"); - widget.addProperty(TITLE_PROPERTY, "Longest unit tests"); + return dashboard; + } - widget = dashboard.addWidget(HOTSPOT_METRIC, 1, 3); - widget.addProperty(METRIC_PROPERTY, "complexity"); - widget.addProperty(TITLE_PROPERTY, "Highest complexity"); + private void addFirstColumn(Dashboard dashboard) { + dashboard.addWidget("hotspot_most_violated_rules", 1); - widget = dashboard.addWidget(HOTSPOT_METRIC, 1, 4); - widget.addProperty(METRIC_PROPERTY, "duplicated_lines"); - widget.addProperty(TITLE_PROPERTY, "Highest duplications"); + Dashboard.Widget widget = dashboard.addWidget(HOTSPOT_METRIC, 1); + widget.setProperty(METRIC_PROPERTY, "test_execution_time"); + widget.setProperty(TITLE_PROPERTY, "Longest unit tests"); - widget = dashboard.addWidget("hotspot_most_violated_resources", 2, 1); + widget = dashboard.addWidget(HOTSPOT_METRIC, 1); + widget.setProperty(METRIC_PROPERTY, "complexity"); + widget.setProperty(TITLE_PROPERTY, "Highest complexity"); - widget = dashboard.addWidget(HOTSPOT_METRIC, 2, 2); - widget.addProperty(METRIC_PROPERTY, "uncovered_lines"); - widget.addProperty(TITLE_PROPERTY, "Highest untested lines"); + widget = dashboard.addWidget(HOTSPOT_METRIC, 1); + widget.setProperty(METRIC_PROPERTY, "duplicated_lines"); + widget.setProperty(TITLE_PROPERTY, "Highest duplications"); + } - widget = dashboard.addWidget(HOTSPOT_METRIC, 2, 3); - widget.addProperty(METRIC_PROPERTY, "function_complexity"); - widget.addProperty(TITLE_PROPERTY, "Highest average method complexity"); + private void addSecondColumn(Dashboard dashboard) { + dashboard.addWidget("hotspot_most_violated_resources", 2); - widget = dashboard.addWidget(HOTSPOT_METRIC, 2, 4); - widget.addProperty(METRIC_PROPERTY, "public_undocumented_api"); - widget.addProperty(TITLE_PROPERTY, "Most undocumented APIs"); + Dashboard.Widget widget = dashboard.addWidget(HOTSPOT_METRIC, 2); + widget.setProperty(METRIC_PROPERTY, "uncovered_lines"); + widget.setProperty(TITLE_PROPERTY, "Highest untested lines"); - return dashboard; + widget = dashboard.addWidget(HOTSPOT_METRIC, 2); + widget.setProperty(METRIC_PROPERTY, "function_complexity"); + widget.setProperty(TITLE_PROPERTY, "Highest average method complexity"); + + widget = dashboard.addWidget(HOTSPOT_METRIC, 2); + widget.setProperty(METRIC_PROPERTY, "public_undocumented_api"); + widget.setProperty(TITLE_PROPERTY, "Most undocumented APIs"); } }
\ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb index 7c397e1366b..47368a29e23 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/hotspots/hotspot_metric.html.erb @@ -36,7 +36,7 @@ <% unless snapshots && !snapshots.empty? %> <h3><%= title -%></h3> - <span class="empty_widget"><%= message('widget.hotspot_metric.cannot_display_not_numeric_metric') -%></span> + <span class="empty_widget"><%= message('no_results') -%></span> <% else %> <div class="line-block"> diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java new file mode 100644 index 00000000000..d5148fa1767 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java @@ -0,0 +1,38 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 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.dashboards; + +import org.hamcrest.core.Is; +import org.junit.Test; +import org.sonar.api.web.dashboard.Dashboard; +import org.sonar.api.web.dashboard.DashboardLayout; + +import static org.junit.Assert.assertThat; + +public class DefaultDashboardTest { + @Test + public void shouldCreateDashboard() { + Dashboard main = new DefaultDashboard().createDashboard(); + assertThat(main.getId(), Is.is("dashboard")); + assertThat(main.getName(), Is.is("Dashboard")); + assertThat(main.getLayout(), Is.is(DashboardLayout.TWO_COLUMNS)); + assertThat(main.getWidgets().size(), Is.is(11)); + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java new file mode 100644 index 00000000000..1057e9a5c96 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java @@ -0,0 +1,38 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 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.dashboards; + +import org.hamcrest.core.Is; +import org.junit.Test; +import org.sonar.api.web.dashboard.Dashboard; +import org.sonar.api.web.dashboard.DashboardLayout; + +import static org.junit.Assert.assertThat; + +public class HotspotsDashboardTest { + @Test + public void shouldCreateDashboard() { + Dashboard hotspots = new HotspotsDashboard().createDashboard(); + assertThat(hotspots.getId(), Is.is("hotspots")); + assertThat(hotspots.getName(), Is.is("Hotspots")); + assertThat(hotspots.getLayout(), Is.is(DashboardLayout.TWO_COLUMNS)); + assertThat(hotspots.getWidgets().size(), Is.is(8)); + } +} |