From c360a20c4d08eca10db9a702d619fd0c3bc5e1ad Mon Sep 17 00:00:00 2001 From: Dorian Burihabwa Date: Mon, 10 Jun 2024 15:04:27 +0200 Subject: [PATCH] [NO-JIRA] Upgrade sonar-scanner-java-library to version 3.0.1.175 --- build.gradle.kts | 2 +- .../sonarqube/gradle/AbstractGradleIT.java | 2 +- .../gradle/SonarPropertyComputer.java | 6 ++-- .../java/org/sonarqube/gradle/SonarTask.java | 19 ++++++----- .../sonarqube/gradle/FunctionalTests.groovy | 32 +++++++++---------- .../sonarqube/gradle/GradleKtsTests.groovy | 16 +++++----- 6 files changed, 40 insertions(+), 37 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index ff6ca941..c11b7c4c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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") diff --git a/integrationTests/src/test/java/org/sonarqube/gradle/AbstractGradleIT.java b/integrationTests/src/test/java/org/sonarqube/gradle/AbstractGradleIT.java index c4c79752..c605ef06 100644 --- a/integrationTests/src/test/java/org/sonarqube/gradle/AbstractGradleIT.java +++ b/integrationTests/src/test/java/org/sonarqube/gradle/AbstractGradleIT.java @@ -79,7 +79,7 @@ protected Properties runGradlewSonarSimulationModeWithEnv(String project, Map 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); diff --git a/src/main/java/org/sonarqube/gradle/SonarPropertyComputer.java b/src/main/java/org/sonarqube/gradle/SonarPropertyComputer.java index a1b76517..5c657683 100644 --- a/src/main/java/org/sonarqube/gradle/SonarPropertyComputer.java +++ b/src/main/java/org/sonarqube/gradle/SonarPropertyComputer.java @@ -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; @@ -218,8 +218,8 @@ private static void configureSourceEncoding(Project project, final Map properties) { - for (Map.Entry e : Utils.loadEnvironmentProperties(System.getenv()).entrySet()) { - properties.put(e.getKey().toString(), e.getValue().toString()); + for (Map.Entry e : EnvironmentConfig.load(System.getenv()).entrySet()) { + properties.put(e.getKey(), e.getValue()); } } diff --git a/src/main/java/org/sonarqube/gradle/SonarTask.java b/src/main/java/org/sonarqube/gradle/SonarTask.java index ad87f804..b0b6501c 100644 --- a/src/main/java/org/sonarqube/gradle/SonarTask.java +++ b/src/main/java/org/sonarqube/gradle/SonarTask.java @@ -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 SonarQube Scanner. @@ -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() { @@ -142,7 +145,7 @@ private String getPluginVersion() { } private static boolean isSkippedWithProperty(Map 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; } diff --git a/src/test/groovy/org/sonarqube/gradle/FunctionalTests.groovy b/src/test/groovy/org/sonarqube/gradle/FunctionalTests.groovy index 3c3838a4..1b8fd2dc 100644 --- a/src/test/groovy/org/sonarqube/gradle/FunctionalTests.groovy +++ b/src/test/groovy/org/sonarqube/gradle/FunctionalTests.groovy @@ -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") @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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' @@ -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" @@ -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" @@ -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() diff --git a/src/test/groovy/org/sonarqube/gradle/GradleKtsTests.groovy b/src/test/groovy/org/sonarqube/gradle/GradleKtsTests.groovy index ef04c7ee..21f12b47 100644 --- a/src/test/groovy/org/sonarqube/gradle/GradleKtsTests.groovy +++ b/src/test/groovy/org/sonarqube/gradle/GradleKtsTests.groovy @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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()