From a530f2b1b1adf82d76b9739c306215c59b714184 Mon Sep 17 00:00:00 2001 From: Marcin Stachniuk Date: Mon, 16 Dec 2024 16:34:51 +0100 Subject: [PATCH 1/2] SONARGO-79 Update sonar-orchestrator dependency --- .cirrus.yml | 2 + gradle/libs.versions.toml | 8 +- its/plugin/build.gradle.kts | 19 +++-- .../org/sonarsource/slang/CoverageTest.java | 7 +- .../sonarsource/slang/DuplicationsTest.java | 2 +- .../sonarsource/slang/ExternalReportTest.java | 19 +---- .../org/sonarsource/slang/MeasuresTest.java | 2 +- .../org/sonarsource/slang/NoSonarTest.java | 2 +- .../org/sonarsource/slang/SonarLintTest.java | 37 ++++------ .../java/org/sonarsource/slang/TestBase.java | 56 +++++++++++++- .../org/sonarsource/slang/TestReportTest.java | 7 +- .../java/org/sonarsource/slang/Tests.java | 73 ------------------- its/ruling/build.gradle.kts | 15 +++- .../org/sonarsource/slang/GoRulingTest.java | 41 +++-------- 14 files changed, 114 insertions(+), 176 deletions(-) delete mode 100644 its/plugin/src/integrationTest/java/org/sonarsource/slang/Tests.java diff --git a/.cirrus.yml b/.cirrus.yml index eca91538..bd717c3b 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -125,6 +125,7 @@ qa_plugin_task: env: ITS_PROJECT: "plugin" GRADLE_TASK: ":its:plugin:integrationTest" + KEEP_ORCHESTRATOR_RUNNING: "true" matrix: - SQ_VERSION: "DEV" - SQ_VERSION: "LATEST_RELEASE" @@ -139,6 +140,7 @@ qa_ruling_task: SQ_VERSION: "LATEST_RELEASE" GRADLE_TASK: ":its:ruling:integrationTest" ITS_PROJECT: "ruling" + KEEP_ORCHESTRATOR_RUNNING: "true" <<: *LINUX_4_CPU_8G <<: *GRADLE_ITS_TEMPLATE <<: *ON_FAILURE diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 83dcf2d4..d4a8ada8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,12 +3,14 @@ slang-dependencies = "1.17.0.6351" analyzer-commons = "2.16.0.3141" plugin-api = "10.10.0.2391" sonarqube = "10.0.0.68432" -orchestrator = "3.42.0.312" +orchestrator = "5.1.0.2254" sonarlint = "9.0.0.74282" minimal-json = "0.9.5" mockito-core = "5.13.0" assertj-core = "3.26.3" junit-jupiter = "5.11.0" +# slf4j is provided by SQ, SC or SL, should be aligned with sonar-plugin-api in integration tests +slf4j-api = "1.7.30" [libraries] sonar-plugin-api = { group = "org.sonarsource.api.plugin", name = "sonar-plugin-api", version.ref = "plugin-api" } @@ -20,7 +22,7 @@ checkstyle-import = { group = "org.sonarsource.slang", name = "checkstyle-import minimal-json = { group = "com.eclipsesource.minimal-json", name = "minimal-json", version.ref = "minimal-json" } sonar-plugin-api-test-fixtures = { group = "org.sonarsource.api.plugin", name = "sonar-plugin-api-test-fixtures", version.ref = "plugin-api" } sonar-plugin-api-impl = { group = "org.sonarsource.sonarqube", name = "sonar-plugin-api-impl", version.ref = "sonarqube" } -sonar-orchestrator = { group = "org.sonarsource.orchestrator", name = "sonar-orchestrator", version.ref = "orchestrator" } +sonar-orchestrator-junit5 = { group = "org.sonarsource.orchestrator", name = "sonar-orchestrator-junit5", version.ref = "orchestrator" } sonarlint-core = { group = "org.sonarsource.sonarlint.core", name = "sonarlint-core", version.ref = "sonarlint" } sonar-ws = { group = "org.sonarsource.sonarqube", name = "sonar-ws", version.ref = "sonarqube" } slang-antlr = { group = "org.sonarsource.slang", name = "slang-antlr", version.ref = "slang-dependencies" } @@ -29,4 +31,4 @@ mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mo assertj-core = { group = "org.assertj", name = "assertj-core", version.ref = "assertj-core" } junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit-jupiter" } junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit-jupiter" } -junit-vintage-engine = { group = "org.junit.vintage", name = "junit-vintage-engine", version.ref = "junit-jupiter" } +slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j-api" } diff --git a/its/plugin/build.gradle.kts b/its/plugin/build.gradle.kts index d9bf1938..09cb8870 100644 --- a/its/plugin/build.gradle.kts +++ b/its/plugin/build.gradle.kts @@ -5,23 +5,28 @@ plugins { } dependencies { + "integrationTestImplementation"(libs.slf4j.api) + "integrationTestImplementation"(project(":sonar-go-plugin", configuration = "shadow")) "integrationTestImplementation"(libs.sonar.analyzer.commons) "integrationTestImplementation"(libs.sonar.ws) "integrationTestImplementation"(libs.assertj.core) "integrationTestImplementation"(libs.sonarlint.core) - "integrationTestImplementation"(libs.sonar.orchestrator) - "integrationTestRuntimeOnly"(libs.junit.vintage.engine) + "integrationTestImplementation"(libs.sonar.orchestrator.junit5) { + exclude("ch.qos.logback", "logback-classic") + exclude("org.slf4j", "slf4j-api") + exclude("org.slf4j", "jcl-over-slf4j") + exclude("org.slf4j", "log4j-over-slf4j") + } + "integrationTestImplementation"(libs.junit.jupiter.api) + + "integrationTestRuntimeOnly"(libs.junit.jupiter.engine) } -sonarqube.isSkipProject = true +sonar.isSkipProject = true integrationTest { testSources.set(file("projects")) } tasks.named("integrationTest") { - filter { - includeTestsMatching("org.sonarsource.slang.Tests") - includeTestsMatching("org.sonarsource.slang.SonarLintTest") - } systemProperty("java.awt.headless", "true") } diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/CoverageTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/CoverageTest.java index 36bab640..9feba2f9 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/CoverageTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/CoverageTest.java @@ -19,9 +19,7 @@ import com.sonar.orchestrator.build.SonarScanner; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -29,9 +27,6 @@ public class CoverageTest extends TestBase { private static final Path BASE_DIRECTORY = Paths.get("projects", "measures"); - @Rule - public TemporaryFolder tmpDir = new TemporaryFolder(); - @Test public void go_coverage() { final String projectKey = "goCoverage"; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/DuplicationsTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/DuplicationsTest.java index 6a180623..a85bb764 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/DuplicationsTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/DuplicationsTest.java @@ -16,7 +16,7 @@ */ package org.sonarsource.slang; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/ExternalReportTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/ExternalReportTest.java index 084d49c7..11d07534 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/ExternalReportTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/ExternalReportTest.java @@ -17,28 +17,19 @@ package org.sonarsource.slang; import com.sonar.orchestrator.build.SonarScanner; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; import org.sonarqube.ws.Issues.Issue; import org.sonarqube.ws.client.issues.SearchRequest; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; public class ExternalReportTest extends TestBase { private static final String BASE_DIRECTORY = "projects/externalreport/"; - @Rule - public TemporaryFolder tmpDir = new TemporaryFolder(); - @Test public void govet() { final String projectKey = "govet"; @@ -119,14 +110,6 @@ private List getExternalIssues(String componentKey) { .collect(Collectors.toList()); } - private Path createTemporaryReportFromTemplate(Path sourceReportPath, String placeHolder, String newValue) throws IOException { - String reportContent = new String(Files.readAllBytes(sourceReportPath), UTF_8); - reportContent = reportContent.replace(placeHolder, newValue); - Path destReportPath = tmpDir.newFile(sourceReportPath.getFileName().toString()).toPath().toRealPath(); - Files.write(destReportPath, reportContent.getBytes(UTF_8)); - return destReportPath; - } - private static String formatIssues(List issues) { return issues.stream() .map(issue -> filePath(issue) + "|" + diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/MeasuresTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/MeasuresTest.java index 5fc09758..3b724843 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/MeasuresTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/MeasuresTest.java @@ -16,7 +16,7 @@ */ package org.sonarsource.slang; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/NoSonarTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/NoSonarTest.java index b19eeedb..aaf4d251 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/NoSonarTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/NoSonarTest.java @@ -16,7 +16,7 @@ */ package org.sonarsource.slang; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/SonarLintTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/SonarLintTest.java index 45487701..8d2704aa 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/SonarLintTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/SonarLintTest.java @@ -17,7 +17,6 @@ package org.sonarsource.slang; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.OrchestratorBuilder; import com.sonar.orchestrator.locator.Locators; import java.io.File; import java.io.IOException; @@ -33,11 +32,10 @@ import org.apache.commons.io.FileUtils; import org.assertj.core.groups.Tuple; import org.jetbrains.annotations.NotNull; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl; import org.sonarsource.sonarlint.core.analysis.api.ClientInputFile; import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue; @@ -52,22 +50,14 @@ public class SonarLintTest { - @ClassRule - public static TemporaryFolder temp = new TemporaryFolder(); + @TempDir + static Path baseDir; private static StandaloneSonarLintEngine sonarlintEngine; - private static File baseDir; - - @BeforeClass - public static void prepare() throws Exception { - // Orchestrator is used only to retrieve plugin artifacts from filesystem or maven - OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv(); - Tests.addGoPlugin(orchestratorBuilder); - Orchestrator orchestrator = orchestratorBuilder - .useDefaultAdminCredentialsForBuilds(true) - .setSonarVersion(System.getProperty(Tests.SQ_VERSION_PROPERTY, Tests.DEFAULT_SQ_VERSION)) - .build(); + @BeforeAll + public static void prepare() { + Orchestrator orchestrator = TestBase.ORCHESTRATOR; Locators locators = orchestrator.getConfiguration().locators(); StandaloneGlobalConfiguration.Builder sonarLintConfigBuilder = StandaloneGlobalConfiguration.builder(); @@ -77,7 +67,7 @@ public static void prepare() throws Exception { .forEach(sonarLintConfigBuilder::addPlugin); sonarLintConfigBuilder - .setSonarLintUserHome(temp.newFolder().toPath()) + .setSonarLintUserHome(baseDir) .setLogOutput((formattedMessage, level) -> { /* Don't pollute logs */ }); @@ -85,10 +75,9 @@ public static void prepare() throws Exception { .addEnabledLanguage(Language.GO) .build(); sonarlintEngine = new StandaloneSonarLintEngineImpl(configuration); - baseDir = temp.newFolder(); } - @AfterClass + @AfterAll public static void stop() { sonarlintEngine.stop(); } @@ -116,7 +105,7 @@ public void test_go_nosonar() throws Exception { private List analyzeWithSonarLint(ClientInputFile inputFile) { List issues = new ArrayList<>(); StandaloneAnalysisConfiguration analysisConfiguration = StandaloneAnalysisConfiguration.builder() - .setBaseDir(baseDir.toPath()) + .setBaseDir(baseDir) .addInputFiles(Collections.singletonList(inputFile)) .build(); @@ -132,7 +121,7 @@ private void assertIssues(List issues, Tuple... expectedIssues) { } private ClientInputFile prepareInputFile(String content) throws IOException { - File file = new File(baseDir, "foo.go"); + File file = new File(baseDir.toFile(), "foo.go"); FileUtils.write(file, content, StandardCharsets.UTF_8); return createInputFile(file.toPath()); } diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java index 66a6a887..8bfd0e40 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java @@ -18,11 +18,20 @@ import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; +import com.sonar.orchestrator.build.SonarScannerInstaller; +import com.sonar.orchestrator.config.Configuration; +import com.sonar.orchestrator.junit5.OrchestratorExtension; +import com.sonar.orchestrator.junit5.OrchestratorExtensionBuilder; +import com.sonar.orchestrator.locator.FileLocation; +import com.sonar.orchestrator.version.Version; import java.io.File; import java.util.Collections; import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nullable; -import org.junit.ClassRule; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.sonarqube.ws.Issues; import org.sonarqube.ws.Measures.ComponentWsResponse; import org.sonarqube.ws.Measures.Measure; @@ -36,8 +45,49 @@ public abstract class TestBase { - @ClassRule - public static final Orchestrator ORCHESTRATOR = Tests.ORCHESTRATOR; + public static final String KEEP_ORCHESTRATOR_RUNNING_ENV = "KEEP_ORCHESTRATOR_RUNNING"; + public static final boolean KEEP_ORCHESTRATOR_RUNNING = "true".equals(System.getenv(KEEP_ORCHESTRATOR_RUNNING_ENV)); + public static final String SQ_VERSION_PROPERTY = "sonar.runtimeVersion"; + public static final String DEFAULT_SQ_VERSION = "LATEST_RELEASE"; + public static final FileLocation GO_PLUGIN_LOCATION = FileLocation.byWildcardFilename(new File("../../sonar-go-plugin/build/libs"), "sonar-go-plugin-*-all.jar"); + public static final Configuration CONFIGURATION = Configuration.createEnv(); + + private static final AtomicInteger REQUESTED_ORCHESTRATORS_KEY = new AtomicInteger(); + private static final CountDownLatch IS_ORCHESTRATOR_READY = new CountDownLatch(1); + private static final String SCANNER_VERSION = "5.0.1.3006"; + + private static final OrchestratorExtensionBuilder orchestratorBuilder = OrchestratorExtension.builder(CONFIGURATION); + public static final Orchestrator ORCHESTRATOR = orchestratorBuilder + .addPlugin(GO_PLUGIN_LOCATION) + .useDefaultAdminCredentialsForBuilds(true) + .setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION)) + .restoreProfileAtStartup(FileLocation.of("src/integrationTest/resources/nosonar-go.xml")) + .build(); + + @BeforeAll + public static void startOrchestrator() { + // This is to avoid multiple starts when using nested tests + // See https://github.com/junit-team/junit5/issues/2421 + if (REQUESTED_ORCHESTRATORS_KEY.getAndIncrement() == 0) { + ORCHESTRATOR.start(); + // installed scanner will be shared by all tests + new SonarScannerInstaller(CONFIGURATION.locators()).install(Version.create(SCANNER_VERSION), CONFIGURATION.fileSystem().workspace()); + IS_ORCHESTRATOR_READY.countDown(); + } else { + try { + IS_ORCHESTRATOR_READY.await(); + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + } + } + + @AfterAll + public static void stopOrchestrator() { + if (!KEEP_ORCHESTRATOR_RUNNING && REQUESTED_ORCHESTRATORS_KEY.decrementAndGet() == 0) { + ORCHESTRATOR.stop(); + } + } protected SonarScanner getSonarScanner(String projectKey, String directoryToScan, String languageKey) { return getSonarScanner(projectKey, directoryToScan, languageKey, null); diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestReportTest.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestReportTest.java index 9bff0403..3c0161da 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestReportTest.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestReportTest.java @@ -16,12 +16,10 @@ */ package org.sonarsource.slang; -import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.build.SonarScanner; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -29,9 +27,6 @@ public class TestReportTest extends TestBase { private static final Path BASE_DIRECTORY = Paths.get("projects", "measures"); - @ClassRule - public static Orchestrator orchestrator = Tests.ORCHESTRATOR; - @Test public void go_test_report() { final String projectKey = "goTestReport"; diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/Tests.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/Tests.java deleted file mode 100644 index eba37435..00000000 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/Tests.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SonarSource Go - * Copyright (C) 2018-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the Sonar Source-Available License for more details. - * - * You should have received a copy of the Sonar Source-Available License - * along with this program; if not, see https://sonarsource.com/license/ssal/ - */ -package org.sonarsource.slang; - -import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.OrchestratorBuilder; -import com.sonar.orchestrator.locator.FileLocation; -import com.sonar.orchestrator.locator.Location; -import com.sonar.orchestrator.locator.MavenLocation; -import java.io.File; -import org.apache.commons.lang.StringUtils; -import org.junit.ClassRule; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - CoverageTest.class, - TestReportTest.class, - DuplicationsTest.class, - ExternalReportTest.class, - MeasuresTest.class, - NoSonarTest.class, -}) -public class Tests { - - static final String SQ_VERSION_PROPERTY = "sonar.runtimeVersion"; - static final String DEFAULT_SQ_VERSION = "LATEST_RELEASE"; - - @ClassRule - public static final Orchestrator ORCHESTRATOR; - - static { - OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv(); - addGoPlugin(orchestratorBuilder); - ORCHESTRATOR = orchestratorBuilder - .useDefaultAdminCredentialsForBuilds(true) - .setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION)) - .restoreProfileAtStartup(FileLocation.of("src/integrationTest/resources/nosonar-go.xml")) - .build(); - } - - static void addGoPlugin(OrchestratorBuilder builder) { - String plugin = "sonar-go-plugin"; - String slangVersion = System.getProperty("slangVersion"); - - Location pluginLocation; - if (StringUtils.isEmpty(slangVersion)) { - // use the plugin that was built on local machine - pluginLocation = FileLocation.byWildcardMavenFilename(new File("../../" + plugin + "/build/libs"), plugin + "-*-all.jar"); - } else { - // QA environment downloads the plugin built by the CI job - pluginLocation = MavenLocation.of("org.sonarsource.slang", plugin, slangVersion); - } - - builder.addPlugin(pluginLocation); - } - -} diff --git a/its/ruling/build.gradle.kts b/its/ruling/build.gradle.kts index 5b796fd1..956e807b 100644 --- a/its/ruling/build.gradle.kts +++ b/its/ruling/build.gradle.kts @@ -5,13 +5,22 @@ plugins { } dependencies { + "integrationTestImplementation"(libs.slf4j.api) "integrationTestImplementation"(libs.sonar.analyzer.commons) "integrationTestImplementation"(libs.assertj.core) - "integrationTestImplementation"(libs.sonar.orchestrator) - "integrationTestRuntimeOnly"(libs.junit.vintage.engine) + "integrationTestImplementation"(libs.sonar.orchestrator.junit5) { + exclude("ch.qos.logback", "logback-classic") + exclude("org.slf4j", "slf4j-api") + exclude("org.slf4j", "jcl-over-slf4j") + exclude("org.slf4j", "log4j-over-slf4j") + } + "integrationTestImplementation"(libs.junit.jupiter.api) + + "integrationTestRuntimeOnly"(project(":sonar-go-plugin", configuration = "shadow")) + "integrationTestRuntimeOnly"(libs.junit.jupiter.engine) } -sonarqube.isSkipProject = true +sonar.isSkipProject = true integrationTest { testSources.set(rootProject.file("its/sources")) diff --git a/its/ruling/src/integrationTest/java/org/sonarsource/slang/GoRulingTest.java b/its/ruling/src/integrationTest/java/org/sonarsource/slang/GoRulingTest.java index 8cbdb5ec..c409daa8 100644 --- a/its/ruling/src/integrationTest/java/org/sonarsource/slang/GoRulingTest.java +++ b/its/ruling/src/integrationTest/java/org/sonarsource/slang/GoRulingTest.java @@ -17,10 +17,9 @@ package org.sonarsource.slang; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.OrchestratorBuilder; import com.sonar.orchestrator.build.SonarScanner; +import com.sonar.orchestrator.junit5.OrchestratorExtension; import com.sonar.orchestrator.locator.FileLocation; -import com.sonar.orchestrator.locator.Location; import com.sonar.orchestrator.locator.MavenLocation; import java.io.File; import java.io.IOException; @@ -30,11 +29,10 @@ import java.util.HashMap; import java.util.Map; import java.util.Scanner; -import org.apache.commons.lang.StringUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.sonarsource.analyzer.commons.ProfileGenerator; import static org.assertj.core.api.Assertions.assertThat; @@ -46,16 +44,16 @@ public class GoRulingTest { private static Orchestrator orchestrator; private static boolean keepSonarqubeRunning = "true".equals(System.getProperty("keepSonarqubeRunning")); + public static final FileLocation GO_PLUGIN_LOCATION = FileLocation.byWildcardFilename(new File("../../sonar-go-plugin/build/libs"), "sonar-go-plugin-*-all.jar"); - @BeforeClass + @BeforeAll public static void setUp() { - OrchestratorBuilder builder = Orchestrator.builderEnv() + var builder = OrchestratorExtension.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION)) + .addPlugin(GO_PLUGIN_LOCATION) .addPlugin(MavenLocation.of("org.sonarsource.sonar-lits-plugin", "sonar-lits-plugin", "0.10.0.2181")); - addGoPlugin(builder); - orchestrator = builder.build(); orchestrator.start(); @@ -68,24 +66,8 @@ public static void setUp() { orchestrator.getServer().restoreProfile(FileLocation.of(goProfile)); } - static void addGoPlugin(OrchestratorBuilder builder) { - String plugin = "sonar-go-plugin"; - String slangVersion = System.getProperty("slangVersion"); - - Location pluginLocation; - if (StringUtils.isEmpty(slangVersion)) { - // use the plugin that was built on local machine - pluginLocation = FileLocation.byWildcardMavenFilename(new File("../../" + plugin + "/build/libs"), plugin + "-*-all.jar"); - } else { - // QA environment downloads the plugin built by the CI job - pluginLocation = MavenLocation.of("org.sonarsource.slang", plugin, slangVersion); - } - - builder.addPlugin(pluginLocation); - } - @Test - @Ignore("This test should only be run manually") + @Disabled("This test should only be run manually") public void go_manual_keep_sonarqube_server_up() throws IOException { keepSonarqubeRunning = true; test_go(); @@ -135,12 +117,11 @@ private void run_ruling_test(Map projectProperties) throws IOExc assertThat(litsDifference).isEmpty(); } - @AfterClass + @AfterAll public static void after() { if (keepSonarqubeRunning) { // keep server running, use CTRL-C to stop it new Scanner(System.in).next(); } } - } From d517f84673d67a8e0bdedb26bf7d792ba91105b8 Mon Sep 17 00:00:00 2001 From: Marcin Stachniuk Date: Tue, 17 Dec 2024 10:01:59 +0100 Subject: [PATCH 2/2] Code review remarks --- .../integrationTest/java/org/sonarsource/slang/TestBase.java | 2 +- sonar-go-plugin/build.gradle.kts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java index 8bfd0e40..11e9f23d 100644 --- a/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java +++ b/its/plugin/src/integrationTest/java/org/sonarsource/slang/TestBase.java @@ -54,7 +54,7 @@ public abstract class TestBase { private static final AtomicInteger REQUESTED_ORCHESTRATORS_KEY = new AtomicInteger(); private static final CountDownLatch IS_ORCHESTRATOR_READY = new CountDownLatch(1); - private static final String SCANNER_VERSION = "5.0.1.3006"; + private static final String SCANNER_VERSION = "6.2.1.4610"; private static final OrchestratorExtensionBuilder orchestratorBuilder = OrchestratorExtension.builder(CONFIGURATION); public static final Orchestrator ORCHESTRATOR = orchestratorBuilder diff --git a/sonar-go-plugin/build.gradle.kts b/sonar-go-plugin/build.gradle.kts index 1c692172..0cabf12a 100644 --- a/sonar-go-plugin/build.gradle.kts +++ b/sonar-go-plugin/build.gradle.kts @@ -90,6 +90,7 @@ tasks.shadowJar { exclude("libs/**") exclude("META-INF/maven/**") exclude("tmp/**") + exclude("spotless/**") } doLast { enforceJarSizeAndCheckContent(tasks.shadowJar.get().archiveFile.get().asFile, 9_000_000L, 9_500_000L)