Skip to content

Commit

Permalink
#1011: Add support for Sonarqube 24.12
Browse files Browse the repository at this point in the history
The latest release for Sonarqube has removed the LiveMeasures concept,
instead just using Measures, and has moved to a new versioning strategy
for community edition. The plugin has therefore been update to the
latest version number of Sonarqube and the appropriate DAO and DTO
references updated.
  • Loading branch information
mc1arke committed Dec 11, 2024
1 parent d4298a8 commit 704c680
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, LiveMeasureDto> qualityGateMeasuresByComponentUuids = getDbClient().liveMeasureDao()
Map<String, MeasureDto> 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<String, String> analysisDateByBranchUuid = getDbClient().snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, pullRequestUuids).stream()
.collect(Collectors.toMap(SnapshotDto::getRootComponentUuid, s -> DateUtils.formatDateTime(s.getCreatedAt())));

Expand All @@ -114,7 +114,7 @@ private static void checkPermission(ProjectDto project, UserSession userSession)
}

private static void addPullRequest(ProjectPullRequests.ListWsResponse.Builder response, BranchDto branch, Map<String, BranchDto> mergeBranchesByUuid,
@Nullable LiveMeasureDto qualityGateMeasure, @Nullable String analysisDate) {
@Nullable MeasureDto qualityGateMeasure, @Nullable String analysisDate) {
Optional<BranchDto> mergeBranch = Optional.ofNullable(mergeBranchesByUuid.get(branch.getMergeBranchUuid()));

ProjectPullRequests.PullRequest.Builder builder = ProjectPullRequests.PullRequest.newBuilder();
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 704c680

Please sign in to comment.