]> source.dussan.org Git - sonarqube.git/commitdiff
fix quality flaws
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 17 Nov 2016 08:22:49 +0000 (09:22 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 17 Nov 2016 16:59:43 +0000 (17:59 +0100)
server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java

index 183aa1463a686715262b7616c0b3794821d846a4..c5ee0e2c66c259283b79b2311f5901855dbfd308 100644 (file)
@@ -254,7 +254,7 @@ public class LogbackHelper {
     return newLevel;
   }
 
-  private Level resolveLevel(Props props, String... propertyKeys) {
+  private static Level resolveLevel(Props props, String... propertyKeys) {
     Level newLevel = Level.INFO;
     for (String propertyKey : propertyKeys) {
       Level level = getPropertyValueAsLevel(props, propertyKey);
index 38e1f2ab9142d7d312a847a2f3497c5ac07b3ca2..0837efc6733e97e2c8133a6a59adb1976bda3b16 100644 (file)
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import javax.annotation.concurrent.Immutable;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.utils.log.Logger;
@@ -160,8 +161,8 @@ public class FileMoveDetectionStep implements ComputationStep {
           .setStrategy(Strategy.LEAVES)
           .build());
       return from(componentDtos)
-            .transform(componentDto -> new DbComponent(componentDto.getId(), componentDto.key(), componentDto.uuid(), componentDto.path()))
-            .uniqueIndex(DbComponent::getKey);
+        .transform(componentDto -> new DbComponent(componentDto.getId(), componentDto.key(), componentDto.uuid(), componentDto.path()))
+        .uniqueIndex(DbComponent::getKey);
     }
   }
 
@@ -247,36 +248,38 @@ public class FileMoveDetectionStep implements ComputationStep {
   private static ElectedMatches electMatches(Set<String> dbFileKeys, Map<String, File> reportFileSourcesByKey, MatchesByScore matchesByScore) {
     ElectedMatches electedMatches = new ElectedMatches(matchesByScore, dbFileKeys, reportFileSourcesByKey);
     Multimap<String, Match> matchesPerFileForScore = ArrayListMultimap.create();
-    for (List<Match> matches : matchesByScore) {
-      // no match for this score value, ignore
-      if (matches == null) {
-        continue;
-      }
+    matchesByScore.forEach(matches -> electMatches(matches, electedMatches, matchesPerFileForScore));
+    return electedMatches;
+  }
+
+  private static void electMatches(@Nullable List<Match> matches, ElectedMatches electedMatches, Multimap<String, Match> matchesPerFileForScore) {
+    // no match for this score value, ignore
+    if (matches == null) {
+      return;
+    }
 
-      List<Match> matchesToValidate = electedMatches.filter(matches);
-      if (matchesToValidate.isEmpty()) {
-        continue;
+    List<Match> matchesToValidate = electedMatches.filter(matches);
+    if (matchesToValidate.isEmpty()) {
+      return;
+    }
+    if (matchesToValidate.size() == 1) {
+      Match match = matchesToValidate.get(0);
+      electedMatches.add(match);
+    } else {
+      matchesPerFileForScore.clear();
+      for (Match match : matchesToValidate) {
+        matchesPerFileForScore.put(match.getDbKey(), match);
+        matchesPerFileForScore.put(match.getReportKey(), match);
       }
-      if (matchesToValidate.size() == 1) {
-        Match match = matchesToValidate.get(0);
-        electedMatches.add(match);
-      } else {
-        matchesPerFileForScore.clear();
-        for (Match match : matchesToValidate) {
-          matchesPerFileForScore.put(match.getDbKey(), match);
-          matchesPerFileForScore.put(match.getReportKey(), match);
-        }
-        // validate non ambiguous matches (ie. the match is the only match of either the db file and the report file)
-        for (Match match : matchesToValidate) {
-          int dbFileMatchesCount = matchesPerFileForScore.get(match.getDbKey()).size();
-          int reportFileMatchesCount = matchesPerFileForScore.get(match.getReportKey()).size();
-          if (dbFileMatchesCount == 1 && reportFileMatchesCount == 1) {
-            electedMatches.add(match);
-          }
+      // validate non ambiguous matches (ie. the match is the only match of either the db file and the report file)
+      for (Match match : matchesToValidate) {
+        int dbFileMatchesCount = matchesPerFileForScore.get(match.getDbKey()).size();
+        int reportFileMatchesCount = matchesPerFileForScore.get(match.getReportKey()).size();
+        if (dbFileMatchesCount == 1 && reportFileMatchesCount == 1) {
+          electedMatches.add(match);
         }
       }
     }
-    return electedMatches;
   }
 
   private static MovedFilesRepository.OriginalFile toOriginalFile(DbComponent dbComponent) {