From: Sébastien Lesaint Date: Thu, 17 Nov 2016 08:22:49 +0000 (+0100) Subject: fix quality flaws X-Git-Tag: 6.2-RC1~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea69b9b5dba17f416447fc152d6b9f291c04a59e;p=sonarqube.git fix quality flaws --- diff --git a/server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java b/server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java index 183aa1463a6..c5ee0e2c66c 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java +++ b/server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java @@ -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); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java index 38e1f2ab914..0837efc6733 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/filemove/FileMoveDetectionStep.java @@ -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 dbFileKeys, Map reportFileSourcesByKey, MatchesByScore matchesByScore) { ElectedMatches electedMatches = new ElectedMatches(matchesByScore, dbFileKeys, reportFileSourcesByKey); Multimap matchesPerFileForScore = ArrayListMultimap.create(); - for (List 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 matches, ElectedMatches electedMatches, Multimap matchesPerFileForScore) { + // no match for this score value, ignore + if (matches == null) { + return; + } - List matchesToValidate = electedMatches.filter(matches); - if (matchesToValidate.isEmpty()) { - continue; + List 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) {