diff options
author | David Gageot <david@gageot.net> | 2012-05-25 08:45:45 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-05-25 08:59:32 +0200 |
commit | 7c03664400952bb5497e07a76e4d26bd9a22b7d3 (patch) | |
tree | a47ad18c0f5ae442020d75916baa5e3b9e9e6398 /plugins | |
parent | 5e86cfa298427f58bb8d342ed972f5c77a35c816 (diff) | |
download | sonarqube-7c03664400952bb5497e07a76e4d26bd9a22b7d3.tar.gz sonarqube-7c03664400952bb5497e07a76e4d26bd9a22b7d3.zip |
Create 'My Favourites' Dashboard through extension point.
The dashboard is created but not activated.
Diffstat (limited to 'plugins')
6 files changed, 161 insertions, 34 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 21f7e163bc6..b2d3748cff1 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,6 +19,8 @@ */ package org.sonar.plugins.core; +import org.sonar.plugins.core.dashboards.MyFavouritesDashboard; + import com.google.common.collect.Lists; import org.sonar.api.CoreProperties; import org.sonar.api.Extension; @@ -344,6 +346,7 @@ public final class CorePlugin extends SonarPlugin { extensions.add(TimeMachineDashboard.class); extensions.add(ProjectsDashboard.class); extensions.add(TreemapDashboard.class); + extensions.add(MyFavouritesDashboard.class); // chart extensions.add(XradarChart.class); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java new file mode 100644 index 00000000000..7f824f9745e --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java @@ -0,0 +1,50 @@ +/* + * 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; + +/** + * Base class for global dashboard containing a single + * filter widget. + * + * @since 3.1 + */ +abstract class AbstractFilterDashboard extends DashboardTemplate { + protected abstract String getFilterKey(); + + @Override + public Dashboard createDashboard() { + Dashboard dashboard = Dashboard.create() + .setGlobal(true) + .setLayout(DashboardLayout.ONE_COLUMN); + + Widget filterWidget = dashboard.addWidget("filter", 1) + .setProperty(FilterWidget.FILTER, getFilterKey()); + + return dashboard; + } +} diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboard.java new file mode 100644 index 00000000000..8e0e6582ba4 --- /dev/null +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboard.java @@ -0,0 +1,45 @@ +/* + * 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.api.web.Dashboard; +import org.sonar.plugins.core.filters.MyFavouritesFilter; + +/** + * My favorites global dashboard for Sonar + * + * @since 3.1 + */ +public final class MyFavouritesDashboard extends AbstractFilterDashboard { + @Override + public String getName() { + return "My Favourites"; + } + + @Override + protected String getFilterKey() { + return new MyFavouritesFilter().getName(); + } + + @Override + public Dashboard createDashboard() { + return super.createDashboard().setActivated(false); + } +}
\ No newline at end of file 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 index 3483cee4866..49fd4f3043a 100644 --- 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 @@ -19,34 +19,21 @@ */ 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; +import org.sonar.plugins.core.filters.ProjectFilter; /** * Projects global dashboard for Sonar * * @since 3.1 */ -public final class ProjectsDashboard extends DashboardTemplate { +public final class ProjectsDashboard extends AbstractFilterDashboard { @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; + protected String getFilterKey() { + return new ProjectFilter().getName(); } }
\ 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 index f782704c4eb..29bf58530bb 100644 --- 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 @@ -19,34 +19,21 @@ */ 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; +import org.sonar.plugins.core.filters.TreeMapFilter; /** * Treemap global dashboard for Sonar * * @since 3.1 */ -public final class TreemapDashboard extends DashboardTemplate { +public final class TreemapDashboard extends AbstractFilterDashboard { @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; + protected String getFilterKey() { + return new TreeMapFilter().getName(); } }
\ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboardTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboardTest.java new file mode 100644 index 00000000000..d3cd570b876 --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboardTest.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 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.CorePlugin; +import org.sonar.plugins.core.filters.MyFavouritesFilter; +import org.sonar.plugins.core.widgets.FilterWidget; + +import static org.fest.assertions.Assertions.assertThat; + +public class MyFavouritesDashboardTest { + MyFavouritesDashboard template = new MyFavouritesDashboard(); + + @Test + public void should_have_a_name() { + assertThat(template.getName()).isEqualTo("My Favourites"); + } + + @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(dashboard.isActivated()).isFalse(); + assertThat(widget.getId()).isEqualTo(new FilterWidget().getId()); + assertThat(widget.getProperty("filter")).isEqualTo(new MyFavouritesFilter().getName()); + } +} |