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

Gradle JDK installation directory contains glibc/musl name for linux distributions #482

Merged
merged 13 commits into from
Dec 12, 2024
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-482.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Gradle JDK installation directory contains glibc/musl name for linux
distributions
links:
- https://github.com/palantir/gradle-jdks/pull/482
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static void writeJdkInstallationConfiguration(
GradleJdksConfigsUtils.writeConfigurationFile(
jdkOsArchDir.resolve("download-url"), resolveDownloadUrl(baseUrl, jdkDistributionName, jdkRelease));
GradleJdksConfigsUtils.writeConfigurationFile(
jdkOsArchDir.resolve("local-path"), resolveLocalPath(jdkDistributionName, jdkRelease));
jdkOsArchDir.resolve("local-path"), resolveLocalPath(os, jdkDistributionName, jdkRelease));
} catch (Exception e) {
throw new RuntimeException(
String.format("Failed to crate jdk configuration files in dir %s", jdkOsArchDir), e);
Expand All @@ -93,8 +93,14 @@ private static void writeInstallationScripts(Path targetDir) {
GradleJdksConfigsUtils.copyResourceToPath(scriptsDir, "gradle-jdks-setup.jar");
}

private static String resolveLocalPath(JdkDistributionName jdkDistributionName, JdkRelease jdkRelease) {
return String.format("%s-%s", jdkDistributionName, jdkRelease.version());
// TODO(crogoz): Remove glibcOrMusl from the localPath name. This is a workaround for the excavator workflow.
// Excavator caches the location of gradle-jdks directory, however it doesn't take into consideration if the job
// is running on a musl/glibc image. Without this, we might be using the jdk used for a different c implementation.
private static String resolveLocalPath(Os os, JdkDistributionName jdkDistributionName, JdkRelease jdkRelease) {
return os.glibcOrMuslDistribution()
.map(cDistribution ->
String.format("%s-%s-%s", jdkDistributionName, jdkRelease.version(), cDistribution))
.orElseGet(() -> String.format("%s-%s", jdkDistributionName, jdkRelease.version()));
}

private static String resolveDownloadUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ void can_install_generated_gradle_jdk_files() throws IOException {
.resolve(CurrentOs.get().uiName())
.resolve(CurrentArch.get().uiName())
.resolve("local-path"));
assertThat(localPath).isEqualTo(String.format("amazon-corretto-%s\n", JDK_VERSION));

switch (CurrentOs.get()) {
case LINUX_MUSL:
assertThat(localPath).isEqualTo(String.format("amazon-corretto-%s-musl\n", JDK_VERSION));
break;
case LINUX_GLIBC:
assertThat(localPath).isEqualTo(String.format("amazon-corretto-%s-glibc\n", JDK_VERSION));
break;
case WINDOWS:
case MACOS:
assertThat(localPath).isEqualTo(String.format("amazon-corretto-%s\n", JDK_VERSION));
break;
}
Path installationScript = latestGradleJdksDir.resolve("scripts").resolve("install-jdks.sh");
ProcessBuilder processBuilder = new ProcessBuilder()
.command(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ public final String uiName() {
return UiNames.uiName(this);
}

public Optional<String> glibcOrMuslDistribution() {
switch (this) {
case LINUX_MUSL:
return Optional.of("musl");
case LINUX_GLIBC:
return Optional.of("glibc");
case MACOS:
case WINDOWS:
return Optional.empty();
}
throw new IllegalStateException("Unsupported OS: " + this);
}

public static Optional<Os> fromString(String osUiName) {
return UiNames.fromString(values(), osUiName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ private static Stream<JdkDistributionConfig> getJdkDistributionConfig(
.get(),
jdkPath.filename(),
jdkPath.extension()));
jdkDistribution.getLocalPath().set(String.format("%s-%s", jdkDistributionName, jdkVersion.get()));
String localPathName = os.glibcOrMuslDistribution()
.map(cDistribution -> String.format("%s-%s-%s", jdkDistributionName, jdkVersion.get(), cDistribution))
.orElseGet(() -> String.format("%s-%s", jdkDistributionName, jdkVersion.get()));
jdkDistribution.getLocalPath().set(localPathName);
return Stream.of(jdkDistribution);
}

Expand Down