Skip to content

Commit

Permalink
Use embedded node in ruling and QA (#4180)
Browse files Browse the repository at this point in the history
  • Loading branch information
saberduck authored Sep 20, 2023
1 parent 4cfcc82 commit 668ccbd
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 46 deletions.
40 changes: 24 additions & 16 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -68,17 +65,18 @@ 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
- 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:
eks_container:
<<: *CONTAINER_DEFINITION
dockerfile: .cirrus/nodejs.Dockerfile
docker_arguments:
CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT}
cpu: 15
memory: 30G
env:
Expand Down Expand Up @@ -124,6 +122,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
Expand All @@ -142,25 +143,31 @@ ws_scan_task:
ws_artifacts:
path: 'whitesource/**/*'

plugin_qa_task:
plugin_qa_with_node_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
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,!SonarJsIntegrationTest --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
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:
Expand Down Expand Up @@ -189,7 +196,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:
Expand All @@ -216,7 +223,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
Expand Down
22 changes: 14 additions & 8 deletions its/plugin/sonarlint-tests/src/test/java/SonarLintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 21 additions & 14 deletions its/plugin/sonarlint-tests/src/test/java/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("../../");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,10 +51,31 @@ 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"
);

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 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"))
? Pattern.compile("sonar-javascript-plugin-.*-multi\\.jar")
: Pattern.compile("sonar-javascript-plugin-[0-9.]*(?:-SNAPSHOT)?\\.jar");
}

public static final OrchestratorExtension ORCHESTRATOR = OrchestratorExtension
.builderEnv()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sonar-plugin/sonar-javascript-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@
<skipDependenciesPackaging>true</skipDependenciesPackaging>
<sonarLintSupported>true</sonarLintSupported>
<sonarQubeMinVersion>${sonarQubeMinVersion}</sonarQubeMinVersion>
<!-- Keep in sync with NodeDeprecationWarning#MIN_SUPPORTED_NODE_VERSION -->
<nodeJsMinVersion>14.17.0</nodeJsMinVersion>
<jreMinVersion>${jdk.min.version}</jreMinVersion>
</configuration>
</plugin>
Expand Down Expand Up @@ -284,6 +282,8 @@
<manifestEntries>
<!-- This is used to get plugin version at runtime using getPackage().getImplementationVersion() -->
<Implementation-Version>${project.version}</Implementation-Version>
<!-- Keep in sync with NodeDeprecationWarning#MIN_SUPPORTED_NODE_VERSION -->
<NodeJs-Min-Version>14.17.0</NodeJs-Min-Version>
</manifestEntries>
</transformer>
</transformers>
Expand Down

0 comments on commit 668ccbd

Please sign in to comment.