Skip to content

Commit

Permalink
[NO-JIRA] Upgrade sonar-scanner-java-library to version 3.0.1.175
Browse files Browse the repository at this point in the history
  • Loading branch information
dorian-burihabwa-sonarsource committed Jun 10, 2024
1 parent c9c8fa9 commit c360a20
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ repositories {
}

dependencies {
implementation("org.sonarsource.scanner.api:sonar-scanner-api:2.16.3.1081")
implementation("org.sonarsource.scanner.lib:sonar-scanner-java-library:3.0.1.175")
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
compileOnly("com.android.tools.build:gradle:8.1.1")
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected Properties runGradlewSonarSimulationModeWithEnv(String project, Map<St
protected Properties runGradlewSonarSimulationModeWithEnv(String project, String exeRelativePath, Map<String, String> env, String... args) throws Exception {
File out = temp.newFile();
String[] newArgs = Stream.concat(
Stream.of("-Dsonar.scanner.dumpToFile=" + out.getAbsolutePath()),
Stream.of("-Dsonar.scanner.internal.dumpToFile=" + out.getAbsolutePath()),
Arrays.stream(args))
.toArray(String[]::new);
runGradlewSonarWithEnv(project, exeRelativePath, env, newArgs);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/sonarqube/gradle/SonarPropertyComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import org.gradle.api.tasks.testing.Test;
import org.gradle.testing.jacoco.tasks.JacocoReport;
import org.gradle.util.GradleVersion;
import org.sonarsource.scanner.api.Utils;
import org.sonarsource.scanner.lib.EnvironmentConfig;

import static org.sonarqube.gradle.SonarUtils.appendProp;
import static org.sonarqube.gradle.SonarUtils.exists;
Expand Down Expand Up @@ -218,8 +218,8 @@ private static void configureSourceEncoding(Project project, final Map<String, O
}

private static void addEnvironmentProperties(Map<String, Object> properties) {
for (Map.Entry<Object, Object> e : Utils.loadEnvironmentProperties(System.getenv()).entrySet()) {
properties.put(e.getKey().toString(), e.getValue().toString());
for (Map.Entry<String, String> e : EnvironmentConfig.load(System.getenv()).entrySet()) {
properties.put(e.getKey(), e.getValue());
}
}

Expand Down
19 changes: 11 additions & 8 deletions src/main/java/org/sonarqube/gradle/SonarTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.TaskAction;
import org.gradle.util.GradleVersion;
import org.sonarsource.scanner.api.EmbeddedScanner;
import org.sonarsource.scanner.api.LogOutput;
import org.sonarsource.scanner.api.ScanProperties;
import org.sonarsource.scanner.lib.ScannerEngineBootstrapper;
import org.sonarsource.scanner.lib.ScannerEngineFacade;
import org.sonarsource.scanner.lib.internal.batch.LogOutput;

/**
* Analyses one or more projects with the <a href="http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle">SonarQube Scanner</a>.
Expand Down Expand Up @@ -125,10 +125,13 @@ public void run() {
return;
}

EmbeddedScanner scanner = EmbeddedScanner.create("ScannerGradle", getPluginVersion() + "/" + GradleVersion.current(), getLogOutput())
.addGlobalProperties(mapProperties);
scanner.start();
scanner.execute(new HashMap<>());
ScannerEngineBootstrapper scanner = ScannerEngineBootstrapper.create("ScannerGradle", getPluginVersion() + "/" + GradleVersion.current())
.addBootstrapProperties(mapProperties);
try (ScannerEngineFacade engineFacade = scanner.bootstrap()) {
engineFacade.analyze(new HashMap<>());
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private String getPluginVersion() {
Expand All @@ -142,7 +145,7 @@ private String getPluginVersion() {
}

private static boolean isSkippedWithProperty(Map<String, String> properties) {
if ("true".equalsIgnoreCase(properties.getOrDefault(ScanProperties.SKIP, "false"))) {
if ("true".equalsIgnoreCase(properties.getOrDefault("sonar.skip", "false"))) {
LOGGER.warn("Sonar Scanner analysis skipped");
return true;
}
Expand Down
32 changes: 16 additions & 16 deletions src/test/groovy/org/sonarqube/gradle/FunctionalTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class FunctionalTests extends Specification {
def result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

then:
result.task(":sonarqube").outcome == SUCCESS
result.task(":sonar").outcome == SUCCESS
def props = new Properties()
props.load(outFile.newDataInputStream())
!props.containsKey("sonar.java.jdkHome")
Expand Down Expand Up @@ -94,12 +94,12 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

then:
result.task(":sonarqube").outcome == SUCCESS
result.task(":sonar").outcome == SUCCESS
def props = new Properties()
props.load(outFile.newDataInputStream())
new File(props."sonar.java.jdkHome").exists()
Expand Down Expand Up @@ -128,7 +128,7 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonar', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand Down Expand Up @@ -158,7 +158,7 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonar', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand All @@ -183,7 +183,7 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand Down Expand Up @@ -212,13 +212,13 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

then:
result.output.contains('Heterogeneous compiler configuration has been detected. Using compiler configuration from task: \'compileJava\'')
result.task(":sonarqube").outcome == SUCCESS
result.task(":sonar").outcome == SUCCESS
def props = new Properties()
props.load(outFile.newDataInputStream())
new File(props."sonar.java.jdkHome").exists()
Expand Down Expand Up @@ -248,12 +248,12 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

then:
result.task(":sonarqube").outcome == SUCCESS
result.task(":sonar").outcome == SUCCESS
def props = new Properties()
props.load(outFile.newDataInputStream())
props."sonar.java.source" == '8'
Expand Down Expand Up @@ -283,12 +283,12 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

then:
result.task(":sonarqube").outcome == SUCCESS
result.task(":sonar").outcome == SUCCESS
def props = new Properties()
props.load(outFile.newDataInputStream())
props."sonar.java.enablePreview" == "true"
Expand All @@ -315,12 +315,12 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

then:
result.task(":sonarqube").outcome == SUCCESS
result.task(":sonar").outcome == SUCCESS
def props = new Properties()
props.load(outFile.newDataInputStream())
props."sonar.java.enablePreview" == "true"
Expand All @@ -347,7 +347,7 @@ class FunctionalTests extends Specification {
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonar', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand Down
16 changes: 8 additions & 8 deletions src/test/groovy/org/sonarqube/gradle/GradleKtsTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GradleKtsTests extends Specification {
def result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand All @@ -74,7 +74,7 @@ class GradleKtsTests extends Specification {
def result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand All @@ -95,7 +95,7 @@ class GradleKtsTests extends Specification {
def result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand All @@ -115,7 +115,7 @@ class GradleKtsTests extends Specification {
def result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand All @@ -136,7 +136,7 @@ class GradleKtsTests extends Specification {
def result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand All @@ -156,7 +156,7 @@ class GradleKtsTests extends Specification {
def result = GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand All @@ -178,7 +178,7 @@ class GradleKtsTests extends Specification {
GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand Down Expand Up @@ -208,7 +208,7 @@ class GradleKtsTests extends Specification {
GradleRunner.create()
.withProjectDir(testProjectDir.toFile())
.forwardOutput()
.withArguments('sonarqube', '--info', '-Dsonar.scanner.dumpToFile=' + outFile.toAbsolutePath())
.withArguments('sonarqube', '--info', '-Dsonar.scanner.internal.dumpToFile=' + outFile.toAbsolutePath())
.withPluginClasspath()
.build()

Expand Down

0 comments on commit c360a20

Please sign in to comment.