]> source.dussan.org Git - sonarqube.git/commitdiff
Cleaner code and fix warnings
authorDavid Gageot <david@gageot.net>
Fri, 25 May 2012 20:47:42 +0000 (22:47 +0200)
committerDavid Gageot <david@gageot.net>
Fri, 25 May 2012 20:47:42 +0000 (22:47 +0200)
16 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/AbstractFilterDashboard.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectsDashboard.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ReviewsDashboard.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/TreemapDashboard.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/MyFavouritesFilter.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/ProjectFilter.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/filters/TreeMapFilter.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/FilterWidget.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/MyFavouritesDashboardTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/ProjectsDashboardTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/dashboards/TreemapDashboardTest.java
sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewDatabaseStore.java
sonar-core/src/main/java/org/sonar/core/review/workflow/ReviewStore.java
sonar-core/src/main/java/org/sonar/core/review/workflow/WorkflowEngine.java
sonar-core/src/test/java/org/sonar/core/review/workflow/ReviewDatabaseStoreTest.java
sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java

index 7d4d2d25ed0241e355d1a3ec622e8a84b7eb3841..ca0429a80ca7585a34fa7747486a5a589d2d3c12 100644 (file)
@@ -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) {
   }
index 49fd4f3043a93963d4a8975738b2983ffd2c5d54..290a57728881ea9abbeeb4107f2970a6e3097520 100644 (file)
@@ -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
index 41767da7d5ffec022246590322d201c8ddbfbd91..96e052a91af28be8e3c2f584b617d09498ff4f90 100644 (file)
@@ -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";
index 29bf58530bba89ad2a1df4e050703fe74fbf6da5..0a8072901c58e943345ee8efe67b66af98acd9ed 100644 (file)
@@ -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
index 32fd31d0373aacf349aa664adeeb02fd8a0e668b..a7a6125b68f1b981b472b380e122ceb97e12d8e7 100644 (file)
@@ -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));
   }
 }
index c9e635881d9a9517327b08d941c9ecf1c48c07ef..50f387f7bf0d1757516b0ae88d75739300fe9085 100644 (file)
@@ -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));
   }
 }
index 985bb434b653469743dd59ed52d9d30857ad9789..2f84341e5bbd7b206711b5942b72ebbfb85669e9 100644 (file)
@@ -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));
   }
 }
index bc10229498a5b74b1d708360236638929b570ed1..f623da2ab5ec0d22e9f4d911a2d7bd65081f835e 100644 (file)
@@ -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";
 
index 9955cbe9be9e1cb56a58d43a7b2b4d2bb8db1789..adb279cc1259ac44c8e15e9b6d269e5cfb9b3cbe 100644 (file)
@@ -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");
   }
 }
index 613263b3434adcc5207a5132da4d6098fbf47254..bfff5d5ea1fc54538c8b680e502e7983ce5ff022 100644 (file)
  */
 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");
   }
 }
index 44bc6c34b17a17a02b1abb209d32884678081f52..3d164d6e79bc55aca6c7a62c7ac86e4d7461cb6c 100644 (file)
  */
 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");
   }
 }
index b48ea94bf5f2fd13991cde25ff476369ea5210c0..9dd425e38bc0804b4b018ef64a21b5fa98f1b5f9 100644 (file)
@@ -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;
 
index 22a298e1ed1fcc9b307095168458996682126ada..36540973903270b17b2d553a4ba7067e8c079f8a 100644 (file)
@@ -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 {
index 22e821cf5080a7da66b048d1901ec82d68f11eca..a73d42cadf13eb9f9cb95f12047dd300b08d3c7b 100644 (file)
@@ -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<String, String> 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);
     }
index 99eae6f733057a014d5da911c0ba74e0078d92a4..0dbfa6a6d3ba410c8af18eb65231fa4e06ba32c4 100644 (file)
@@ -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 {
index d5c066d557674c90f7cd16656a67f7c440c93a8b..b639339f1bf07a303a6625426c3d0659a6ecc767 100644 (file)
@@ -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;