From 94781afc60833a976b850f9909f3fcc07d93345e Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Mon, 18 Sep 2023 23:56:44 +0200 Subject: [PATCH 1/9] Use embedded node in ruling and QA --- .cirrus.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index b85a600c789..5d5329b51fb 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -20,9 +20,6 @@ env: CIRRUS_SHELL: bash container_definition: &CONTAINER_DEFINITION - dockerfile: .cirrus/nodejs.Dockerfile - docker_arguments: - CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT} cluster_name: ${CIRRUS_CLUSTER_NAME} builder_role: cirrus-builder builder_image: docker-builder-v* @@ -79,6 +76,9 @@ plugin_qa_body: &PLUGIN_QA_BODY build_task: eks_container: <<: *CONTAINER_DEFINITION + dockerfile: .cirrus/nodejs.Dockerfile + docker_arguments: + CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT} cpu: 15 memory: 30G env: @@ -124,6 +124,9 @@ ws_scan_task: - build eks_container: <<: *CONTAINER_DEFINITION + dockerfile: .cirrus/nodejs.Dockerfile + docker_arguments: + CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT} cpu: 4 memory: 8G # run only on master and long-term branches @@ -145,13 +148,11 @@ ws_scan_task: plugin_qa_task: <<: *PLUGIN_QA_BODY eks_container: - dockerfile: .cirrus/nodejs.jdk17.Dockerfile - docker_arguments: - matrix: - - NODE_VERSION: 14 - - NODE_VERSION: 16 - - NODE_VERSION: 18 - - NODE_VERSION: 20 + matrix: + - dockerfile: .cirrus/nodejs.jdk17.Dockerfile + docker_arguments: + NODE_VERSION: 14 + - image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest env: SQ_VERSION: LATEST_RELEASE @@ -189,7 +190,7 @@ ruling_task: <<: *ONLY_SONARSOURCE_QA eks_container: <<: *CONTAINER_DEFINITION - dockerfile: .cirrus/nodejs.jdk17.Dockerfile + image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest cpu: 15 memory: 24G env: From fb989deb1a49630ab3e94a74ebb3c71296a1283a Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Tue, 19 Sep 2023 00:39:22 +0200 Subject: [PATCH 2/9] remove node version script --- .cirrus.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 5d5329b51fb..5424d54dc58 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -65,8 +65,6 @@ plugin_qa_body: &PLUGIN_QA_BODY CIRRUS_CLONE_DEPTH: 10 SONARSOURCE_QA: true <<: *MAVEN_CACHE - node_version_script: - - node -v qa_script: - source cirrus-env QA - source set_maven_build_version $BUILD_NUMBER From 72f23916d89d3d469f30212cae2d553e8ff6787d Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Tue, 19 Sep 2023 13:55:14 +0200 Subject: [PATCH 3/9] don't build custom plugin on axis without node (with embedded node) --- .cirrus.yml | 26 ++++++++++++------- .../it/plugin/OrchestratorStarter.java | 13 +++++++++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 5424d54dc58..85b2109b6c4 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -68,7 +68,7 @@ plugin_qa_body: &PLUGIN_QA_BODY qa_script: - source cirrus-env QA - source set_maven_build_version $BUILD_NUMBER - - mvn -f its/plugin/pom.xml -Dsonar.runtimeVersion=${SQ_VERSION} -B -e -V verify surefire-report:report + - mvn -f its/plugin/pom.xml -Dsonar.runtimeVersion=${SQ_VERSION} ${MVN_TEST} -B -e -V verify surefire-report:report cleanup_before_cache_script: cleanup_maven_repository build_task: @@ -143,23 +143,30 @@ ws_scan_task: ws_artifacts: path: 'whitesource/**/*' -plugin_qa_task: +plugin_qa_with_node_task: <<: *PLUGIN_QA_BODY eks_container: - matrix: - - dockerfile: .cirrus/nodejs.jdk17.Dockerfile - docker_arguments: - NODE_VERSION: 14 - - image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest + dockerfile: .cirrus/nodejs.jdk17.Dockerfile + env: + SQ_VERSION: LATEST_RELEASE + MVN_TEST: '' + +plugin_qa_no_node_task: + <<: *PLUGIN_QA_BODY + eks_container: + image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest env: SQ_VERSION: LATEST_RELEASE + SONARJS_ARTIFACT: multi + MVN_TEST: "-Dtest=!EslintCustomRulesTest --projects '!org.sonarsource.javascript:eslint-custom-rules-plugin'" plugin_qa_sq_dev_task: <<: *PLUGIN_QA_BODY eks_container: - dockerfile: .cirrus/nodejs.jdk17.Dockerfile + image: ${CIRRUS_AWS_ACCOUNT}.dkr.ecr.eu-central-1.amazonaws.com/base:j17-latest env: SQ_VERSION: DEV + SONARJS_ARTIFACT: multi # Plugin QA for Windows is splint into 2 parts to make it faster plugin_qa_win_task: @@ -215,7 +222,8 @@ promote_task: depends_on: - ws_scan - build_win - - plugin_qa + - plugin_qa_with_node + - plugin_qa_no_node - plugin_qa_sq_dev - plugin_qa_win - ruling diff --git a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/OrchestratorStarter.java b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/OrchestratorStarter.java index c14cfed636a..28ab1af9641 100644 --- a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/OrchestratorStarter.java +++ b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/OrchestratorStarter.java @@ -46,11 +46,22 @@ public final class OrchestratorStarter implements BeforeAllCallback, ExtensionContext.Store.CloseableResource { static final String SCANNER_VERSION = "5.0.1.3006"; + static final FileLocation JAVASCRIPT_PLUGIN_LOCATION = FileLocation.byWildcardMavenFilename( new File("../../../sonar-plugin/sonar-javascript-plugin/target"), - "sonar-javascript-plugin-*-multi.jar" + artifact() ); + /** + * This is used to test artifact with and without embedded runtime during plugin QA integration tests + * + */ + private static String artifact() { + return "multi".equals(System.getenv("SONARJS_ARTIFACT")) + ? "sonar-javascript-plugin-*-multi.jar" + : "sonar-javascript-plugin-*.jar"; + } + public static final OrchestratorExtension ORCHESTRATOR = OrchestratorExtension .builderEnv() .useDefaultAdminCredentialsForBuilds(true) From a13c2a16ada37ee714ab0feda4be576fac3b83aa Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Tue, 19 Sep 2023 23:28:13 +0200 Subject: [PATCH 4/9] fix plugin location --- .../it/plugin/OrchestratorStarter.java | 31 ++++++++++++++----- .../it/plugin/SonarJsIntegrationTest.java | 11 ++++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/OrchestratorStarter.java b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/OrchestratorStarter.java index 28ab1af9641..89fd9eb7deb 100644 --- a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/OrchestratorStarter.java +++ b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/OrchestratorStarter.java @@ -28,9 +28,14 @@ import com.sonar.orchestrator.junit5.OrchestratorExtension; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.MavenLocation; -import java.io.File; +import com.sonar.orchestrator.locator.URLLocation; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import javax.annotation.CheckForNull; import org.junit.jupiter.api.extension.BeforeAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; @@ -47,19 +52,29 @@ public final class OrchestratorStarter static final String SCANNER_VERSION = "5.0.1.3006"; - static final FileLocation JAVASCRIPT_PLUGIN_LOCATION = FileLocation.byWildcardMavenFilename( - new File("../../../sonar-plugin/sonar-javascript-plugin/target"), - artifact() - ); + static final URLLocation JAVASCRIPT_PLUGIN_LOCATION = artifact(); /** * This is used to test artifact with and without embedded runtime during plugin QA integration tests * */ - private static String artifact() { + private static URLLocation artifact() { + var target = Path.of("../../../sonar-plugin/sonar-javascript-plugin/target"); + try (var stream = Files.walk(target, 1)) { + var plugin = stream + .filter(p -> pluginFilenameMatcher().matcher(p.getFileName().toString()).matches()) + .findAny() + .orElseThrow(); + return URLLocation.create(plugin.toUri().toURL()); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + private static Pattern pluginFilenameMatcher() { return "multi".equals(System.getenv("SONARJS_ARTIFACT")) - ? "sonar-javascript-plugin-*-multi.jar" - : "sonar-javascript-plugin-*.jar"; + ? Pattern.compile("sonar-javascript-plugin-.*-multi\\.jar") + : Pattern.compile("sonar-javascript-plugin-[0-9.]*(?:-SNAPSHOT)?\\.jar"); } public static final OrchestratorExtension ORCHESTRATOR = OrchestratorExtension diff --git a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/SonarJsIntegrationTest.java b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/SonarJsIntegrationTest.java index fcf5dfe6ee6..2a072ce2c52 100644 --- a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/SonarJsIntegrationTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/SonarJsIntegrationTest.java @@ -63,7 +63,16 @@ class SonarJsIntegrationTest { @TempDir Path temp; - static Path pluginJar = OrchestratorStarter.JAVASCRIPT_PLUGIN_LOCATION.getFile().toPath(); + static Path pluginJar; + + static { + try { + pluginJar = Path.of(OrchestratorStarter.JAVASCRIPT_PLUGIN_LOCATION.getURL().toURI()); + } catch (URISyntaxException e) { + throw new IllegalStateException(e); + } + } + static final Gson gson = new Gson(); @Test From 2a3b24a24e842a8048ca0b9a5a439c3c3014164d Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Tue, 19 Sep 2023 23:47:47 +0200 Subject: [PATCH 5/9] fix escape --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index 85b2109b6c4..baaec212d1a 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -158,7 +158,7 @@ plugin_qa_no_node_task: env: SQ_VERSION: LATEST_RELEASE SONARJS_ARTIFACT: multi - MVN_TEST: "-Dtest=!EslintCustomRulesTest --projects '!org.sonarsource.javascript:eslint-custom-rules-plugin'" + MVN_TEST: '-Dtest=!EslintCustomRulesTest --projects !org.sonarsource.javascript:eslint-custom-rules-plugin' plugin_qa_sq_dev_task: <<: *PLUGIN_QA_BODY From cb812ce856a89e52b105bf17494abfaa3f26235e Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Wed, 20 Sep 2023 00:12:24 +0200 Subject: [PATCH 6/9] dont run tests which require sonarjs --- .cirrus.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cirrus.yml b/.cirrus.yml index baaec212d1a..ddd96e54545 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -158,7 +158,7 @@ plugin_qa_no_node_task: env: SQ_VERSION: LATEST_RELEASE SONARJS_ARTIFACT: multi - MVN_TEST: '-Dtest=!EslintCustomRulesTest --projects !org.sonarsource.javascript:eslint-custom-rules-plugin' + MVN_TEST: '-Dtest=!EslintCustomRulesTest,!SonarJsIntegrationTest --projects !org.sonarsource.javascript:eslint-custom-rules-plugin' plugin_qa_sq_dev_task: <<: *PLUGIN_QA_BODY From d23557bc00af562ca462031f3497cfc28cb19b50 Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Wed, 20 Sep 2023 00:39:29 +0200 Subject: [PATCH 7/9] fix unbound variable --- .cirrus.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.cirrus.yml b/.cirrus.yml index ddd96e54545..c919c25b4f1 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -167,6 +167,7 @@ plugin_qa_sq_dev_task: env: SQ_VERSION: DEV SONARJS_ARTIFACT: multi + MVN_TEST: '-Dtest=!EslintCustomRulesTest,!SonarJsIntegrationTest --projects !org.sonarsource.javascript:eslint-custom-rules-plugin' # Plugin QA for Windows is splint into 2 parts to make it faster plugin_qa_win_task: From 7441e8d1359ab9cd19467cd87fa35f821c39ba2a Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Wed, 20 Sep 2023 09:55:04 +0200 Subject: [PATCH 8/9] remove nodejs requirement from manifest --- sonar-plugin/sonar-javascript-plugin/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonar-plugin/sonar-javascript-plugin/pom.xml b/sonar-plugin/sonar-javascript-plugin/pom.xml index dcfc79ca6d5..746d8b3d199 100644 --- a/sonar-plugin/sonar-javascript-plugin/pom.xml +++ b/sonar-plugin/sonar-javascript-plugin/pom.xml @@ -129,8 +129,6 @@ true true ${sonarQubeMinVersion} - - 14.17.0 ${jdk.min.version} @@ -260,6 +258,8 @@ ${project.version} + + 14.17.0 From 2e8776f7c205c63a1d26df0c1c16d19bedc8cd16 Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Wed, 20 Sep 2023 10:37:45 +0200 Subject: [PATCH 9/9] Fix SonarLintTest assert --- .../src/test/java/SonarLintTest.java | 22 +++++++----- .../src/test/java/TestUtils.java | 35 +++++++++++-------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/its/plugin/sonarlint-tests/src/test/java/SonarLintTest.java b/its/plugin/sonarlint-tests/src/test/java/SonarLintTest.java index 38343bbfb59..ae93aaca555 100644 --- a/its/plugin/sonarlint-tests/src/test/java/SonarLintTest.java +++ b/its/plugin/sonarlint-tests/src/test/java/SonarLintTest.java @@ -103,14 +103,20 @@ void should_raise_issues() throws IOException { tuple("javascript:S3504", 4, filePath, "CRITICAL") ); - assertThat( - logs - .stream() - .anyMatch(s -> - s.matches("Using Node\\.js executable .* from property sonar\\.nodejs\\.executable\\.") - ) - ) - .isTrue(); + if (!usingEmbeddedNode()) { + assertThat( + logs + .stream() + .anyMatch(s -> + s.matches("Using Node\\.js executable .* from property sonar\\.nodejs\\.executable\\.") + ) + ) + .isTrue(); + } + } + + private static boolean usingEmbeddedNode() { + return TestUtils.JAVASCRIPT_PLUGIN_LOCATION.toString().contains("multi"); } @Test diff --git a/its/plugin/sonarlint-tests/src/test/java/TestUtils.java b/its/plugin/sonarlint-tests/src/test/java/TestUtils.java index 9335f50cc28..197936da417 100644 --- a/its/plugin/sonarlint-tests/src/test/java/TestUtils.java +++ b/its/plugin/sonarlint-tests/src/test/java/TestUtils.java @@ -30,28 +30,35 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; +import java.util.regex.Pattern; import org.sonarsource.sonarlint.core.analysis.api.ClientInputFile; public class TestUtils { - static final Path JAVASCRIPT_PLUGIN_LOCATION; - - static { - var start = homeDir().resolve("../sonar-plugin/sonar-javascript-plugin/target"); - try (var walk = Files.walk(start)) { - JAVASCRIPT_PLUGIN_LOCATION = - walk - .filter(p -> { - var filename = p.getFileName().toString(); - return filename.startsWith("sonar-javascript-plugin-") && filename.endsWith(".jar"); - }) - .findAny() - .orElseThrow(); + static final Path JAVASCRIPT_PLUGIN_LOCATION = artifact(); + + /** + * This is used to test artifact with and without embedded runtime during plugin QA integration tests + * + */ + private static Path artifact() { + var target = homeDir().resolve("../sonar-plugin/sonar-javascript-plugin/target"); + try (var stream = Files.walk(target, 1)) { + return stream + .filter(p -> pluginFilenameMatcher().matcher(p.getFileName().toString()).matches()) + .findAny() + .orElseThrow(); } catch (IOException e) { - throw new IllegalStateException(e); + throw new UncheckedIOException(e); } } + private static Pattern pluginFilenameMatcher() { + return "multi".equals(System.getenv("SONARJS_ARTIFACT")) + ? Pattern.compile("sonar-javascript-plugin-.*-multi\\.jar") + : Pattern.compile("sonar-javascript-plugin-[0-9.]*(?:-SNAPSHOT)?\\.jar"); + } + public static Path homeDir() { return Path.of("../../"); }