From 2f66634a7ab0cff2eb20f7b32347a35174075334 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 25 May 2012 22:47:42 +0200 Subject: [PATCH] Cleaner code and fix warnings --- .../dashboards/AbstractFilterDashboard.java | 9 ++++--- .../core/dashboards/ProjectsDashboard.java | 2 +- .../core/dashboards/ReviewsDashboard.java | 1 - .../core/dashboards/TreemapDashboard.java | 2 +- .../core/filters/MyFavouritesFilter.java | 19 +++++++------- .../plugins/core/filters/ProjectFilter.java | 26 +++++++++---------- .../plugins/core/filters/TreeMapFilter.java | 18 ++++++------- .../plugins/core/widgets/FilterWidget.java | 4 +-- .../dashboards/MyFavouritesDashboardTest.java | 6 ++--- .../dashboards/ProjectsDashboardTest.java | 9 +++---- .../core/dashboards/TreemapDashboardTest.java | 9 +++---- .../review/workflow/ReviewDatabaseStore.java | 2 -- .../core/review/workflow/ReviewStore.java | 2 -- .../core/review/workflow/WorkflowEngine.java | 3 +-- .../workflow/ReviewDatabaseStoreTest.java | 2 -- .../java/org/sonar/server/ui/JRubyFacade.java | 1 - 16 files changed, 50 insertions(+), 65 deletions(-) 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 index 7d4d2d25ed0..ca0429a80ca 100644 --- 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 @@ -31,8 +31,6 @@ import org.sonar.plugins.core.widgets.FilterWidget; * @since 3.1 */ abstract class AbstractFilterDashboard extends DashboardTemplate { - protected abstract String getFilterKey(); - @Override public final Dashboard createDashboard() { Dashboard dashboard = Dashboard.create() @@ -48,7 +46,12 @@ abstract class AbstractFilterDashboard extends DashboardTemplate { } /** - * Override this method to complete dashboard + * The key of the filter to display. + */ + protected abstract String getFilterKey(); + + /** + * Override this method to complete dashboard. */ protected void doCompleteDashboard(Dashboard dashboard) { } 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 49fd4f3043a..290a5772888 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 @@ -34,6 +34,6 @@ public final class ProjectsDashboard extends AbstractFilterDashboard { @Override protected String getFilterKey() { - return new ProjectFilter().getName(); + return ProjectFilter.NAME; } } \ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ReviewsDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ReviewsDashboard.java index 41767da7d5f..96e052a91af 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ReviewsDashboard.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ReviewsDashboard.java @@ -29,7 +29,6 @@ import org.sonar.api.web.DashboardTemplate; * @since 2.14 */ public final class ReviewsDashboard extends DashboardTemplate { - @Override public String getName() { return "Reviews"; 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 29bf58530bb..0a8072901c5 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 @@ -34,6 +34,6 @@ public final class TreemapDashboard extends AbstractFilterDashboard { @Override protected String getFilterKey() { - return new TreeMapFilter().getName(); + return TreeMapFilter.NAME; } } \ No newline at end of file diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java index 32fd31d0373..a7a6125b68f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java @@ -40,15 +40,14 @@ public class MyFavouritesFilter extends FilterTemplate { @Override public Filter createFilter() { - Filter filter = Filter.create(); - filter.setDisplayAs(Filter.LIST); - filter.setFavouritesOnly(true); - filter.add(Criterion.createForQualifier("VW", "SVW", "TRK", "BRC", "DIR", "PAC", "FIL", "CLA", "UTS")); - filter.add(FilterColumn.create("metric", CoreMetrics.ALERT_STATUS_KEY, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("name", null, FilterColumn.ASC, false)); - filter.add(FilterColumn.create("metric", CoreMetrics.NCLOC_KEY, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("metric", CoreMetrics.VIOLATIONS_DENSITY_KEY, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("date", null, FilterColumn.DESC, false)); - return filter; + return Filter.create() + .setDisplayAs(Filter.LIST) + .setFavouritesOnly(true) + .add(Criterion.createForQualifier("VW", "SVW", "TRK", "BRC", "DIR", "PAC", "FIL", "CLA", "UTS")) + .add(FilterColumn.create("metric", CoreMetrics.ALERT_STATUS_KEY, FilterColumn.DESC, false)) + .add(FilterColumn.create("name", null, FilterColumn.ASC, false)) + .add(FilterColumn.create("metric", CoreMetrics.NCLOC_KEY, FilterColumn.DESC, false)) + .add(FilterColumn.create("metric", CoreMetrics.VIOLATIONS_DENSITY_KEY, FilterColumn.DESC, false)) + .add(FilterColumn.create("date", null, FilterColumn.DESC, false)); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java index c9e635881d9..50f387f7bf0 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java @@ -32,24 +32,24 @@ import org.sonar.api.web.FilterTemplate; * @since 3.1 */ public class ProjectFilter extends FilterTemplate { + public static final String NAME = "Projects"; + @Override public String getName() { - return "Projects"; + return NAME; } @Override public Filter createFilter() { - Filter filter = Filter.create(); - filter.setDisplayAs(Filter.LIST); - filter.add(Criterion.createForQualifier(Qualifiers.PROJECT)); - filter.add(FilterColumn.create("metric", CoreMetrics.ALERT_STATUS_KEY, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("name", null, FilterColumn.ASC, false)); - filter.add(FilterColumn.create("version", null, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("metric", CoreMetrics.NCLOC_KEY, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("metric", CoreMetrics.VIOLATIONS_DENSITY_KEY, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("date", null, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("links", null, FilterColumn.DESC, false)); - - return filter; + return Filter.create() + .setDisplayAs(Filter.LIST) + .add(Criterion.createForQualifier(Qualifiers.PROJECT)) + .add(FilterColumn.create("metric", CoreMetrics.ALERT_STATUS_KEY, FilterColumn.DESC, false)) + .add(FilterColumn.create("name", null, FilterColumn.ASC, false)) + .add(FilterColumn.create("version", null, FilterColumn.DESC, false)) + .add(FilterColumn.create("metric", CoreMetrics.NCLOC_KEY, FilterColumn.DESC, false)) + .add(FilterColumn.create("metric", CoreMetrics.VIOLATIONS_DENSITY_KEY, FilterColumn.DESC, false)) + .add(FilterColumn.create("date", null, FilterColumn.DESC, false)) + .add(FilterColumn.create("links", null, FilterColumn.DESC, false)); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java index 985bb434b65..2f84341e5bb 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java @@ -32,20 +32,20 @@ import org.sonar.api.web.FilterTemplate; * @since 3.1 */ public class TreeMapFilter extends FilterTemplate { + public static final String NAME = "Treemap"; + @Override public String getName() { - return "Treemap"; + return NAME; } @Override public Filter createFilter() { - Filter filter = Filter.create(); - filter.setDisplayAs(Filter.TREEMAP); - filter.add(Criterion.createForQualifier(Qualifiers.PROJECT)); - filter.add(FilterColumn.create("name", null, FilterColumn.ASC, false)); - filter.add(FilterColumn.create("metric", CoreMetrics.NCLOC_KEY, FilterColumn.DESC, false)); - filter.add(FilterColumn.create("metric", CoreMetrics.VIOLATIONS_DENSITY_KEY, FilterColumn.DESC, false)); - - return filter; + return Filter.create() + .setDisplayAs(Filter.TREEMAP) + .add(Criterion.createForQualifier(Qualifiers.PROJECT)) + .add(FilterColumn.create("name", null, FilterColumn.ASC, false)) + .add(FilterColumn.create("metric", CoreMetrics.NCLOC_KEY, FilterColumn.DESC, false)) + .add(FilterColumn.create("metric", CoreMetrics.VIOLATIONS_DENSITY_KEY, FilterColumn.DESC, false)); } } 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 bc10229498a..f623da2ab5e 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 @@ -31,9 +31,9 @@ import static org.sonar.api.web.WidgetScope.*; @WidgetCategory({"Filters", "Global"}) @WidgetScope(GLOBAL) -@WidgetProperties({ +@WidgetProperties( @WidgetProperty(key = FilterWidget.FILTER, type = WidgetPropertyType.FILTER, optional = false) -}) +) public class FilterWidget extends AbstractRubyTemplate implements RubyRailsWidget { public static final String FILTER = "filter"; 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 index 9955cbe9be9..adb279cc125 100644 --- 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 @@ -24,8 +24,6 @@ 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; @@ -49,7 +47,7 @@ public class MyFavouritesDashboardTest { assertThat(dashboard.isGlobal()).isTrue(); assertThat(dashboard.isActivated()).isFalse(); - assertThat(widget.getId()).isEqualTo(new FilterWidget().getId()); - assertThat(widget.getProperty("filter")).isEqualTo(new MyFavouritesFilter().getName()); + assertThat(widget.getId()).isEqualTo("filter"); + assertThat(widget.getProperty("filter")).isEqualTo("My favourites"); } } 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 index 613263b3434..bfff5d5ea1f 100644 --- 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 @@ -19,14 +19,11 @@ */ 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 org.sonar.plugins.core.CorePlugin; import static org.fest.assertions.Assertions.assertThat; @@ -49,7 +46,7 @@ public class ProjectsDashboardTest { 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()); + assertThat(widget.getId()).isEqualTo("filter"); + assertThat(widget.getProperty("filter")).isEqualTo("Projects"); } } 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 index 44bc6c34b17..3d164d6e79b 100644 --- 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 @@ -19,14 +19,11 @@ */ 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 org.sonar.plugins.core.CorePlugin; import static org.fest.assertions.Assertions.assertThat; @@ -49,7 +46,7 @@ public class TreemapDashboardTest { 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()); + assertThat(widget.getId()).isEqualTo("filter"); + assertThat(widget.getProperty("filter")).isEqualTo("Treemap"); } } diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewDatabaseStore.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewDatabaseStore.java index b48ea94bf5f..9dd425e38bc 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewDatabaseStore.java +++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewDatabaseStore.java @@ -35,8 +35,6 @@ import org.sonar.core.review.ReviewDto; import org.sonar.core.review.ReviewMapper; import org.sonar.core.review.workflow.review.Comment; import org.sonar.core.review.workflow.review.DefaultReview; -import org.sonar.core.review.workflow.review.MutableReview; - import java.util.Date; import java.util.List; diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewStore.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewStore.java index 22a298e1ed1..36540973903 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewStore.java +++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewStore.java @@ -21,8 +21,6 @@ package org.sonar.core.review.workflow; import org.sonar.api.config.Settings; import org.sonar.core.review.workflow.review.DefaultReview; -import org.sonar.core.review.workflow.review.MutableReview; - import java.util.List; public interface ReviewStore { diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/WorkflowEngine.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/WorkflowEngine.java index 22e821cf508..a73d42cadf1 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/workflow/WorkflowEngine.java +++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/WorkflowEngine.java @@ -31,7 +31,6 @@ import org.sonar.core.review.workflow.condition.Condition; import org.sonar.core.review.workflow.function.Function; import org.sonar.core.review.workflow.review.DefaultReview; import org.sonar.core.review.workflow.review.DefaultWorkflowContext; -import org.sonar.core.review.workflow.review.MutableReview; import org.sonar.core.review.workflow.review.Review; import org.sonar.core.review.workflow.review.WorkflowContext; import org.sonar.core.review.workflow.screen.Screen; @@ -105,7 +104,7 @@ public class WorkflowEngine implements ServerComponent { Map immutableParameters = ImmutableMap.copyOf(parameters); // TODO execute functions are change state before functions that consume state (like "create-jira-issue") - Review initialReview = ((DefaultReview) review).cloneImmutable(); + Review initialReview = review.cloneImmutable(); for (Function function : workflow.getFunctions(commandKey)) { function.doExecute(review, initialReview, context, immutableParameters); } diff --git a/sonar-core/src/test/java/org/sonar/core/review/workflow/ReviewDatabaseStoreTest.java b/sonar-core/src/test/java/org/sonar/core/review/workflow/ReviewDatabaseStoreTest.java index 99eae6f7330..0dbfa6a6d3b 100644 --- a/sonar-core/src/test/java/org/sonar/core/review/workflow/ReviewDatabaseStoreTest.java +++ b/sonar-core/src/test/java/org/sonar/core/review/workflow/ReviewDatabaseStoreTest.java @@ -24,8 +24,6 @@ import org.sonar.api.utils.DateUtils; import org.sonar.core.persistence.DaoTestCase; import org.sonar.core.review.workflow.review.Comment; import org.sonar.core.review.workflow.review.DefaultReview; -import org.sonar.core.review.workflow.review.MutableReview; - import java.util.Date; public class ReviewDatabaseStoreTest extends DaoTestCase { diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index d5c066d5576..b639339f1bf 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -46,7 +46,6 @@ import org.sonar.core.resource.ResourceIndexerDao; import org.sonar.core.review.workflow.WorkflowEngine; import org.sonar.core.review.workflow.review.DefaultReview; import org.sonar.core.review.workflow.review.DefaultWorkflowContext; -import org.sonar.core.review.workflow.review.MutableReview; import org.sonar.core.review.workflow.review.Review; import org.sonar.core.review.workflow.screen.Screen; import org.sonar.markdown.Markdown; -- 2.39.5