Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-170 Bundle SonarJS with Node.js Runtime on Linux ARM64 Platform #4726

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class EmbeddedNode {

enum Platform {
WIN_X64,
LINUX_ARM64,
LINUX_X64,
DARWIN_ARM64,
DARWIN_X64,
Expand All @@ -71,6 +72,8 @@ private String pathInJar() {
switch (this) {
case WIN_X64:
return "/win-x64/";
case LINUX_ARM64:
return "/linux-arm64/";
case LINUX_X64:
return "/linux-x64/";
case DARWIN_ARM64:
Expand Down Expand Up @@ -115,6 +118,8 @@ static Platform detect(Environment env) {
var lowerCaseOsName = osName.toLowerCase(Locale.ROOT);
if (osName.contains("Windows") && isX64(env)) {
return WIN_X64;
} else if (lowerCaseOsName.contains("linux") && isARM64(env) ) {
return LINUX_ARM64;
} else if (lowerCaseOsName.contains("linux") && isX64(env) && !env.isAlpine()) {
// alpine linux is using musl libc, which is not compatible with linux-x64
return LINUX_X64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.mockito.Mockito.when;
import static org.sonar.plugins.javascript.bridge.EmbeddedNode.Platform.DARWIN_ARM64;
import static org.sonar.plugins.javascript.bridge.EmbeddedNode.Platform.DARWIN_X64;
import static org.sonar.plugins.javascript.bridge.EmbeddedNode.Platform.LINUX_ARM64;
import static org.sonar.plugins.javascript.bridge.EmbeddedNode.Platform.LINUX_X64;
import static org.sonar.plugins.javascript.bridge.EmbeddedNode.Platform.UNSUPPORTED;
import static org.sonar.plugins.javascript.bridge.EmbeddedNode.Platform.WIN_X64;
Expand Down Expand Up @@ -115,7 +116,14 @@ void should_detect_platform_for_mac_os_x64_environment() {
}

@Test
void should_detect_platform_for_linux_environment() {
void should_detect_platform_for_linux_arm64_environment() {
var platform = Platform.detect(createLinuxArm64Environment());
assertThat(platform).isEqualTo(LINUX_ARM64);
assertThat(platform.archivePathInJar()).isEqualTo("/linux-arm64/node.xz");
}

@Test
void should_detect_platform_for_linux_x64_environment() {
var linux = mock(Environment.class);
when(linux.getOsName()).thenReturn("linux");
when(linux.getOsArch()).thenReturn("amd64");
Expand Down Expand Up @@ -188,6 +196,13 @@ private Environment createTestEnvironment() {
return mockEnvironment;
}

private Environment createLinuxArm64Environment() {
Environment mockEnvironment = mock(Environment.class);
when(mockEnvironment.getOsName()).thenReturn("linux");
when(mockEnvironment.getOsArch()).thenReturn("aarch64");
return mockEnvironment;
}

private Environment createMacOSArm64Environment() {
Environment mockEnvironment = mock(Environment.class);
when(mockEnvironment.getOsName()).thenReturn("mac os x");
Expand Down
28 changes: 28 additions & 0 deletions sonar-plugin/sonar-javascript-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,34 @@
</configuration>
</execution>

<execution>
<id>linux-arm64</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>linux-arm64</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<!-- This is used to get plugin version at runtime using getPackage().getImplementationVersion() -->
<Implementation-Version>${project.version}</Implementation-Version>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>linux-arm64/node.xz</resource>
<file>${project.build.directory}/node/linux-arm64/node.xz</file>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>linux-arm64/version.txt</resource>
<file>${project.build.directory}/node/linux-arm64/version.txt</file>
</transformer>
</transformers>
</configuration>
</execution>

<execution>
<id>multi</id>
<phase>package</phase>
Expand Down
7 changes: 7 additions & 0 deletions tools/fetch-node/node-distros.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export const DISTROS = [
sha: 'fc5b73f2a78c17bbe926cdb1447d652f9f094c79582f1be6471b4b38a2e1ccc8',
binPath: 'bin/node',
},
{
id: 'linux-arm64',
url: `${NODE_ORG_URL}-linux-arm64.tar.gz`,
artifactoryUrl: `${NODE_ARTIFACTORY_URL}-linux-arm64.tar.gz`,
sha: 'd2a7dbeeb274bfd16b579d2cafb92f673010df36c83a5b55de3916aad6806a6a',
binPath: 'bin/node',
},
{
id: 'linux-x64',
url: `${NODE_ORG_URL}-linux-x64.tar.gz`,
Expand Down
1 change: 1 addition & 0 deletions tools/fetch-node/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<arguments>
<argument>${project.basedir}/downloads/runtimes/darwin-arm64/node</argument>
<argument>${project.basedir}/downloads/runtimes/darwin-x64/node</argument>
<argument>${project.basedir}/downloads/runtimes/linux-arm64/node</argument>
<argument>${project.basedir}/downloads/runtimes/linux-x64/node</argument>
<argument>${project.basedir}/downloads/runtimes/win-x64/node.exe</argument>
</arguments>
Expand Down
Loading