Skip to content

Commit

Permalink
feat: added support of Node.js distribution compatible with Linux S39…
Browse files Browse the repository at this point in the history
…0X systems (#262)

Fixes #260
  • Loading branch information
v1nc3n4 authored Nov 5, 2024
1 parent 4811b9f commit af783f4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,11 +26,14 @@ public class Platform {

private static final Set<String> SUPPORTED_JVM_ARM_64_BITS_ARCH_IDS = Set.of("aarch64");

private static final Set<String> SUPPORTED_JVM_PPC_LE_64_BITS_ARCH_IDS = Set.of("ppc64le");
private static final Set<String> SUPPORTED_JVM_PPC_64_BITS_LE_ARCH_IDS = Set.of("ppc64le");

private static final Set<String> SUPPORTED_JVM_S390X_64_BITS_ARCH_IDS = Set.of("s390x");

private static final Set<String> 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<String> SUPPORTED_LINUX_OS_IDS = Set.of("linux");
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -77,6 +82,8 @@ public Optional<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit af783f4

Please sign in to comment.