Skip to content

Commit

Permalink
SLLS-292 use latest analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Jan 2, 2025
1 parent a7c976a commit 5b4fe65
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 34 deletions.
31 changes: 20 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
<!-- Version used by Xodus -->
<kotlin.version>1.6.10</kotlin.version>
<!-- analyzers used for tests -->
<sonar.java.version>7.33.0.35775</sonar.java.version>
<sonar.javascript.version>10.13.0.25911</sonar.javascript.version>
<sonar.php.version>3.35.0.11659</sonar.php.version>
<sonar.python.version>4.17.0.14845</sonar.python.version>
<sonar.html.version>3.16.0.5274</sonar.html.version>
<sonar.xml.version>2.10.0.4108</sonar.xml.version>
<sonar.text.version>2.18.0.4812</sonar.text.version>
<sonar.go.version>1.15.0.4655</sonar.go.version>
<sonar.iac.version>1.27.0.9518</sonar.iac.version>
<sonar.csharp.version>10.2.0.103721</sonar.csharp.version>
<sonar.java.version>8.8.0.37665</sonar.java.version>
<sonar.javascript.version>10.20.0.29356</sonar.javascript.version>
<sonar.php.version>3.41.0.12692</sonar.php.version>
<sonar.python.version>4.25.0.19056</sonar.python.version>
<sonar.html.version>3.18.0.5605</sonar.html.version>
<sonar.xml.version>2.12.0.5749</sonar.xml.version>
<sonar.text.version>2.20.0.5038</sonar.text.version>
<sonar.go.version>1.18.0.240</sonar.go.version>
<sonar.iac.version>1.40.0.13983</sonar.iac.version>
<sonar.csharp.version>10.3.0.106239</sonar.csharp.version>
<sonarlint.omnisharp.version>1.25.0.100242</sonarlint.omnisharp.version>
<gitRepositoryName>sonarlint-language-server</gitRepositoryName>
<!-- Release: enable publication to Bintray -->
Expand Down Expand Up @@ -205,6 +205,15 @@
<outputDirectory>${project.build.directory}/plugins</outputDirectory>
<destFileName>sonarjava.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-symbolic-execution-plugin</artifactId>
<version>${sonar.java.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/plugins</outputDirectory>
<destFileName>sonarjavasymbolicexecution.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.sonarsource.javascript</groupId>
<artifactId>sonar-javascript-plugin</artifactId>
Expand Down Expand Up @@ -426,7 +435,7 @@
<artifactItem>
<groupId>com.sonarsource.cpp</groupId>
<artifactId>sonar-cfamily-plugin</artifactId>
<version>6.56.0.72172</version>
<version>6.62.0.78645</version>
<destFileName>cfamily.jar</destFileName>
<type>jar</type>
</artifactItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ static void startServer() throws Exception {
var iac = fullPathToJar("sonariac");
var html = fullPathToJar("sonarhtml");
var java = fullPathToJar("sonarjava");
var javasymbolicexecution = fullPathToJar("sonarjavasymbolicexecution");
var js = fullPathToJar("sonarjs");
var php = fullPathToJar("sonarphp");
var py = fullPathToJar("sonarpython");
var text = fullPathToJar("sonartext");
var xml = fullPathToJar("sonarxml");
var omnisharp = fullPathToJar("sonarlintomnisharp");
String[] languageServerArgs = new String[]{"-port", "" + port, "-analyzers", go, java, js, php, py, html, xml, text, iac, omnisharp};
String[] languageServerArgs = new String[]{"-port", "" + port, "-analyzers", go, java, javasymbolicexecution, js, php, py, html, xml, text, iac, omnisharp};
if (COMMERCIAL_ENABLED) {
var cfamily = fullPathToJar("cfamily");
languageServerArgs = ArrayUtils.add(languageServerArgs, cfamily);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,23 @@ void analyseJavaFilesAsNonJavaIfNoClasspath() throws Exception {

client.javaConfigs.put(uri, null);

didOpen(uri, "java", "public class Foo {\n public static final String AWS_SECRET_KEY = \"AKIAIGKECZXA7EXAMPLF\";\n public static void main() {\n // System.out.println(\"foo\");\n }\n}");
didOpen(uri, "java", """
public class Foo {
public static final String KEY = "AKIAIGKECZXA7AEIJKMQ";
public static final String AWS_SECRET_ACCESS_KEY = "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";
public static void main() {
// System.out.println("foo");
}
}
""");

awaitUntilAsserted(() -> assertThat(client.getDiagnostics(uri))
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
tuple(0, 13, 0, 16, "java:S1118", "sonarqube", "Add a private constructor to hide the implicit public one.", DiagnosticSeverity.Warning),
tuple(0, 15, 0, 18, "java:S1118", "sonarqube", "Add a private constructor to hide the implicit public one.", DiagnosticSeverity.Warning),
tuple(0, 0, 0, 0, "java:S1220", "sonarqube", "Move this file to a named package.", DiagnosticSeverity.Warning),
tuple(1, 46, 1, 66, "secrets:S6290", "sonarqube", "Make sure the access granted with this AWS access key ID is restricted", DiagnosticSeverity.Warning),
tuple(3, 5, 3, 31, "java:S125", "sonarqube", "This block of commented-out lines of code should be removed.", DiagnosticSeverity.Warning)));
tuple(2, 56, 2, 96, "secrets:S6290", "sonarqube", "Make sure this AWS Secret Access Key gets revoked, changed, and removed from the code.", DiagnosticSeverity.Warning),
tuple(4, 9, 4, 35, "java:S125", "sonarqube", "This block of commented-out lines of code should be removed.", DiagnosticSeverity.Warning)));
awaitUntilAsserted(() -> assertThat(client.logs)
.extracting(withoutTimestamp())
.contains(
Expand Down Expand Up @@ -167,19 +175,21 @@ void analyzeSimpleJavaFileWithFlows() throws Exception {
client.javaConfigs.put(uri, javaConfigResponse);

didOpen(uri, "java",
"public class AnalyzeSimpleJavaFileWithFlows {\n" +
" private AnalyzeSimpleJavaFileWithFlows() {}\n" +
" static int computeValue(int input) {\n" +
" String message = \"polop\";\n" +
" if (input == 42) {\n" +
" message = null;\n" +
" }\n" +
" return doSomeThingWith(message);\n" +
" }\n" +
" private static int doSomeThingWith(String param) {\n" +
" return param.length();\n" +
" }\n" +
"}");
"""
public class AnalyzeSimpleJavaFileWithFlows {
private AnalyzeSimpleJavaFileWithFlows() {}
static int computeValue(int input) {
String message = "polop";
if (input == 42) {
message = null;
}
return doSomeThingWith(message);
}
private static int doSomeThingWith(String param) {
return param.length();
}
}
""");

awaitUntilAsserted(() -> assertThat(client.getDiagnostics(uri))
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
Expand Down Expand Up @@ -242,7 +252,7 @@ void analyzeSimpleJavaTestFileOnOpen() throws Exception {

awaitUntilAsserted(() -> assertThat(client.getDiagnostics(uri))
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
.contains(
tuple(3, 14, 3, 18, "java:S2699", "sonarqube", "Add at least one assertion to this test case.", DiagnosticSeverity.Warning)));
}

Expand Down Expand Up @@ -270,16 +280,20 @@ void testClassPathUpdateEvictCacheAndTriggersNewAnalysis(@TempDir Path projectRo

awaitUntilAsserted(() -> assertThat(client.logs)
.extracting(withoutTimestampAndMillis())
.contains("[Info] Analysis detected 0 issues and 0 Security Hotspots in XXXms"));
.contains("[Info] Analysis detected 2 issues and 0 Security Hotspots in XXXms"));
client.logs.clear();

// Update classpath
javaConfigResponse.setClasspath(new String[]{Paths.get(this.getClass().getResource("/junit-4.12.jar").toURI()).toAbsolutePath().toString()});
lsProxy.didClasspathUpdate(new DidClasspathUpdateParams(projectRootUri2));

awaitUntilAsserted(() -> assertThat(client.logs)
.extracting(withoutTimestampAndMillis())
.contains("[Info] Analysis detected 3 issues and 0 Security Hotspots in XXXms"));

awaitUntilAsserted(() -> assertThat(client.getDiagnostics(uri))
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactlyInAnyOrder(
.contains(
tuple(3, 14, 3, 18, "java:S2699", "sonarqube", "Add at least one assertion to this test case.", DiagnosticSeverity.Warning)));

assertThat(client.logs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ void analyzeSimpleDockerFileOnOpen() throws Exception {
awaitUntilAsserted(() -> assertThat(client.getDiagnostics(uri))
.extracting(startLine(), startCharacter(), endLine(), endCharacter(), code(), Diagnostic::getSource, Diagnostic::getMessage, Diagnostic::getSeverity)
.containsExactly(
tuple(0, 18, 0, 20, DOCKER_S6476, "sonarqube", "Replace `as` with upper case format `AS`.", DiagnosticSeverity.Warning),
tuple(0, 0, 0, 4, DOCKER_S6476, "sonarqube", "Replace `from` with upper case format `FROM`.", DiagnosticSeverity.Warning)));
tuple(0, 18, 0, 20, DOCKER_S6476, "sonarqube", "Replace \"as\" with upper case format \"AS\".", DiagnosticSeverity.Warning),
tuple(0, 0, 0, 4, DOCKER_S6476, "sonarqube", "Replace \"from\" with upper case format \"FROM\".", DiagnosticSeverity.Warning)));
}

@Test
Expand Down

0 comments on commit 5b4fe65

Please sign in to comment.