Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sonar 10.4 #4

Merged
merged 26 commits into from
Apr 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b134ef4
Update 1.17.0
C4tWithShell Feb 8, 2024
d07b087
Update
C4tWithShell Feb 8, 2024
6e233a3
Update gradle
C4tWithShell Feb 8, 2024
d526737
[Gradle Release Plugin] - new version commit: '1.17.1'.
web-flow Feb 8, 2024
6fb4793
Update
C4tWithShell Feb 15, 2024
c33123d
[Gradle Release Plugin] - new version commit: '1.17.2'.
web-flow Feb 15, 2024
62a54b0
Update Jwts
C4tWithShell Feb 15, 2024
b296d3e
[Gradle Release Plugin] - new version commit: '1.17.3'.
web-flow Feb 15, 2024
58cbdd1
Update time
C4tWithShell Feb 15, 2024
d586b95
[Gradle Release Plugin] - new version commit: '1.17.4'.
web-flow Feb 15, 2024
c51e51c
Update jwts builder
C4tWithShell Feb 15, 2024
e94e5a8
[Gradle Release Plugin] - new version commit: '1.17.5'.
web-flow Feb 15, 2024
7b989e0
Add deps
C4tWithShell Feb 15, 2024
9b3841b
Merge branch 'update/17.0' of https://github.com/soramitsu/soramitsu-…
C4tWithShell Feb 15, 2024
f7bb4a4
[Gradle Release Plugin] - new version commit: '1.17.6'.
web-flow Feb 15, 2024
75510fc
Try with builder
C4tWithShell Feb 15, 2024
1916b9b
[Gradle Release Plugin] - new version commit: '1.17.7'.
web-flow Feb 15, 2024
2d005ff
Remove issuedAt
C4tWithShell Feb 15, 2024
34fc298
[Gradle Release Plugin] - new version commit: '1.17.8'.
web-flow Feb 15, 2024
b1ce483
Test
C4tWithShell Feb 15, 2024
d7eb2a1
Update 1.17.1
C4tWithShell Feb 15, 2024
ecf6d47
Update 1.17.1
C4tWithShell Feb 15, 2024
058ba89
Update 1.17.1
C4tWithShell Feb 15, 2024
67c6fb5
[Gradle Release Plugin] - new version commit: '1.17.2'.
web-flow Feb 15, 2024
08f2d79
Update
C4tWithShell Apr 8, 2024
e12b77e
[Gradle Release Plugin] - new version commit: '1.17.3'.
web-flow Apr 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update
C4tWithShell committed Apr 8, 2024
commit 08f2d79500fcf76e7c28405549aaf63f192bc6cc
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mc1arke_sonarqube-community-branch-plugin&metric=alert_status)](https://sonarcloud.io/dashboard?id=mc1arke_sonarqube-community-branch-plugin)
[![Build Status](https://img.shields.io/github/actions/workflow/status/mc1arke/sonarqube-community-branch-plugin/.github/workflows/build.yml?branch=master&logo=github)](https://github.com/mc1arke/sonarqube-community-branch-plugin?workflow=build)
[![Build Status](https://img.shields.io/github/actions/workflow/status/soramitsu/soramitsu-sonarqube-community-branch-plugin/.github/workflows/build.yml?branch=master&logo=github)](https://github.com/mc1arke/sonarqube-community-branch-plugin?workflow=build)

# Sonarqube Community Branch Plugin

@@ -23,6 +22,12 @@ Use the following table to find the correct plugin version for each SonarQube ve

SonarQube Version | Plugin Version
------------------|---------------
10.4 | 1.17.2
10.3 | 1.16.1
10.2 | 1.16.0
10.1 | 1.15.0
10.0 | 1.15.0
9.9 (LTS) | 1.14.0
9.8+ | 1.14.0
9.7 | 1.13.0
9.1 - 9.6 | 1.12.0
@@ -35,6 +40,8 @@ SonarQube Version | Plugin Version
7.8 - 8.0 | 1.3.2
7.4 - 7.7 | 1.0.2

Older versions are listed on the Github release page but are no longer supported.

# Features

The plugin is intended to support the
@@ -71,6 +78,13 @@ __Note:__ If you're setting the `SONAR_WEB_JAVAADDITIONALOPTS` or `SONAR_CE_JAVA
your container launch then you'll need to add the `javaagent` configuration to your overrides to match what's in the
provided Dockerfile.

## Docker Compose

A `docker-compose.yml` file is provided.
It uses the env variables available in `.env`.

To use it, clone the repository and execute `docker-compose up`. Note that you need to have docker-compose installed in your system and added to your PATH

## Kubernetes with official Helm Chart

When using
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -62,17 +62,17 @@ tasks.withType(JavaCompile) {
dependencies {
compileOnly(fileTree(dir: sonarLibraries, include: '**/*.jar', exclude: 'extensions/*.jar'))
testImplementation(fileTree(dir: sonarLibraries, include: '**/*.jar', exclude: 'extensions/*.jar'))
testImplementation('org.mockito:mockito-core:5.8.0')
testImplementation('org.assertj:assertj-core:3.25.1')
testImplementation('org.wiremock:wiremock:3.3.1')
testImplementation('org.mockito:mockito-core:5.11.0')
testImplementation('org.assertj:assertj-core:3.25.3')
testImplementation('org.wiremock:wiremock:3.5.2')
zip("sonarqube:sonarqube:${sonarqubeVersion}@zip")
implementation('org.bouncycastle:bcpkix-jdk15on:1.70')
implementation(files('lib/nodes-0.5.0.jar'))
runtimeOnly('com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.16.1')
runtimeOnly('com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.0')
compileOnly('com.google.code.findbugs:jsr305:3.0.2')
implementation('org.javassist:javassist:3.30.2-GA')
implementation('com.squareup.okhttp3:logging-interceptor:4.12.0')
testImplementation(platform('org.junit:junit-bom:5.10.1'))
testImplementation(platform('org.junit:junit-bom:5.10.2'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation('junit:junit:4.13.2')
testRuntimeOnly('org.junit.vintage:junit-vintage-engine')
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ public class CheckRunDetails {
private final List<Annotation> annotations;
private final CheckConclusionState checkConclusionState;
private final int pullRequestId;
private final String projectKey;

private CheckRunDetails(Builder builder) {
summary = builder.summary;
@@ -49,6 +50,7 @@ private CheckRunDetails(Builder builder) {
annotations = builder.annotations;
checkConclusionState = builder.checkConclusionState;
pullRequestId = builder.pullRequestId;
projectKey = builder.projectKey;
}

public String getSummary() {
@@ -95,6 +97,10 @@ public int getPullRequestId() {
return pullRequestId;
}

public String getProjectKey() {
return projectKey;
}

public static Builder builder() {
return new Builder();
}
@@ -111,6 +117,7 @@ public static final class Builder {
private List<Annotation> annotations;
private CheckConclusionState checkConclusionState;
private int pullRequestId;
private String projectKey;

private Builder() {
super();
@@ -171,6 +178,11 @@ public Builder withPullRequestId(int pullRequestId) {
return this;
}

public Builder withProjectKey(String projectKey) {
this.projectKey = projectKey;
return this;
}

public CheckRunDetails build() {
return new CheckRunDetails(this);
}
Original file line number Diff line number Diff line change
@@ -78,12 +78,9 @@ public RepositoryAuthenticationToken getInstallationToken(String apiUrl, String

Instant issued = clock.instant().minus(10, ChronoUnit.SECONDS);
Instant expiry = issued.plus(2, ChronoUnit.MINUTES);
String jwtToken = new DefaultJwtBuilder()
.expiration(Date.from(expiry))
.issuedAt(Date.from(issued))
.claim("iss", appId)
.signWith(createPrivateKey(apiPrivateKey), Jwts.SIG.RS256)
.compact();
String jwtToken = new DefaultJwtBuilder().issuedAt(Date.from(issued)).expiration(Date.from(expiry))
.claim("iss", appId).signWith(createPrivateKey(apiPrivateKey), Jwts.SIG.RS256).compact();

Optional<RepositoryAuthenticationToken> repositoryAuthenticationToken = findTokenFromAppInstallationList(getV3Url(apiUrl) + "/app/installations", jwtToken, projectPath);

return repositoryAuthenticationToken.orElseThrow(() -> new InvalidConfigurationException(InvalidConfigurationException.Scope.PROJECT,
Original file line number Diff line number Diff line change
@@ -49,12 +49,14 @@ public static class CommentNode {
private final Actor author;
@GraphQLProperty(name = "isMinimized")
private final boolean minimized;
private final String body;

@JsonCreator
public CommentNode(@JsonProperty("id") String id, @JsonProperty("author") Actor author, @JsonProperty("isMinimized") boolean minimized) {
public CommentNode(@JsonProperty("id") String id, @JsonProperty("author") Actor author, @JsonProperty("isMinimized") boolean minimized, @JsonProperty("body") String body) {
this.id = id;
this.author = author;
this.minimized = minimized;
this.body = body;
}

public String getId() {
@@ -68,5 +70,9 @@ public Actor getAuthor() {
public boolean isMinimized() {
return minimized;
}

public String getBody() {
return body;
}
}
}
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ public String createCheckRun(CheckRunDetails checkRunDetails, boolean postSummar


if (postSummaryComment) {
postSummaryComment(graphqlUrl, headers, checkRunDetails.getPullRequestId(), checkRunDetails.getSummary());
postSummaryComment(graphqlUrl, headers, checkRunDetails.getPullRequestId(), checkRunDetails.getSummary(), checkRunDetails.getProjectKey());
}

return graphQLResponseEntity.getResponse().getCheckRun().getId();
@@ -128,7 +128,7 @@ public String getRepositoryUrl() {
return repositoryAuthenticationToken.getRepositoryUrl();
}

private void postSummaryComment(String graphqlUrl, Map<String, String> headers, int pullRequestKey, String summary) throws IOException {
private void postSummaryComment(String graphqlUrl, Map<String, String> headers, int pullRequestKey, String summary, String projectId) throws IOException {
String login = getLogin(graphqlUrl, headers);

GetRepository.PullRequest pullRequest = getPullRequest(graphqlUrl, headers, pullRequestKey);
@@ -137,6 +137,7 @@ private void postSummaryComment(String graphqlUrl, Map<String, String> headers,
getComments(pullRequest, graphqlUrl, headers, pullRequestKey).stream()
.filter(c -> "Bot".equalsIgnoreCase(c.getAuthor().getType()) && login.equalsIgnoreCase(c.getAuthor().getLogin()))
.filter(c -> !c.isMinimized())
.filter(c -> c.getBody().contains(String.format("**Project ID:** %s\r\n", projectId)))
.map(Comments.CommentNode::getId)
.forEach(commentId -> this.minimizeComment(graphqlUrl, headers, commentId));

Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@ public DecorationResult decorateQualityGateStatus(AnalysisDetails analysisDetail
.withExternalId(analysisDetails.getAnalysisId())
.withName(String.format("%s Sonarqube Results", analysisDetails.getAnalysisProjectName()))
.withTitle("Quality Gate " + (analysisDetails.getQualityGateStatus() == QualityGate.Status.OK ? "success" : "failed"))
.withProjectKey(analysisDetails.getAnalysisProjectKey())
.build();

try {
Original file line number Diff line number Diff line change
@@ -90,9 +90,9 @@ public AnalysisIssueSummary createAnalysisIssueSummary(PostAnalysisIssueVisitor.
.withProjectKey(analysisDetails.getAnalysisProjectKey())
.withResolution(issue.resolution())
.withSeverity(issue.severity())
.withSeverityImageUrl(String.format("%s/checks/Severity/%s.svg?sanitize=true", baseImageUrl, issue.severity().toLowerCase()))
.withSeverityImageUrl(String.format("%s/checks/Severity/%s.png", baseImageUrl, issue.severity().toLowerCase()))
.withType(issue.type().name())
.withTypeImageUrl(String.format("%s/checks/IssueType/%s.svg?sanitize=true", baseImageUrl, issue.type().name().toLowerCase()))
.withTypeImageUrl(String.format("%s/checks/IssueType/%s.png", baseImageUrl, issue.type().name().toLowerCase()))
.build();
}

@@ -131,10 +131,10 @@ public AnalysisSummary createAnalysisSummary(AnalysisDetails analysisDetails) {
.withSummaryImageUrl(baseImageUrl + "/common/icon.png")
.withBugCount(issueCounts.get(RuleType.BUG))
.withBugUrl(getIssuesUrlForRuleType(analysisDetails, RuleType.BUG))
.withBugImageUrl(baseImageUrl + "/common/bug.svg?sanitize=true")
.withBugImageUrl(baseImageUrl + "/common/bug.png")
.withCodeSmellCount(issueCounts.get(RuleType.CODE_SMELL))
.withCodeSmellUrl(getIssuesUrlForRuleType(analysisDetails, RuleType.CODE_SMELL))
.withCodeSmellImageUrl(baseImageUrl + "/common/code_smell.svg?sanitize=true")
.withCodeSmellImageUrl(baseImageUrl + "/common/code_smell.png")
.withCoverage(coverage)
.withNewCoverage(newCoverage)
.withCoverageUrl(getComponentMeasuresUrlForCodeMetrics(analysisDetails, CoreMetrics.NEW_COVERAGE_KEY))
@@ -149,13 +149,13 @@ public AnalysisSummary createAnalysisSummary(AnalysisDetails analysisDetails) {
.collect(Collectors.toList()))
.withStatusDescription(QualityGate.Status.OK == analysisDetails.getQualityGateStatus() ? "Passed" : "Failed")
.withStatusImageUrl(QualityGate.Status.OK == analysisDetails.getQualityGateStatus()
? baseImageUrl + "/checks/QualityGateBadge/passed.svg?sanitize=true"
: baseImageUrl + "/checks/QualityGateBadge/failed.svg?sanitize=true")
? baseImageUrl + "/checks/QualityGateBadge/passed.png"
: baseImageUrl + "/checks/QualityGateBadge/failed.png")
.withTotalIssueCount(issueTotal)
.withSecurityHotspotCount(issueCounts.get(RuleType.SECURITY_HOTSPOT))
.withVulnerabilityCount(issueCounts.get(RuleType.VULNERABILITY))
.withVulnerabilityUrl(getIssuesUrlForRuleType(analysisDetails, RuleType.VULNERABILITY))
.withVulnerabilityImageUrl(baseImageUrl + "/common/vulnerability.svg?sanitize=true")
.withVulnerabilityImageUrl(baseImageUrl + "/common/vulnerability.png")
.build();
}

@@ -201,7 +201,7 @@ private String getDashboardUrl(AnalysisDetails analysisDetails) {

private static String createCoverageImage(BigDecimal coverage, String baseImageUrl) {
if (null == coverage) {
return baseImageUrl + "/checks/CoverageChart/NoCoverageInfo.svg?sanitize=true";
return baseImageUrl + "/checks/CoverageChart/NoCoverageInfo.png";
}
BigDecimal matchedLevel = BigDecimal.ZERO;
for (BigDecimal level : COVERAGE_LEVELS) {
@@ -210,12 +210,12 @@ private static String createCoverageImage(BigDecimal coverage, String baseImageU
break;
}
}
return baseImageUrl + "/checks/CoverageChart/" + matchedLevel + ".svg?sanitize=true";
return baseImageUrl + "/checks/CoverageChart/" + matchedLevel + ".png";
}

private static String createDuplicateImage(BigDecimal duplications, String baseImageUrl) {
if (null == duplications) {
return baseImageUrl + "/checks/Duplications/NoDuplicationInfo.svg?sanitize=true";
return baseImageUrl + "/checks/Duplications/NoDuplicationInfo.png";
}
String matchedLevel = "20plus";
for (DuplicationMapping level : DUPLICATION_LEVELS) {
@@ -224,7 +224,7 @@ private static String createDuplicateImage(BigDecimal duplications, String baseI
break;
}
}
return baseImageUrl + "/checks/Duplications/" + matchedLevel + ".svg?sanitize=true";
return baseImageUrl + "/checks/Duplications/" + matchedLevel + ".png";
}

private static String formatQualityGateCondition(QualityGate.Condition condition) {
Binary file added src/main/resources/static/checks/CoverageChart/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/Duplications/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/Duplications/20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/Duplications/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/Duplications/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/IssueType/bug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/C.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/static/checks/RatingBadge/E.png
Binary file added src/main/resources/static/checks/Severity/info.png
Binary file added src/main/resources/static/checks/Severity/major.png
Binary file added src/main/resources/static/checks/Severity/minor.png
Binary file added src/main/resources/static/common/bug.png
Binary file added src/main/resources/static/common/code_smell.png
Binary file added src/main/resources/static/common/vulnerability.png
Original file line number Diff line number Diff line change
@@ -159,6 +159,7 @@ void verifyCheckRunSubmitsCorrectAnnotations() throws IOException {
" {" +
" \"id\": \"MDEyOklzc3VlQ29tbWVudDE1MDE3\"," +
" \"isMinimized\": false," +
" \"body\": \"**Project ID:** project-key-test\\r\\n\"," +
" \"author\": {" +
" \"__typename\": \"Bot\"," +
" \"login\": \"test-sonar\"" +
@@ -207,6 +208,7 @@ void verifyCheckRunSubmitsCorrectAnnotations() throws IOException {
.withName("Name")
.withTitle("Title")
.withPullRequestId(999)
.withProjectKey("project-key-test")
.build();


@@ -299,7 +301,7 @@ void verifyCheckRunSubmitsCorrectAnnotations() throws IOException {
assertEquals(requestEntities.get(2), getPullRequestRequestEntityArgumentCaptor.getValue());
assertEquals(
"query { repository (owner:\"owner\",name:\"repository\") { url pullRequest : pullRequest (number:999) { comments : comments (first:100) { nodes" +
" { author { type : __typename login } id minimized : isMinimized } pageInfo { hasNextPage endCursor } } id } } } ",
" { author { type : __typename login } id minimized : isMinimized body } pageInfo { hasNextPage endCursor } } id } } } ",
getPullRequestRequestEntityArgumentCaptor.getValue().getRequest()
);

Original file line number Diff line number Diff line change
@@ -147,6 +147,7 @@ void verifyCorrectArgumentsAndReturnValuesUsed() throws IOException {
.withSeverity(i % 5 < 1 ? CheckAnnotationLevel.NOTICE : i % 5 > 2 ? CheckAnnotationLevel.FAILURE : CheckAnnotationLevel.WARNING)
.build()).collect(Collectors.toList()))
.withCheckConclusionState(CheckConclusionState.SUCCESS)
.withProjectKey(analysisDetails.getAnalysisProjectKey())
.build());
assertThat(decorationResult).usingRecursiveComparison().isEqualTo(expectedResult);
}
Loading