From: Duarte Meneses Date: Wed, 9 Jan 2019 13:16:56 +0000 (+0100) Subject: SONAR-11605 No changed lines detected in P/R and SLB if target branch is not explicit... X-Git-Tag: 7.6~149 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8d3f4bd7495ee6aa204f31c7329ffffedc7e5ae7;p=sonarqube.git SONAR-11605 No changed lines detected in P/R and SLB if target branch is not explicitly specified --- diff --git a/server/sonar-server/src/main/resources/org/sonar/server/branch/ws/list-example.json b/server/sonar-server/src/main/resources/org/sonar/server/branch/ws/list-example.json index 5fa613fe94d..2e95cea4b2e 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/branch/ws/list-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/branch/ws/list-example.json @@ -1,19 +1,10 @@ { "branches": [ - { - "name": "feature/bar", - "isMain": false, - "type": "LONG", - "status": { - "qualityGateStatus": "OK" - }, - "analysisDate": "2017-04-01T01:15:42+0100" - }, { "name": "feature/foo", "isMain": false, "type": "SHORT", - "mergeBranch": "feature/bar", + "mergeBranch": "master", "status": { "qualityGateStatus": "OK", "bugs": 1, @@ -21,6 +12,15 @@ "codeSmells": 0 }, "analysisDate": "2017-04-03T13:37:00+0100" + }, + { + "name": "master", + "isMain": true, + "type": "LONG", + "status": { + "qualityGateStatus": "ERROR" + }, + "analysisDate": "2017-04-01T01:15:42+0100" } ] } diff --git a/server/sonar-server/src/test/java/org/sonar/server/branch/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/branch/ws/ListActionTest.java index b40e2548b53..091cb5079e4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/branch/ws/ListActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/branch/ws/ListActionTest.java @@ -107,16 +107,13 @@ public class ListActionTest { @Test public void test_example() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube")); - - ComponentDto longLivingBranch = db.components() - .insertProjectBranch(project, b -> b.setKey("feature/bar").setBranchType(org.sonar.db.component.BranchType.LONG)); + ComponentDto project = db.components().insertMainBranch(p -> p.setDbKey("sonarqube")); db.getDbClient().snapshotDao().insert(db.getSession(), - newAnalysis(longLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime())); - db.measures().insertLiveMeasure(longLivingBranch, qualityGateStatus, m -> m.setData("OK")); + newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime())); + db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR")); ComponentDto shortLivingBranch = db.components() - .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid())); + .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(project.uuid())); db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(shortLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime())); db.measures().insertLiveMeasure(shortLivingBranch, qualityGateStatus, m -> m.setData("OK")); @@ -139,16 +136,13 @@ public class ListActionTest { @Test public void test_with_SCAN_EXCUTION_permission() { - ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("sonarqube")); - - ComponentDto longLivingBranch = db.components() - .insertProjectBranch(project, b -> b.setKey("feature/bar").setBranchType(org.sonar.db.component.BranchType.LONG)); + ComponentDto project = db.components().insertMainBranch(p -> p.setDbKey("sonarqube")); db.getDbClient().snapshotDao().insert(db.getSession(), - newAnalysis(longLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime())); - db.measures().insertLiveMeasure(longLivingBranch, qualityGateStatus, m -> m.setData("OK")); + newAnalysis(project).setLast(true).setCreatedAt(parseDateTime("2017-04-01T01:15:42+0100").getTime())); + db.measures().insertLiveMeasure(project, qualityGateStatus, m -> m.setData("ERROR")); ComponentDto shortLivingBranch = db.components() - .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(longLivingBranch.uuid())); + .insertProjectBranch(project, b -> b.setKey("feature/foo").setBranchType(SHORT).setMergeBranchUuid(project.uuid())); db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(shortLivingBranch).setLast(true).setCreatedAt(parseDateTime("2017-04-03T13:37:00+0100").getTime())); db.measures().insertLiveMeasure(shortLivingBranch, qualityGateStatus, m -> m.setData("OK")); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ChangedLinesPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ChangedLinesPublisher.java index f04cbf78ab0..4b9d463a164 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ChangedLinesPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ChangedLinesPublisher.java @@ -73,7 +73,6 @@ public class ChangedLinesPublisher implements ReportPublisherStep { } private int writeChangedLines(ScmProvider provider, ScannerReportWriter writer, String targetScmBranch) { - Path rootBaseDir = inputModuleHierarchy.root().getBaseDir(); Map changedFiles = StreamSupport.stream(inputComponentStore.allChangedFilesToPublish().spliterator(), false) .collect(Collectors.toMap(DefaultInputFile::path, f -> f)); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java index 05aa97c274f..4398c3dc3a8 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.CheckForNull; -import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; /** @@ -31,10 +30,7 @@ import javax.annotation.concurrent.Immutable; */ @Immutable public class ProjectBranches { - private final Map branches; - - @Nullable private final String defaultBranchName; public ProjectBranches(List branchInfos) { @@ -59,7 +55,6 @@ public class ProjectBranches { return branches.isEmpty(); } - @CheckForNull public String defaultBranchName() { return defaultBranchName; } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java index 9c3feab2c22..93132a99b65 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectPullRequests.java @@ -32,16 +32,11 @@ import javax.annotation.concurrent.Immutable; */ @Immutable public class ProjectPullRequests { - + private static final BinaryOperator PICK_MOST_RECENT_ANALYSIS = (a, b) -> a.getAnalysisDate() < b.getAnalysisDate() ? b : a; private final Map pullRequestsByBranchName; public ProjectPullRequests(List pullRequestInfos) { - BinaryOperator mergeFunction = pickMostRecentAnalysis(); - this.pullRequestsByBranchName = pullRequestInfos.stream().collect(Collectors.toMap(PullRequestInfo::getBranch, Function.identity(), mergeFunction)); - } - - private static BinaryOperator pickMostRecentAnalysis() { - return (a, b) -> a.getAnalysisDate() < b.getAnalysisDate() ? b : a; + this.pullRequestsByBranchName = pullRequestInfos.stream().collect(Collectors.toMap(PullRequestInfo::getBranch, Function.identity(), PICK_MOST_RECENT_ANALYSIS)); } @CheckForNull