aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-05-24 08:22:55 +0200
committerDavid Gageot <david@gageot.net>2012-05-24 09:34:58 +0200
commitd9538939baa6cd86340505da1f4283ac12a94cb8 (patch)
tree1ded7ae835553cfcfbe21d5fc44b2a90722cef06 /plugins
parent764537e903cef07f68b0a0d97e6b925e19363170 (diff)
downloadsonarqube-d9538939baa6cd86340505da1f4283ac12a94cb8.tar.gz
sonarqube-d9538939baa6cd86340505da1f4283ac12a94cb8.zip
Create Projects and Treemap default dashboards using extension point
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java13
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectsDashboard.java52
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TreemapDashboard.java52
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/DefaultDashboardTest.java25
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/HotspotsDashboardTest.java27
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectsDashboardTest.java55
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java37
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TreemapDashboardTest.java55
9 files changed, 283 insertions, 36 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 c95ebe4777b..559927d6b0d 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
@@ -19,12 +19,6 @@
*/
package org.sonar.plugins.core;
-import org.sonar.plugins.core.filters.MyFavouritesFilter;
-
-import org.sonar.plugins.core.filters.TreeMapFilter;
-
-import org.sonar.plugins.core.filters.ProjectFilter;
-
import com.google.common.collect.Lists;
import org.sonar.api.CoreProperties;
import org.sonar.api.Extension;
@@ -44,8 +38,13 @@ import org.sonar.plugins.core.charts.XradarChart;
import org.sonar.plugins.core.colorizers.JavaColorizerFormat;
import org.sonar.plugins.core.dashboards.DefaultDashboard;
import org.sonar.plugins.core.dashboards.HotspotsDashboard;
+import org.sonar.plugins.core.dashboards.ProjectsDashboard;
import org.sonar.plugins.core.dashboards.ReviewsDashboard;
import org.sonar.plugins.core.dashboards.TimeMachineDashboard;
+import org.sonar.plugins.core.dashboards.TreemapDashboard;
+import org.sonar.plugins.core.filters.MyFavouritesFilter;
+import org.sonar.plugins.core.filters.ProjectFilter;
+import org.sonar.plugins.core.filters.TreeMapFilter;
import org.sonar.plugins.core.security.ApplyProjectRolesDecorator;
import org.sonar.plugins.core.sensors.BranchCoverageDecorator;
import org.sonar.plugins.core.sensors.CheckAlertThresholds;
@@ -341,6 +340,8 @@ public final class CorePlugin extends SonarPlugin {
extensions.add(HotspotsDashboard.class);
extensions.add(ReviewsDashboard.class);
extensions.add(TimeMachineDashboard.class);
+ extensions.add(ProjectsDashboard.class);
+ extensions.add(TreemapDashboard.class);
// chart
extensions.add(XradarChart.class);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectsDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectsDashboard.java
new file mode 100644
index 00000000000..3483cee4866
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectsDashboard.java
@@ -0,0 +1,52 @@
+/*
+ * 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.dashboards;
+
+import org.sonar.plugins.core.widgets.FilterWidget;
+
+import org.sonar.api.web.Dashboard.Widget;
+
+import org.sonar.api.web.Dashboard;
+import org.sonar.api.web.DashboardLayout;
+import org.sonar.api.web.DashboardTemplate;
+
+/**
+ * Projects global dashboard for Sonar
+ *
+ * @since 3.1
+ */
+public final class ProjectsDashboard extends DashboardTemplate {
+ @Override
+ public String getName() {
+ return "Projects";
+ }
+
+ @Override
+ public Dashboard createDashboard() {
+ Dashboard dashboard = Dashboard.create();
+ dashboard.setGlobal(true);
+ dashboard.setLayout(DashboardLayout.ONE_COLUMN);
+
+ Widget filterWidget = dashboard.addWidget("filter", 1);
+ filterWidget.setProperty(FilterWidget.FILTER, "Projects");
+
+ return dashboard;
+ }
+} \ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TreemapDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TreemapDashboard.java
new file mode 100644
index 00000000000..f782704c4eb
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TreemapDashboard.java
@@ -0,0 +1,52 @@
+/*
+ * 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.dashboards;
+
+import org.sonar.plugins.core.widgets.FilterWidget;
+
+import org.sonar.api.web.Dashboard.Widget;
+
+import org.sonar.api.web.Dashboard;
+import org.sonar.api.web.DashboardLayout;
+import org.sonar.api.web.DashboardTemplate;
+
+/**
+ * Treemap global dashboard for Sonar
+ *
+ * @since 3.1
+ */
+public final class TreemapDashboard extends DashboardTemplate {
+ @Override
+ public String getName() {
+ return "Treemap";
+ }
+
+ @Override
+ public Dashboard createDashboard() {
+ Dashboard dashboard = Dashboard.create();
+ dashboard.setGlobal(true);
+ dashboard.setLayout(DashboardLayout.ONE_COLUMN);
+
+ Widget filterWidget = dashboard.addWidget("filter", 1);
+ filterWidget.setProperty(FilterWidget.FILTER, "Treemap");
+
+ return dashboard;
+ }
+} \ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java
index 76beef5339f..bc10229498a 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java
@@ -32,9 +32,10 @@ import static org.sonar.api.web.WidgetScope.*;
@WidgetCategory({"Filters", "Global"})
@WidgetScope(GLOBAL)
@WidgetProperties({
- @WidgetProperty(key = "filter", type = WidgetPropertyType.FILTER, optional = false)
+ @WidgetProperty(key = FilterWidget.FILTER, type = WidgetPropertyType.FILTER, optional = false)
})
public class FilterWidget extends AbstractRubyTemplate implements RubyRailsWidget {
+ public static final String FILTER = "filter";
public String getId() {
return "filter";
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
index 5b92c98030e..7e13f5c4995 100644
--- 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
@@ -19,20 +19,31 @@
*/
package org.sonar.plugins.core.dashboards;
-import org.hamcrest.core.Is;
import org.junit.Test;
import org.sonar.api.web.Dashboard;
import org.sonar.api.web.DashboardLayout;
+import org.sonar.plugins.core.CorePlugin;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class DefaultDashboardTest {
+ DefaultDashboard template = new DefaultDashboard();
+
+ @Test
+ public void should_have_a_name() {
+ assertThat(template.getName()).isEqualTo("Dashboard");
+ }
+
@Test
- public void shouldCreateDashboard() {
- DefaultDashboard template = new DefaultDashboard();
+ public void should_be_registered_as_an_extension() {
+ assertThat(new CorePlugin().getExtensions()).contains(template.getClass());
+ }
+
+ @Test
+ public void should_create_dashboard() {
Dashboard dashboard = template.createDashboard();
- assertThat(template.getName(), Is.is("Dashboard"));
- assertThat(dashboard.getLayout(), Is.is(DashboardLayout.TWO_COLUMNS));
- assertThat(dashboard.getWidgets().size(), Is.is(11));
+
+ assertThat(dashboard.getLayout()).isEqualTo(DashboardLayout.TWO_COLUMNS);
+ assertThat(dashboard.getWidgets()).hasSize(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
index af6be55c7cb..58b6763d95e 100644
--- 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
@@ -19,20 +19,31 @@
*/
package org.sonar.plugins.core.dashboards;
-import org.hamcrest.core.Is;
import org.junit.Test;
import org.sonar.api.web.Dashboard;
import org.sonar.api.web.DashboardLayout;
+import org.sonar.plugins.core.CorePlugin;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
public class HotspotsDashboardTest {
+ HotspotsDashboard template = new HotspotsDashboard();
+
+ @Test
+ public void should_have_a_name() {
+ assertThat(template.getName()).isEqualTo("Hotspots");
+ }
+
@Test
- public void shouldCreateDashboard() {
- HotspotsDashboard template = new HotspotsDashboard();
- Dashboard hotspots = template.createDashboard();
- assertThat(template.getName(), Is.is("Hotspots"));
- assertThat(hotspots.getLayout(), Is.is(DashboardLayout.TWO_COLUMNS));
- assertThat(hotspots.getWidgets().size(), Is.is(8));
+ public void should_be_registered_as_an_extension() {
+ assertThat(new CorePlugin().getExtensions()).contains(template.getClass());
+ }
+
+ @Test
+ public void should_create_dashboard() {
+ Dashboard dashboard = template.createDashboard();
+
+ assertThat(dashboard.getLayout()).isEqualTo(DashboardLayout.TWO_COLUMNS);
+ assertThat(dashboard.getWidgets()).hasSize(8);
}
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectsDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectsDashboardTest.java
new file mode 100644
index 00000000000..613263b3434
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectsDashboardTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.dashboards;
+
+import org.sonar.plugins.core.CorePlugin;
+
+import com.google.common.collect.Iterables;
+import org.junit.Test;
+import org.sonar.api.web.Dashboard;
+import org.sonar.api.web.Dashboard.Widget;
+import org.sonar.plugins.core.filters.ProjectFilter;
+import org.sonar.plugins.core.widgets.FilterWidget;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ProjectsDashboardTest {
+ ProjectsDashboard template = new ProjectsDashboard();
+
+ @Test
+ public void should_have_a_name() {
+ assertThat(template.getName()).isEqualTo("Projects");
+ }
+
+ @Test
+ public void should_be_registered_as_an_extension() {
+ assertThat(new CorePlugin().getExtensions()).contains(template.getClass());
+ }
+
+ @Test
+ public void should_create_global_dashboard_with_one_filter() {
+ Dashboard dashboard = template.createDashboard();
+ Widget widget = Iterables.getOnlyElement(dashboard.getWidgets());
+
+ assertThat(dashboard.isGlobal()).isTrue();
+ assertThat(widget.getId()).isEqualTo(new FilterWidget().getId());
+ assertThat(widget.getProperty("filter")).isEqualTo(new ProjectFilter().getName());
+ }
+}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java
index 59463ce21f3..25fc1c29709 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TimeMachineDashboardTest.java
@@ -19,28 +19,37 @@
*/
package org.sonar.plugins.core.dashboards;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.Collection;
-
import org.junit.Test;
import org.sonar.api.web.Dashboard;
import org.sonar.api.web.Dashboard.Widget;
import org.sonar.api.web.DashboardLayout;
+import org.sonar.plugins.core.CorePlugin;
+
+import static org.fest.assertions.Assertions.assertThat;
public class TimeMachineDashboardTest {
+ TimeMachineDashboard template = new TimeMachineDashboard();
+
+ @Test
+ public void should_have_a_name() {
+ assertThat(template.getName()).isEqualTo("TimeMachine");
+ }
+
+ @Test
+ public void should_be_registered_as_an_extension() {
+ assertThat(new CorePlugin().getExtensions()).contains(template.getClass());
+ }
+
@Test
- public void shouldCreateDashboard() {
- TimeMachineDashboard template = new TimeMachineDashboard();
- Dashboard hotspots = template.createDashboard();
- assertThat(template.getName(), is("TimeMachine"));
- assertThat(hotspots.getLayout(), is(DashboardLayout.TWO_COLUMNS));
- Collection<Widget> widgets = hotspots.getWidgets();
- assertThat(widgets.size(), is(7));
- for (Widget widget : widgets) {
+ public void should_create_dashboard() {
+ Dashboard dashboard = template.createDashboard();
+
+ assertThat(dashboard.getLayout()).isEqualTo(DashboardLayout.TWO_COLUMNS);
+ assertThat(dashboard.getWidgets()).hasSize(7);
+
+ for (Widget widget : dashboard.getWidgets()) {
if (widget.getId().equals("time_machine")) {
- assertThat(widget.getProperty("displaySparkLine"), is("true"));
+ assertThat(widget.getProperty("displaySparkLine")).isEqualTo("true");
}
}
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TreemapDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TreemapDashboardTest.java
new file mode 100644
index 00000000000..44bc6c34b17
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TreemapDashboardTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.dashboards;
+
+import org.sonar.plugins.core.CorePlugin;
+
+import com.google.common.collect.Iterables;
+import org.junit.Test;
+import org.sonar.api.web.Dashboard;
+import org.sonar.api.web.Dashboard.Widget;
+import org.sonar.plugins.core.filters.TreeMapFilter;
+import org.sonar.plugins.core.widgets.FilterWidget;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class TreemapDashboardTest {
+ TreemapDashboard template = new TreemapDashboard();
+
+ @Test
+ public void should_have_a_name() {
+ assertThat(template.getName()).isEqualTo("Treemap");
+ }
+
+ @Test
+ public void should_be_registered_as_an_extension() {
+ assertThat(new CorePlugin().getExtensions()).contains(template.getClass());
+ }
+
+ @Test
+ public void should_create_dashboard() {
+ Dashboard dashboard = template.createDashboard();
+ Widget widget = Iterables.getOnlyElement(dashboard.getWidgets());
+
+ assertThat(dashboard.isGlobal()).isTrue();
+ assertThat(widget.getId()).isEqualTo(new FilterWidget().getId());
+ assertThat(widget.getProperty("filter")).isEqualTo(new TreeMapFilter().getName());
+ }
+}