Skip to content

Commit c02dcde

Browse files
Upgrade libs (#39)
* Upgrade java plugin * Upgrade sonar libs and adjust interfaces
1 parent 0db85cd commit c02dcde

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

build.gradle

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ build.dependsOn(infra)
3232
test.dependsOn(infra)
3333

3434
dependencies {
35-
compile("org.sonarsource.sonarlint.core:sonarlint-core:2.10.0.367")
36-
compile("org.sonarsource.sonarlint.core:sonarlint-client-api:2.10.0.367")
35+
compile("org.sonarsource.sonarlint.core:sonarlint-core:2.17.0.899")
36+
compile("org.sonarsource.sonarlint.core:sonarlint-client-api:2.17.0.899")
3737
compile("org.sonarsource.sonarlint:sonarlint-cli:2.1.0.566")
38-
compile("com.google.code.gson:gson:2.6.2")
39-
38+
compile("com.google.code.gson:gson:2.8.2")
4039

4140
// Plugins
42-
compile("org.sonarsource.java:sonar-java-plugin:4.3.0.7717")
41+
compile("org.sonarsource.java:sonar-java-plugin:4.14.0.11784")
4342

4443
testCompile("org.assertj:assertj-core:2.8.0")
4544
testCompile("org.skyscreamer:jsonassert:1.5.0")

src/main/java/cc/analysis/SonarLintFactory.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.nio.file.Path;
1212

1313
public class SonarLintFactory extends org.sonarlint.cli.analysis.SonarLintFactoryWrapper {
14-
private static final Logger LOGGER = Logger.get();
1514
private Path workDir;
1615

1716
public SonarLintFactory(ConfigurationReader reader, Path workDir) {
@@ -21,14 +20,14 @@ public SonarLintFactory(ConfigurationReader reader, Path workDir) {
2120

2221
@Override
2322
public SonarLint createSonarLint(Path projectHome, boolean mustBeConnected, boolean verbose) {
24-
LOGGER.info("Standalone mode");
23+
LogOutputWrapper logWrapper = new LogOutputWrapper(verbose);
2524

2625
StandaloneGlobalConfiguration config = StandaloneGlobalConfiguration.builder()
2726
.addPlugins(plugins())
28-
.setLogOutput(new LogOutputWrapper(LOGGER, verbose))
27+
.setLogOutput(logWrapper)
2928
.build();
3029

3130
StandaloneSonarLintEngine engine = new StandaloneSonarLintEngineImpl(config);
32-
return new StandaloneSonarLint(engine, workDir);
31+
return new StandaloneSonarLint(engine, workDir, logWrapper);
3332
}
3433
}

src/main/java/cc/analysis/StandaloneSonarLint.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package cc.analysis;
22

33
import org.sonarlint.cli.analysis.IssueCollector;
4+
import org.sonarlint.cli.analysis.LogOutputWrapper;
45
import org.sonarlint.cli.report.ReportFactory;
6+
import org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor;
57
import org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults;
68
import org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile;
79
import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration;
@@ -19,11 +21,13 @@
1921
public class StandaloneSonarLint extends org.sonarlint.cli.analysis.StandaloneSonarLint {
2022
private StandaloneSonarLintEngine engine;
2123
private Path workDir;
24+
private LogOutputWrapper logWrapper;
2225

23-
public StandaloneSonarLint(StandaloneSonarLintEngine engine, Path workDir) {
26+
public StandaloneSonarLint(StandaloneSonarLintEngine engine, Path workDir, LogOutputWrapper logWrapper) {
2427
super(engine);
2528
this.engine = engine;
2629
this.workDir = workDir;
30+
this.logWrapper = logWrapper;
2731
}
2832

2933
@Override
@@ -32,8 +36,11 @@ protected void doAnalysis(Map<String, String> properties, ReportFactory reportFa
3236

3337
IssueCollector collector = new IssueCollector();
3438
StandaloneAnalysisConfiguration config = new StandaloneAnalysisConfiguration(baseDirPath, workDir, inputFiles, properties);
35-
AnalysisResults result = engine.analyze(config, collector);
39+
AnalysisResults result = engine.analyze(config, collector, logWrapper, new NoOpProgressMonitor());
3640
Collection<Trackable> trackables = collector.get().stream().map(IssueTrackable::new).collect(Collectors.toList());
3741
generateReports(trackables, result, reportFactory, baseDirPath.getFileName().toString(), baseDirPath, start);
3842
}
43+
44+
private static class NoOpProgressMonitor extends ProgressMonitor {
45+
}
3946
}

src/main/java/org/sonarlint/cli/analysis/LogOutputWrapper.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import org.sonarlint.cli.util.Logger;
44

55
public class LogOutputWrapper extends DefaultLogOutput {
6-
public LogOutputWrapper(Logger logger, boolean verbose) {
7-
super(logger, verbose);
6+
7+
public LogOutputWrapper(boolean verbose) {
8+
super(Logger.get(), verbose);
89
}
910
}

src/test/java/support/fakes/FakeTrackable.java

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public String getMessage() {
3939
return null;
4040
}
4141

42+
@CheckForNull
43+
@Override
44+
public String getType() {
45+
return null;
46+
}
47+
4248
@CheckForNull
4349
@Override
4450
public Integer getLine() {

src/test/resources/sanity_check_expected_issues.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "issue",
44
"check_name": "squid:S106",
55
"severity": "major",
6-
"description": "Replace this usage of System.out or System.err by a logger.",
6+
"description": "Replace this use of System.out or System.err by a logger.",
77
"content": {
88
"body": "<p>When logging a message there are several important requirements which must be fulfilled:</p>\n<ul>\n <li> The user must be able to easily retrieve the logs </li>\n <li> The format of all logged message must be uniform to allow the user to easily read the log </li>\n <li> Logged data must actually be recorded </li>\n <li> Sensitive data must only be logged securely </li>\n</ul>\n<p>If a program directly writes to the standard outputs, there is absolutely no way to comply with those requirements. That's why defining and using a\ndedicated logger is highly recommended.</p>\n<h2>Noncompliant Code Example</h2>\n<pre>\nSystem.out.println(\"My Message\"); // Noncompliant\n</pre>\n<h2>Compliant Solution</h2>\n<pre>\nlogger.log(\"My Message\");\n</pre>\n<h2>See</h2>\n<ul>\n <li> <a href=\"https://www.securecoding.cert.org/confluence/x/RoElAQ\">CERT, ERR02-J.</a> - Prevent exceptions while logging data </li>\n</ul>"
99
},
@@ -58,7 +58,7 @@
5858
"severity": "critical",
5959
"description": "Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.",
6060
"content": {
61-
"body": "<p>There are several reasons for a method not to have a method body:</p>\n<ul>\n <li> It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production. </li>\n <li> It is not yet, or never will be, supported. In this case an <code>UnsupportedOperationException</code> should be thrown. </li>\n <li> The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override. </li>\n <li> There is a desire to provide a public, no-args constructor. In this case, it can simply be omitted from the code; a default constructor will\n automatically be generated. </li>\n</ul>\n<h2>Noncompliant Code Example</h2>\n<pre>\npublic void doSomething() {\n}\n\npublic void doSomethingElse() {\n}\n</pre>\n<h2>Compliant Solution</h2>\n<pre>\n@Override\npublic void doSomething() {\n // Do nothing because of X and Y.\n}\n\n@Override\npublic void doSomethingElse() {\n throw new UnsupportedOperationException();\n}\n</pre>\n<h2>Exceptions</h2>\n<p>An abstract class may have empty methods, in order to provide default implementations for child classes.</p>\n<pre>\npublic abstract class Animal {\n void speak() {\n }\n}\n</pre>"
61+
"body": "<p>There are several reasons for a method not to have a method body:</p>\n<ul>\n <li> It is an unintentional omission, and should be fixed to prevent an unexpected behavior in production. </li>\n <li> It is not yet, or never will be, supported. In this case an <code>UnsupportedOperationException</code> should be thrown. </li>\n <li> The method is an intentionally-blank override. In this case a nested comment should explain the reason for the blank override. </li>\n</ul>\n<h2>Noncompliant Code Example</h2>\n<pre>\npublic void doSomething() {\n}\n\npublic void doSomethingElse() {\n}\n</pre>\n<h2>Compliant Solution</h2>\n<pre>\n@Override\npublic void doSomething() {\n // Do nothing because of X and Y.\n}\n\n@Override\npublic void doSomethingElse() {\n throw new UnsupportedOperationException();\n}\n</pre>\n<h2>Exceptions</h2>\n<p>Default (no-argument) constructors are ignored when there are other constructors in the class, as are empty methods in abstract classes.</p>\n<pre>\npublic abstract class Animal {\n void speak() { // default implementation ignored\n }\n}\n</pre>"
6262
},
6363
"location": {
6464
"path": "main/java/Library.java",

0 commit comments

Comments
 (0)