From b3366cd3e54c6f2926c4b64e082d90759ef9e715 Mon Sep 17 00:00:00 2001 From: Michael Clarke Date: Wed, 11 Dec 2024 19:47:19 +0000 Subject: [PATCH] #1011: Add support for Sonarqube 24.12 (#1013) --- .env | 2 +- build.gradle | 2 +- .../bitbucket/BitbucketPullRequestDecorator.java | 1 + .../github/GithubPullRequestDecorator.java | 2 ++ .../ws/pullrequest/action/ListAction.java | 12 ++++++------ .../github/GithubPullRequestDecoratorTest.java | 4 ++-- .../ws/pullrequest/action/ListActionTest.java | 13 +++++++------ 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.env b/.env index 4cbc3240..da1e1e7c 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ # The Sonarqube base image. 'latest' if building locally, '8.5-community' if targeting a specific version -SONARQUBE_VERSION=10.6-community +SONARQUBE_VERSION=24.12.0.100206-community # The name of the Dockerfile to run. 'Dockerfile' is building locally, 'release.Dockerfile' if building the release image DOCKERFILE=Dockerfile diff --git a/build.gradle b/build.gradle index 5d98b259..850f7885 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ repositories { } } -def sonarqubeVersion = '10.6.0.92116' +def sonarqubeVersion = '24.12.0.100206' def sonarqubeLibDir = "${projectDir}/sonarqube-lib" def sonarLibraries = "${sonarqubeLibDir}/sonarqube-${sonarqubeVersion}/lib" diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/bitbucket/BitbucketPullRequestDecorator.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/bitbucket/BitbucketPullRequestDecorator.java index 9520523c..71548c0b 100644 --- a/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/bitbucket/BitbucketPullRequestDecorator.java +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/bitbucket/BitbucketPullRequestDecorator.java @@ -185,6 +185,7 @@ static boolean exceedsMaximumNumberOfAnnotations(int chunkCounter, AnnotationUpl private static String toBitbucketSeverity(Severity severity) { switch (severity) { case HIGH: + case BLOCKER: return "HIGH"; case MEDIUM: return "MEDIUM"; diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/GithubPullRequestDecorator.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/GithubPullRequestDecorator.java index 6a1e83b5..876afae0 100644 --- a/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/GithubPullRequestDecorator.java +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/GithubPullRequestDecorator.java @@ -145,10 +145,12 @@ private static GHCheckRun.AnnotationLevel mapToGithubAnnotationLevel(Collection< Severity maxSeverity = sonarqubeSeverity.stream().max(Severity::compareTo).orElseThrow(); switch (maxSeverity) { case LOW: + case INFO: return GHCheckRun.AnnotationLevel.NOTICE; case MEDIUM: return GHCheckRun.AnnotationLevel.WARNING; case HIGH: + case BLOCKER: return GHCheckRun.AnnotationLevel.FAILURE; default: throw new IllegalArgumentException("Unknown severity value: " + sonarqubeSeverity); diff --git a/src/main/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListAction.java b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListAction.java index a84dc477..a65559ba 100644 --- a/src/main/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListAction.java +++ b/src/main/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListAction.java @@ -41,7 +41,7 @@ import org.sonar.db.component.BranchDto; import org.sonar.db.component.BranchType; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.measure.LiveMeasureDto; +import org.sonar.db.measure.MeasureDto; import org.sonar.db.permission.GlobalPermission; import org.sonar.db.project.ProjectDto; import org.sonar.db.protobuf.DbProjectBranches; @@ -91,9 +91,9 @@ public void handleProjectRequest(ProjectDto project, Request request, Response r .collect(Collectors.toList())) .stream().collect(Collectors.toMap(BranchDto::getUuid, Function.identity())); - Map qualityGateMeasuresByComponentUuids = getDbClient().liveMeasureDao() + Map qualityGateMeasuresByComponentUuids = getDbClient().measureDao() .selectByComponentUuidsAndMetricKeys(dbSession, pullRequestUuids, List.of(CoreMetrics.ALERT_STATUS_KEY)).stream() - .collect(Collectors.toMap(LiveMeasureDto::getComponentUuid, Function.identity())); + .collect(Collectors.toMap(MeasureDto::getComponentUuid, Function.identity())); Map analysisDateByBranchUuid = getDbClient().snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, pullRequestUuids).stream() .collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s -> DateUtils.formatDateTime(s.getCreatedAt()))); @@ -114,7 +114,7 @@ private static void checkPermission(ProjectDto project, UserSession userSession) } private static void addPullRequest(ProjectPullRequests.ListWsResponse.Builder response, BranchDto branch, Map mergeBranchesByUuid, - @Nullable LiveMeasureDto qualityGateMeasure, @Nullable String analysisDate) { + @Nullable MeasureDto qualityGateMeasure, @Nullable String analysisDate) { Optional mergeBranch = Optional.ofNullable(mergeBranchesByUuid.get(branch.getMergeBranchUuid())); ProjectPullRequests.PullRequest.Builder builder = ProjectPullRequests.PullRequest.newBuilder(); @@ -147,10 +147,10 @@ private static void addPullRequest(ProjectPullRequests.ListWsResponse.Builder re response.addPullRequests(builder); } - private static void setQualityGate(ProjectPullRequests.PullRequest.Builder builder, @Nullable LiveMeasureDto qualityGateMeasure) { + private static void setQualityGate(ProjectPullRequests.PullRequest.Builder builder, @Nullable MeasureDto qualityGateMeasure) { ProjectPullRequests.Status.Builder statusBuilder = ProjectPullRequests.Status.newBuilder(); if (qualityGateMeasure != null) { - Optional.ofNullable(qualityGateMeasure.getDataAsString()).ifPresent(statusBuilder::setQualityGateStatus); + Optional.ofNullable(qualityGateMeasure.getString(CoreMetrics.ALERT_STATUS_KEY)).ifPresent(statusBuilder::setQualityGateStatus); } builder.setStatus(statusBuilder); } diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/GithubPullRequestDecoratorTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/GithubPullRequestDecoratorTest.java index d4e31425..71385668 100644 --- a/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/GithubPullRequestDecoratorTest.java +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/GithubPullRequestDecoratorTest.java @@ -174,7 +174,7 @@ void shouldDecoratePullRequestWithCorrectAnalysisAndSummaryCommentWhenEnabled() output.add(new GHCheckRunBuilder.Annotation( "path" + i, i, - GHCheckRun.AnnotationLevel.values()[i % GHCheckRun.AnnotationLevel.values().length], + GHCheckRun.AnnotationLevel.values()[i % Severity.values().length < 2 ? 0 : i % Severity.values().length > 2 ? 2 : 1], "issue message " + i)); } @@ -235,7 +235,7 @@ void shouldDecoratePullRequestWithCorrectAnalysisAndNoSummaryCommentWhenDisabled output.add(new GHCheckRunBuilder.Annotation( "path" + i, i, - GHCheckRun.AnnotationLevel.values()[i % GHCheckRun.AnnotationLevel.values().length], + GHCheckRun.AnnotationLevel.values()[i % Severity.values().length < 2 ? 0 : i % Severity.values().length > 2 ? 2 : 1], "issue message " + i)); } diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListActionTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListActionTest.java index 3ea7f759..b6c0f47e 100644 --- a/src/test/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListActionTest.java +++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/server/pullrequest/ws/pullrequest/action/ListActionTest.java @@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; +import org.sonar.api.measures.CoreMetrics; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -40,8 +41,8 @@ import org.sonar.db.component.BranchType; import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.measure.LiveMeasureDao; -import org.sonar.db.measure.LiveMeasureDto; +import org.sonar.db.measure.MeasureDao; +import org.sonar.db.measure.MeasureDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.protobuf.DbProjectBranches; import org.sonar.server.component.ComponentFinder; @@ -130,11 +131,11 @@ void shouldExecuteRequestWithValidParameter() { .setUuid("uuid2") .setKey("branch2Key"))); - LiveMeasureDao liveMeasureDao = mock(); - when(dbClient.liveMeasureDao()).thenReturn(liveMeasureDao); - when(liveMeasureDao.selectByComponentUuidsAndMetricKeys(any(), any(), any())).thenReturn(List.of(new LiveMeasureDto() + MeasureDao measureDao = mock(); + when(dbClient.measureDao()).thenReturn(measureDao); + when(measureDao.selectByComponentUuidsAndMetricKeys(any(), any(), any())).thenReturn(List.of(new MeasureDto() .setComponentUuid("uuid1") - .setData("live measure"))); + .addValue(CoreMetrics.ALERT_STATUS_KEY, "live measure"))); SnapshotDao snapshotDao = mock(); when(dbClient.snapshotDao()).thenReturn(snapshotDao);