]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 31 Aug 2015 13:44:53 +0000 (15:44 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 31 Aug 2015 13:44:53 +0000 (15:44 +0200)
17 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/issue/CloseIssuesOnRemovedComponentsVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/FeedMeasureComputers.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsJsonWriter.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java
server/sonar-server/src/main/java/org/sonar/server/issue/AssignAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/CommentAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeQuery.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java
server/sonar-server/src/main/java/org/sonar/server/issue/PlanAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/SetSeverityAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/TransitionAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/filter/IssueFilterParameters.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/ShowAction.java
server/sonar-server/src/main/java/org/sonar/server/platform/Platform.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java
server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java

index 87075b4b47e43ccfc86e109bb1bb63084a1a0968..7197df5481a77e8679558633e6e31cc7bd4850a6 100644 (file)
@@ -40,7 +40,8 @@ public class CloseIssuesOnRemovedComponentsVisitor extends TypeAwareVisitorAdapt
   private final IssueCache issueCache;
   private final IssueLifecycle issueLifecycle;
 
-  public CloseIssuesOnRemovedComponentsVisitor(BaseIssuesLoader baseIssuesLoader, ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues, IssueCache issueCache, IssueLifecycle issueLifecycle) {
+  public CloseIssuesOnRemovedComponentsVisitor(BaseIssuesLoader baseIssuesLoader, ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues, IssueCache issueCache,
+    IssueLifecycle issueLifecycle) {
     super(CrawlerDepthLimit.PROJECT, POST_ORDER);
     this.baseIssuesLoader = baseIssuesLoader;
     this.componentsWithUnprocessedIssues = componentsWithUnprocessedIssues;
index b5623facd0c59b5f7c7221217be9476b9b2b48bd..48dc14cbf1e4916c43340fbce2eb10a26cbeda11 100644 (file)
@@ -87,14 +87,7 @@ public class FeedMeasureComputers implements ComputationStep {
   private static Iterable<MeasureComputer> sortComputers(List<MeasureComputer> computers) {
     Map<String, MeasureComputer> computersByOutputMetric = new HashMap<>();
     Map<String, MeasureComputer> computersByInputMetric = new HashMap<>();
-    for (MeasureComputer computer : computers) {
-      for (String outputMetric : computer.getOutputMetrics()) {
-        computersByOutputMetric.put(outputMetric, computer);
-      }
-      for (String inputMetric : computer.getInputMetrics()) {
-        computersByInputMetric.put(inputMetric, computer);
-      }
-    }
+    feedComputersByMetric(computers, computersByOutputMetric, computersByInputMetric);
     ToComputerByKey toComputerByOutputMetricKey = new ToComputerByKey(computersByOutputMetric);
     ToComputerByKey toComputerByInputMetricKey = new ToComputerByKey(computersByInputMetric);
 
@@ -111,6 +104,18 @@ public class FeedMeasureComputers implements ComputationStep {
     return dag.sort();
   }
 
+  private static void feedComputersByMetric(List<MeasureComputer> computers, Map<String, MeasureComputer> computersByOutputMetric,
+    Map<String, MeasureComputer> computersByInputMetric) {
+    for (MeasureComputer computer : computers) {
+      for (String outputMetric : computer.getOutputMetrics()) {
+        computersByOutputMetric.put(outputMetric, computer);
+      }
+      for (String inputMetric : computer.getInputMetrics()) {
+        computersByInputMetric.put(inputMetric, computer);
+      }
+    }
+  }
+
   private void validateInputMetrics(List<MeasureComputer> computers) {
     Set<String> pluginMetricKeys = FluentIterable.from(Arrays.asList(metricsRepositories))
       .transformAndConcat(MetricsToMetricList.INSTANCE)
@@ -126,7 +131,7 @@ public class FeedMeasureComputers implements ComputationStep {
     }
   }
 
-  private static Iterable<MeasureComputer> getDependencies(MeasureComputer measureComputer,  ToComputerByKey toComputerByOutputMetricKey) {
+  private static Iterable<MeasureComputer> getDependencies(MeasureComputer measureComputer, ToComputerByKey toComputerByOutputMetricKey) {
     // Remove null computer because a computer can depend on a metric that is only generated by a sensor or on a core metrics
     return FluentIterable.from(measureComputer.getInputMetrics()).transform(toComputerByOutputMetricKey).filter(Predicates.notNull());
   }
index 1c15677a3021504b0ddedf1daaeda58d1cc71be8..7bf7d1ecad884fde4b616f37774725897528e9c0 100644 (file)
@@ -57,7 +57,7 @@ public class DuplicationsJsonWriter {
   private static void writeDuplications(List<DuplicationsParser.Block> blocks, Map<String, String> refByComponentKey, JsonWriter json) {
     for (DuplicationsParser.Block block : blocks) {
       json.beginObject().name("blocks").beginArray();
-      for (DuplicationsParser.Duplication duplication : block.duplications()) {
+      for (DuplicationsParser.Duplication duplication : block.getDuplications()) {
         writeDuplication(refByComponentKey, duplication, json);
       }
       json.endArray().endObject();
index c9e21ccbb40b66192ae0cd00c6b5dbc68d6eae52..5cb81834ccea3311aa9ca715169715a8955648c6 100644 (file)
@@ -157,8 +157,8 @@ public class DuplicationsParser {
       if (b1 == null || b2 == null) {
         return -1;
       }
-      List<Duplication> duplications1 = b1.duplications();
-      List<Duplication> duplications2 = b2.duplications();
+      List<Duplication> duplications1 = b1.getDuplications();
+      List<Duplication> duplications2 = b2.getDuplications();
       if (duplications1.isEmpty() || duplications2.isEmpty()) {
         return -1;
       }
@@ -194,14 +194,14 @@ public class DuplicationsParser {
     }
   }
 
-  public static class Block {
-    List<Duplication> duplications;
+  static class Block {
+    private final List<Duplication> duplications;
 
-    Block(List<Duplication> duplications) {
+    public Block(List<Duplication> duplications) {
       this.duplications = duplications;
     }
 
-    List<Duplication> duplications() {
+    public List<Duplication> getDuplications() {
       return duplications;
     }
   }
index 41e8b91708c6aa3f7acb4ea62a7ca649a6c0716e..e46ce835c0250b53d3901f6c1433e9616d2ced70 100644 (file)
 package org.sonar.server.issue;
 
 import com.google.common.base.Strings;
-import org.sonar.api.server.ServerSide;
+import java.util.Collection;
+import java.util.Map;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.condition.IsUnResolved;
-import org.sonar.core.issue.DefaultIssue;
+import org.sonar.api.server.ServerSide;
 import org.sonar.api.user.User;
 import org.sonar.api.user.UserFinder;
+import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.IssueUpdater;
 import org.sonar.server.user.UserSession;
 
-import java.util.Collection;
-import java.util.Map;
-
 @ServerSide
 public class AssignAction extends Action {
 
-  public static final String KEY = "assign";
+  private static final String ASSIGN_KEY = "assign";
   public static final String VERIFIED_ASSIGNEE = "verifiedAssignee";
 
   private final UserFinder userFinder;
   private final IssueUpdater issueUpdater;
 
   public AssignAction(UserFinder userFinder, IssueUpdater issueUpdater) {
-    super(KEY);
+    super(ASSIGN_KEY);
     this.userFinder = userFinder;
     this.issueUpdater = issueUpdater;
     super.setConditions(new IsUnResolved());
index d37a746aff9691b827f4b6391321008ba2498075..8a0dda0a888f14b6171c30785246445f6ee9bc96 100644 (file)
@@ -24,21 +24,21 @@ import com.google.common.base.Strings;
 import java.util.Collection;
 import java.util.Map;
 import org.sonar.api.issue.Issue;
-import org.sonar.core.issue.DefaultIssue;
 import org.sonar.api.server.ServerSide;
+import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.IssueUpdater;
 import org.sonar.server.user.UserSession;
 
 @ServerSide
 public class CommentAction extends Action {
 
-  public static final String KEY = "comment";
+  public static final String COMMENT_KEY = "comment";
   public static final String COMMENT_PROPERTY = "comment";
 
   private final IssueUpdater issueUpdater;
 
   public CommentAction(IssueUpdater issueUpdater) {
-    super(KEY);
+    super(COMMENT_KEY);
     this.issueUpdater = issueUpdater;
   }
 
index 5acaa1eeb8bbb8c6d9a44caef0c2e6b44ec1f91b..3a6574212451ede61f3bcdd4abc41c52d8a1903a 100644 (file)
@@ -77,7 +77,7 @@ public class IssueBulkChangeQuery {
       hasComment = true;
       Map<String, Object> commentMap = newHashMap();
       commentMap.put(CommentAction.COMMENT_PROPERTY, comment);
-      propertiesByActions.put(CommentAction.KEY, commentMap);
+      propertiesByActions.put(CommentAction.COMMENT_KEY, commentMap);
     }
   }
 
index 3c46a956130f6edf9b3d5a2ca58e5962076ca201..28b7abcb210ecdaa6a87ca9099b090171e5f8ffa 100644 (file)
@@ -103,7 +103,7 @@ public class IssueBulkChangeService {
       if (result.issuesChanged().contains(issue)) {
         // Apply comment action only on changed issues
         if (issueBulkChangeQuery.hasComment()) {
-          applyAction(getAction(CommentAction.KEY), actionContext, issueBulkChangeQuery, result);
+          applyAction(getAction(CommentAction.COMMENT_KEY), actionContext, issueBulkChangeQuery, result);
         }
         issueStorage.save((DefaultIssue) issue);
         if (issueBulkChangeQuery.sendNotifications()) {
index bf2993a12e27f0f960509d26b75de03da7cb3c53..5862fe065970e6293146d3da96e19e5cc0477a4c 100644 (file)
 package org.sonar.server.issue;
 
 import com.google.common.base.Strings;
-import org.sonar.api.server.ServerSide;
+import java.util.Collection;
+import java.util.Map;
 import org.sonar.api.issue.ActionPlan;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.condition.IsUnResolved;
+import org.sonar.api.server.ServerSide;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.IssueUpdater;
 import org.sonar.server.issue.actionplan.ActionPlanService;
 import org.sonar.server.user.UserSession;
 
-import java.util.Collection;
-import java.util.Map;
-
 @ServerSide
 public class PlanAction extends Action {
 
-  public static final String KEY = "plan";
+  public static final String PLAN_KEY = "plan";
   public static final String VERIFIED_ACTION_PLAN = "verifiedActionPlan";
 
   private final ActionPlanService actionPlanService;
   private final IssueUpdater issueUpdater;
 
   public PlanAction(ActionPlanService actionPlanService, IssueUpdater issueUpdater) {
-    super(KEY);
+    super(PLAN_KEY);
     this.actionPlanService = actionPlanService;
     this.issueUpdater = issueUpdater;
     super.setConditions(new IsUnResolved());
index 6c75b9c1f0154366a261fe52c990ee1ab4ab739b..bdda3c2ff2b6d9e1156c665751ee189021b9a21d 100644 (file)
@@ -26,22 +26,22 @@ import java.util.Map;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.condition.Condition;
 import org.sonar.api.issue.condition.IsUnResolved;
-import org.sonar.core.issue.DefaultIssue;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.web.UserRole;
+import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.IssueUpdater;
 import org.sonar.server.user.UserSession;
 
 @ServerSide
 public class SetSeverityAction extends Action {
 
-  public static final String KEY = "set_severity";
+  public static final String SET_SEVERITY_KEY = "set_severity";
 
   private final IssueUpdater issueUpdater;
   private final UserSession userSession;
 
   public SetSeverityAction(IssueUpdater issueUpdater, UserSession userSession) {
-    super(KEY);
+    super(SET_SEVERITY_KEY);
     this.issueUpdater = issueUpdater;
     this.userSession = userSession;
     super.setConditions(new IsUnResolved(), new Condition() {
index 1f4c4b283ed675b7b275c8715a8c90a57e4abdcf..dd4e79f1419d4c40b0d94b977c4247ada9a4054c 100644 (file)
@@ -27,8 +27,8 @@ import java.util.Collection;
 import java.util.Map;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.issue.Issue;
-import org.sonar.core.issue.DefaultIssue;
 import org.sonar.api.server.ServerSide;
+import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.workflow.IssueWorkflow;
 import org.sonar.core.issue.workflow.Transition;
 import org.sonar.server.user.UserSession;
@@ -36,13 +36,13 @@ import org.sonar.server.user.UserSession;
 @ServerSide
 public class TransitionAction extends Action {
 
-  public static final String KEY = "do_transition";
+  public static final String DO_TRANSITION_KEY = "do_transition";
 
   private final IssueWorkflow workflow;
   private final UserSession userSession;
 
   public TransitionAction(IssueWorkflow workflow, UserSession userSession) {
-    super(KEY);
+    super(DO_TRANSITION_KEY);
     this.workflow = workflow;
     this.userSession = userSession;
   }
index 3f1b221d4ec93382c1f6299b89257d89457195e5..8c552eb2c88b250103489f8def07c60ad826fe3e 100644 (file)
@@ -79,7 +79,7 @@ public class IssueFilterParameters {
     ASSIGNEES, LANGUAGES, ASSIGNED, PLANNED, HIDE_RULES, CREATED_AT, CREATED_AFTER, CREATED_BEFORE, CREATED_IN_LAST, COMPONENT_UUIDS, COMPONENT_ROOT_UUIDS, FACET_MODE,
     PROJECTS, PROJECT_UUIDS, PROJECT_KEYS, COMPONENT_KEYS, MODULE_UUIDS, DIRECTORIES, FILE_UUIDS, AUTHORS, HIDE_COMMENTS, PAGE_SIZE, PAGE_INDEX, SORT, ASC);
 
-  public static final List<String> ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate<String>() {
+  static final List<String> ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate<String>() {
     @Override
     public boolean apply(String input) {
       return !PAGE_INDEX.equals(input) && !PAGE_SIZE.equals(input);
index 5487d2ee999e98183bab92a5711e34d19223f39f..520da52f09766e7151d07f1f8f897dd8e3661881 100644 (file)
@@ -211,11 +211,6 @@ public class ShowAction implements IssuesWsAction {
           usersByLogin.put(userLogin, user);
         }
       }
-    }
-
-    for (IssueComment comment : comments) {
-      String userLogin = comment.userLogin();
-      User user = usersByLogin.get(userLogin);
       json
         .beginObject()
         .prop("key", comment.key())
index fc5f931464b38fd50a292f124fd00f87f53004fa..0740f9aa85971a861204baa7c9de3d0bf298a9bf 100644 (file)
@@ -61,9 +61,6 @@ public class Platform {
   private final List<Object> level4AddedComponents = Lists.newArrayList();
   private final Profiler profiler = Profiler.createIfTrace(Loggers.get(Platform.class));
 
-  public Platform() {
-  }
-
   public static Platform getInstance() {
     return INSTANCE;
   }
index 97a54e9aa5175054c55ded5eac9fa63edfa90d31..302cc4ed8b537355eca657fc0a5292d52a9a0428 100644 (file)
@@ -26,7 +26,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-import org.junit.rules.TemporaryFolder;
 import org.sonar.api.resources.Language;
 import org.sonar.api.utils.System2;
 import org.sonar.batch.protocol.Constants;
@@ -69,9 +68,6 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
   @Rule
   public BatchReportReaderRule reportReader = new BatchReportReaderRule();
 
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
-
   DbClient dbClient = dbTester.getDbClient();
   PersistFileSourcesStep underTest;
 
index f463fce9693e58e5d16a5c136219baff99125db3..177e57ff19eefd674043f4bd20470ebf1fd29bc5 100644 (file)
 package org.sonar.server.debt;
 
 import com.google.common.io.Resources;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
 import org.apache.commons.lang.CharUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.custommonkey.xmlunit.Diff;
@@ -30,11 +34,6 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
 
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Pattern;
-
 import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertTrue;
@@ -91,12 +90,12 @@ public class DebtModelXMLExporterTest {
     String xml = xmlExporter.export(debtModel, Collections.<RuleDebt>emptyList());
 
     // root characteristics are sorted by the column "characteristic_order"
-    Pattern regex = Pattern.compile(".*USABILITY.*PORTABILITY.*EFFICIENCY.*", Pattern.DOTALL);
-    assertThat(regex.matcher(xml).matches());
+    assertThat(Pattern.compile(".*PORTABILITY.*USABILITY.*EFFICIENCY.*", Pattern.DOTALL).matcher(xml).matches()).isTrue();
+    assertThat(Pattern.compile(".*USABILITY.*PORTABILITY.*EFFICIENCY.*", Pattern.DOTALL).matcher(xml).matches()).isFalse();
 
     // sub characteristics are sorted by name
-    regex = Pattern.compile(".*CPU Efficiency.*Other Efficiency.*RAM Efficiency.*", Pattern.DOTALL);
-    assertThat(regex.matcher(xml).matches());
+    assertThat(Pattern.compile(".*CPU Efficiency.*Other Efficiency.*RAM Efficiency.*", Pattern.DOTALL).matcher(xml).matches()).isTrue();
+    assertThat(Pattern.compile(".*CPU Efficiency.*RAM Efficiency.*Other Efficiency.*", Pattern.DOTALL).matcher(xml).matches()).isFalse();
   }
 
   @Test
index 06cfbbf8b8201606f78a310c620bc8fe64a0c568..b0791d59c42d862d3732f541beb08084b1912f7b 100644 (file)
@@ -98,7 +98,7 @@ public class DuplicationsParserTest {
     List<DuplicationsParser.Block> blocks = parser.parse(currentFile, getData("duplication_on_same_file.xml"), session);
     assertThat(blocks).hasSize(1);
 
-    List<DuplicationsParser.Duplication> duplications = blocks.get(0).duplications();
+    List<DuplicationsParser.Duplication> duplications = blocks.get(0).getDuplications();
     assertThat(duplications).hasSize(2);
 
     // Smallest line comes first
@@ -118,7 +118,7 @@ public class DuplicationsParserTest {
     List<DuplicationsParser.Block> blocks = parser.parse(currentFile, getData("duplication_on_same_project.xml"), session);
     assertThat(blocks).hasSize(1);
 
-    List<DuplicationsParser.Duplication> duplications = blocks.get(0).duplications();
+    List<DuplicationsParser.Duplication> duplications = blocks.get(0).getDuplications();
     assertThat(duplications).hasSize(2);
 
     // Current file comes first
@@ -138,7 +138,7 @@ public class DuplicationsParserTest {
     List<DuplicationsParser.Block> blocks = parser.parse(currentFile, getData("duplications_on_different_project.xml"), session);
     assertThat(blocks).hasSize(1);
 
-    List<DuplicationsParser.Duplication> duplications = blocks.get(0).duplications();
+    List<DuplicationsParser.Duplication> duplications = blocks.get(0).getDuplications();
     assertThat(duplications).hasSize(3);
 
     // Current file's project comes first
@@ -168,11 +168,11 @@ public class DuplicationsParserTest {
 
     // Block with smaller line should come first
 
-    assertThat(blocks.get(0).duplications().get(0).from()).isEqualTo(38);
-    assertThat(blocks.get(0).duplications().get(1).from()).isEqualTo(29);
+    assertThat(blocks.get(0).getDuplications().get(0).from()).isEqualTo(38);
+    assertThat(blocks.get(0).getDuplications().get(1).from()).isEqualTo(29);
 
-    assertThat(blocks.get(1).duplications().get(0).from()).isEqualTo(94);
-    assertThat(blocks.get(1).duplications().get(1).from()).isEqualTo(83);
+    assertThat(blocks.get(1).getDuplications().get(0).from()).isEqualTo(94);
+    assertThat(blocks.get(1).getDuplications().get(1).from()).isEqualTo(83);
   }
 
   @Test
@@ -180,7 +180,7 @@ public class DuplicationsParserTest {
     List<DuplicationsParser.Block> blocks = parser.parse(currentFile, getData("duplication_on_removed_file.xml"), session);
     assertThat(blocks).hasSize(1);
 
-    List<DuplicationsParser.Duplication> duplications = blocks.get(0).duplications();
+    List<DuplicationsParser.Duplication> duplications = blocks.get(0).getDuplications();
     assertThat(duplications).hasSize(2);
 
     // Duplications on removed file