Skip to content
This repository was archived by the owner on Apr 2, 2019. It is now read-only.

Commit 77ccf5d

Browse files
committed
SONARGITUB-23 Update to SQ plugin API 5.6 (Java 8)
1 parent e583d2c commit 77ccf5d

16 files changed

Lines changed: 240 additions & 407 deletions

pom.xml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.sonarsource.parent</groupId>
77
<artifactId>parent</artifactId>
8-
<version>31</version>
8+
<version>34</version>
99
<relativePath />
1010
</parent>
1111

@@ -19,7 +19,7 @@
1919
<inceptionYear>2015</inceptionYear>
2020

2121
<properties>
22-
<sonar.version>4.5.2</sonar.version>
22+
<sonar.version>5.6</sonar.version>
2323
<sonar.pluginName>GitHub</sonar.pluginName>
2424
<sonar.pluginClass>org.sonar.plugins.github.GitHubPlugin</sonar.pluginClass>
2525

@@ -62,9 +62,9 @@
6262

6363
<repositories>
6464
<!--
65-
Unfortunately this is required because thw transitive dependency org.jenkins-ci:jenkins:pom:1.26
65+
Unfortunately this is required because the transitive dependency org.jenkins-ci:jenkins:pom:1.26
6666
is not available in Maven central repository:
67-
org.kohsuke:github-api:jar:1.69 -> com.infradna.tool:bridge-method-annotation:jar:1.14 -> org.jenkins-ci:annotation-indexer:jar:1.4 -> org.jenkins-ci:jenkins:pom:1.26
67+
org.kohsuke:github-api:jar:1.76 -> com.infradna.tool:bridge-method-annotation:jar:1.14 -> org.jenkins-ci:annotation-indexer:jar:1.4 -> org.jenkins-ci:jenkins:pom:1.26
6868
-->
6969
<repository>
7070
<id>repo.jenkins-ci.org</id>
@@ -74,7 +74,7 @@
7474

7575
<dependencies>
7676
<dependency>
77-
<groupId>org.codehaus.sonar</groupId>
77+
<groupId>org.sonarsource.sonarqube</groupId>
7878
<artifactId>sonar-plugin-api</artifactId>
7979
<version>${sonar.version}</version>
8080
<scope>provided</scope>
@@ -88,17 +88,16 @@
8888
<dependency>
8989
<groupId>org.kohsuke</groupId>
9090
<artifactId>github-api</artifactId>
91-
<version>1.73</version>
91+
<version>1.76</version>
9292
</dependency>
93-
94-
<!-- unit tests -->
9593
<!-- Override version used by GitHub API -->
9694
<dependency>
9795
<groupId>commons-io</groupId>
9896
<artifactId>commons-io</artifactId>
9997
<version>2.4</version>
100-
<scope>test</scope>
10198
</dependency>
99+
100+
<!-- unit tests -->
102101
<dependency>
103102
<groupId>junit</groupId>
104103
<artifactId>junit</artifactId>
@@ -117,12 +116,6 @@
117116
<version>1.9.5</version>
118117
<scope>test</scope>
119118
</dependency>
120-
<dependency>
121-
<groupId>ch.qos.logback</groupId>
122-
<artifactId>logback-classic</artifactId>
123-
<version>1.1.2</version>
124-
<scope>test</scope>
125-
</dependency>
126119
</dependencies>
127120

128121
</project>

src/main/java/org/sonar/plugins/github/GitHubPlugin.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@
1919
*/
2020
package org.sonar.plugins.github;
2121

22-
import java.util.Arrays;
23-
import java.util.List;
2422
import org.sonar.api.CoreProperties;
23+
import org.sonar.api.Plugin;
2524
import org.sonar.api.Properties;
2625
import org.sonar.api.Property;
2726
import org.sonar.api.PropertyType;
28-
import org.sonar.api.SonarPlugin;
2927

3028
@Properties({
3129
@Property(
@@ -63,7 +61,7 @@
6361
global = true,
6462
type = PropertyType.BOOLEAN)
6563
})
66-
public class GitHubPlugin extends SonarPlugin {
64+
public class GitHubPlugin implements Plugin {
6765

6866
public static final String GITHUB_ENDPOINT = "sonar.github.endpoint";
6967
public static final String GITHUB_OAUTH = "sonar.github.oauth";
@@ -72,14 +70,12 @@ public class GitHubPlugin extends SonarPlugin {
7270
public static final String GITHUB_DISABLE_INLINE_COMMENTS = "sonar.github.disableInlineComments";
7371

7472
@Override
75-
public List getExtensions() {
76-
return Arrays.asList(
73+
public void define(Context context) {
74+
context.addExtensions(
7775
PullRequestIssuePostJob.class,
7876
GitHubPluginConfiguration.class,
7977
PullRequestProjectBuilder.class,
8078
PullRequestFacade.class,
81-
InputFileCacheSensor.class,
82-
InputFileCache.class,
8379
MarkDownUtils.class);
8480
}
8581

src/main/java/org/sonar/plugins/github/GitHubPluginConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
import java.util.regex.Matcher;
2323
import java.util.regex.Pattern;
2424
import javax.annotation.CheckForNull;
25-
import org.sonar.api.BatchComponent;
2625
import org.sonar.api.CoreProperties;
26+
import org.sonar.api.batch.BatchSide;
2727
import org.sonar.api.batch.InstantiationStrategy;
2828
import org.sonar.api.config.Settings;
2929
import org.sonar.api.utils.MessageException;
3030

3131
import static org.apache.commons.lang.StringUtils.isNotBlank;
3232

33+
@BatchSide
3334
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
34-
public class GitHubPluginConfiguration implements BatchComponent {
35+
public class GitHubPluginConfiguration {
3536

3637
public static final int MAX_GLOBAL_ISSUES = 10;
3738

src/main/java/org/sonar/plugins/github/GlobalReport.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
*/
2020
package org.sonar.plugins.github;
2121

22-
import com.google.common.annotations.VisibleForTesting;
22+
import java.util.Locale;
2323
import javax.annotation.Nullable;
2424
import org.kohsuke.github.GHCommitState;
25-
import org.sonar.api.issue.Issue;
26-
import org.sonar.api.rule.Severity;
25+
import org.sonar.api.batch.postjob.issue.PostJobIssue;
26+
import org.sonar.api.batch.rule.Severity;
2727

2828
public class GlobalReport {
2929
private final MarkDownUtils markDownUtils;
3030
private final boolean tryReportIssuesInline;
31-
private int[] newIssuesBySeverity = new int[Severity.ALL.size()];
31+
private int[] newIssuesBySeverity = new int[Severity.values().length];
3232
private StringBuilder notReportedOnDiff = new StringBuilder();
3333
private int extraIssueCount = 0;
3434
private int maxGlobalReportedIssues;
@@ -37,15 +37,14 @@ public GlobalReport(MarkDownUtils markDownUtils, boolean tryReportIssuesInline)
3737
this(markDownUtils, tryReportIssuesInline, GitHubPluginConfiguration.MAX_GLOBAL_ISSUES);
3838
}
3939

40-
@VisibleForTesting
4140
public GlobalReport(MarkDownUtils markDownUtils, boolean tryReportIssuesInline, int maxGlobalReportedIssues) {
4241
this.markDownUtils = markDownUtils;
4342
this.tryReportIssuesInline = tryReportIssuesInline;
4443
this.maxGlobalReportedIssues = maxGlobalReportedIssues;
4544
}
4645

47-
private void increment(String severity) {
48-
this.newIssuesBySeverity[Severity.ALL.indexOf(severity)]++;
46+
private void increment(org.sonar.api.batch.rule.Severity severity) {
47+
this.newIssuesBySeverity[severity.ordinal()]++;
4948
}
5049

5150
public String formatForMarkdown() {
@@ -78,7 +77,8 @@ public String formatForMarkdown() {
7877
sb.append(extraCount).append(" extra issue").append(extraCount > 1 ? "s" : "").append("\n");
7978
}
8079
sb.append(
81-
"\nNote: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:\n");
80+
"\nNote: The following issues were found on lines that were not modified in the pull request. "
81+
+ "Because these issues can't be reported as line comments, they are summarized here:\n");
8282
} else if (extraIssuesTruncated) {
8383
sb.append("\n#### Top ").append(maxGlobalReportedIssues).append(" issues\n");
8484
}
@@ -99,8 +99,8 @@ public GHCommitState getStatus() {
9999
return (newIssues(Severity.BLOCKER) > 0 || newIssues(Severity.CRITICAL) > 0) ? GHCommitState.ERROR : GHCommitState.SUCCESS;
100100
}
101101

102-
private int newIssues(String s) {
103-
return newIssuesBySeverity[Severity.ALL.indexOf(s)];
102+
private int newIssues(Severity s) {
103+
return newIssuesBySeverity[s.ordinal()];
104104
}
105105

106106
private void printSummaryBySeverityMarkdown(StringBuilder sb) {
@@ -128,26 +128,27 @@ private void printNewIssuesInline(StringBuilder sb) {
128128
}
129129
}
130130

131-
private void printNewIssuesInline(StringBuilder sb, String severity) {
131+
private void printNewIssuesInline(StringBuilder sb, Severity severity) {
132132
int issueCount = newIssues(severity);
133133
if (issueCount > 0) {
134134
if (sb.charAt(sb.length() - 1) == ',') {
135135
sb.append(" with ");
136136
} else {
137137
sb.append(" and ");
138138
}
139-
sb.append(issueCount).append(" ").append(severity.toLowerCase());
139+
sb.append(issueCount).append(" ").append(severity.name().toLowerCase(Locale.ENGLISH));
140140
}
141141
}
142142

143-
private void printNewIssuesForMarkdown(StringBuilder sb, String severity) {
143+
private void printNewIssuesForMarkdown(StringBuilder sb, Severity severity) {
144144
int issueCount = newIssues(severity);
145145
if (issueCount > 0) {
146-
sb.append("* ").append(MarkDownUtils.getImageMarkdownForSeverity(severity)).append(" ").append(issueCount).append(" ").append(severity.toLowerCase()).append("\n");
146+
sb.append("* ").append(MarkDownUtils.getImageMarkdownForSeverity(severity)).append(" ").append(issueCount).append(" ").append(severity.name().toLowerCase(Locale.ENGLISH))
147+
.append("\n");
147148
}
148149
}
149150

150-
public void process(Issue issue, @Nullable String githubUrl, boolean reportedOnDiff) {
151+
public void process(PostJobIssue issue, @Nullable String githubUrl, boolean reportedOnDiff) {
151152
increment(issue.severity());
152153
if (!reportedOnDiff) {
153154
if (extraIssueCount < maxGlobalReportedIssues) {

src/main/java/org/sonar/plugins/github/InputFileCache.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/main/java/org/sonar/plugins/github/InputFileCacheSensor.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/main/java/org/sonar/plugins/github/IssueComparator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import java.util.Comparator;
2323
import java.util.Objects;
2424
import javax.annotation.Nullable;
25-
import org.sonar.api.issue.Issue;
26-
import org.sonar.api.rule.Severity;
25+
import org.sonar.api.batch.postjob.issue.PostJobIssue;
26+
import org.sonar.api.batch.rule.Severity;
2727

28-
public final class IssueComparator implements Comparator<Issue> {
28+
public final class IssueComparator implements Comparator<PostJobIssue> {
2929
@Override
30-
public int compare(Issue left, Issue right) {
30+
public int compare(PostJobIssue left, PostJobIssue right) {
3131
// Most severe issues should be displayed first.
3232
if (left == right) {
3333
return 0;
@@ -46,15 +46,15 @@ public int compare(Issue left, Issue right) {
4646
return compareSeverity(left.severity(), right.severity());
4747
}
4848

49-
private static int compareComponentKeyAndLine(Issue left, Issue right) {
49+
private static int compareComponentKeyAndLine(PostJobIssue left, PostJobIssue right) {
5050
if (!left.componentKey().equals(right.componentKey())) {
5151
return left.componentKey().compareTo(right.componentKey());
5252
}
5353
return compareInt(left.line(), right.line());
5454
}
5555

56-
private static int compareSeverity(String leftSeverity, String rightSeverity) {
57-
if (Severity.ALL.indexOf(leftSeverity) > Severity.ALL.indexOf(rightSeverity)) {
56+
private static int compareSeverity(Severity leftSeverity, Severity rightSeverity) {
57+
if (leftSeverity.ordinal() > rightSeverity.ordinal()) {
5858
// Display higher severity first. Relies on Severity.ALL to be sorted by severity.
5959
return -1;
6060
} else {

0 commit comments

Comments
 (0)