From af783f405706ed83f401a8d6bc7cc0401d9dd2c0 Mon Sep 17 00:00:00 2001 From: v1nc3n4 <5869062+v1nc3n4@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:27:51 +0100 Subject: [PATCH] feat: added support of Node.js distribution compatible with Linux S390X systems (#262) Fixes #260 --- .../frontendgradleplugin/domain/Platform.java | 21 +++++++++++++++---- ...ResolveNodeDistributionArchitectureId.java | 7 +++++++ .../domain/PlatformTest.java | 5 +++++ ...lveNodeDistributionArchitectureIdTest.java | 6 ++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/Platform.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/Platform.java index 6f8bb427..77927d0f 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/Platform.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/Platform.java @@ -3,6 +3,7 @@ import static java.util.stream.Collectors.toUnmodifiableSet; import java.util.Set; +import java.util.function.Function; import java.util.stream.Stream; import lombok.Builder; @@ -25,11 +26,14 @@ public class Platform { private static final Set SUPPORTED_JVM_ARM_64_BITS_ARCH_IDS = Set.of("aarch64"); - private static final Set SUPPORTED_JVM_PPC_LE_64_BITS_ARCH_IDS = Set.of("ppc64le"); + private static final Set SUPPORTED_JVM_PPC_64_BITS_LE_ARCH_IDS = Set.of("ppc64le"); + + private static final Set SUPPORTED_JVM_S390X_64_BITS_ARCH_IDS = Set.of("s390x"); private static final Set SUPPORTED_JVM_64_BITS_ARCH_IDS = Stream - .concat(Stream.of("x64", "x86_64", "amd64", "ppc64", "sparc"), - SUPPORTED_JVM_ARM_64_BITS_ARCH_IDS.stream()) + .of(Stream.of("x64", "x86_64", "amd64", "ppc64", "sparc"), SUPPORTED_JVM_ARM_64_BITS_ARCH_IDS.stream(), + SUPPORTED_JVM_PPC_64_BITS_LE_ARCH_IDS.stream(), SUPPORTED_JVM_S390X_64_BITS_ARCH_IDS.stream()) + .flatMap(Function.identity()) .collect(toUnmodifiableSet()); private static final Set SUPPORTED_LINUX_OS_IDS = Set.of("linux"); @@ -85,7 +89,16 @@ public boolean isArm32BitsArch() { * @return {@code true} if the architecture is an ARM 64 bits architecture. */ public boolean isPpc64BitsLeArch() { - return matchesAnyIdPart(jvmArch, SUPPORTED_JVM_PPC_LE_64_BITS_ARCH_IDS); + return matchesAnyIdPart(jvmArch, SUPPORTED_JVM_PPC_64_BITS_LE_ARCH_IDS); + } + + /** + * Tells whether the JVM has a S390X 64 bits architecture. + * + * @return {@code true} if the architecture is a S390X 64 bits architecture. + */ + public boolean isS390X64BitsArch() { + return matchesAnyIdPart(jvmArch, SUPPORTED_JVM_S390X_64_BITS_ARCH_IDS); } /** diff --git a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/installer/ResolveNodeDistributionArchitectureId.java b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/installer/ResolveNodeDistributionArchitectureId.java index 5ab8fa00..ed24e0e0 100644 --- a/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/installer/ResolveNodeDistributionArchitectureId.java +++ b/plugin/src/main/java/org/siouan/frontendgradleplugin/domain/installer/ResolveNodeDistributionArchitectureId.java @@ -36,6 +36,11 @@ public class ResolveNodeDistributionArchitectureId { */ static final String LINUX_PPC64LE_ARCH = "linux-ppc64le"; + /** + * Architecture ID for a S390X 64 bits Linux O/S. + */ + static final String LINUX_S390X_ARCH = "linux-s390x"; + /** * Architecture ID for a X64 bits MacOS O/S. */ @@ -77,6 +82,8 @@ public Optional execute(final Platform platform) { extension = LINUX_ARM64_ARCH; } else if (platform.isPpc64BitsLeArch()) { extension = LINUX_PPC64LE_ARCH; + } else if (platform.isS390X64BitsArch()) { + extension = LINUX_S390X_ARCH; } else { extension = LINUX_X64_ARCH; } diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/PlatformTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/PlatformTest.java index 13981977..4642ac30 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/PlatformTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/PlatformTest.java @@ -66,6 +66,11 @@ void should_return_true_when_checking_if_jvm_arch_containing_ppc64le_is_a_ppc_li assertThat(aPlatformWithJvmArch("_Ppc64Le_").isPpc64BitsLeArch()).isTrue(); } + @Test + void should_return_true_when_checking_if_jvm_arch_containing_s390x_is_a_s390x_64_bits_arch() { + assertThat(aPlatformWithJvmArch("_S390x_").isS390X64BitsArch()).isTrue(); + } + @Test void should_return_false_when_checking_if_os_name_containing_ibm_is_an_aix_os() { assertThat(aPlatformWithOsName("_Unix_").isAixOs()).isFalse(); diff --git a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/installer/ResolveNodeDistributionArchitectureIdTest.java b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/installer/ResolveNodeDistributionArchitectureIdTest.java index 101fdccd..d0130e66 100644 --- a/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/installer/ResolveNodeDistributionArchitectureIdTest.java +++ b/plugin/src/test/java/org/siouan/frontendgradleplugin/domain/installer/ResolveNodeDistributionArchitectureIdTest.java @@ -6,6 +6,7 @@ import static org.siouan.frontendgradleplugin.domain.installer.ResolveNodeDistributionArchitectureId.LINUX_ARM32_ARCH; import static org.siouan.frontendgradleplugin.domain.installer.ResolveNodeDistributionArchitectureId.LINUX_ARM64_ARCH; import static org.siouan.frontendgradleplugin.domain.installer.ResolveNodeDistributionArchitectureId.LINUX_PPC64LE_ARCH; +import static org.siouan.frontendgradleplugin.domain.installer.ResolveNodeDistributionArchitectureId.LINUX_S390X_ARCH; import static org.siouan.frontendgradleplugin.domain.installer.ResolveNodeDistributionArchitectureId.LINUX_X64_ARCH; import static org.siouan.frontendgradleplugin.domain.installer.ResolveNodeDistributionArchitectureId.MACOS_ARM64_ARCH; import static org.siouan.frontendgradleplugin.domain.installer.ResolveNodeDistributionArchitectureId.MACOS_X64_ARCH; @@ -79,6 +80,11 @@ void should_resolve_architecture_id_when_os_is_linux_and_jvm_arch_is_ppc64le() { assertThat(usecase.execute(aPlatform("ppc64le", "Linux"))).contains(LINUX_PPC64LE_ARCH); } + @Test + void should_resolve_architecture_id_when_os_is_linux_and_jvm_arch_is_s390x() { + assertThat(usecase.execute(aPlatform("s390x", "Linux"))).contains(LINUX_S390X_ARCH); + } + @Test void should_resolve_architecture_id_when_os_is_mac_and_jvm_arch_is_amd64() { assertThat(usecase.execute(aPlatform("amd64", "Mac OS X"))).contains(MACOS_X64_ARCH);