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

Support Zulu bundle flags #86

Merged
merged 3 commits into from
Jul 29, 2022
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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-86.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Support Zulu bundle flags
links:
- https://github.com/palantir/gradle-jdks/pull/86
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@

package com.palantir.gradle.jdks;

import com.google.common.collect.ImmutableSet;
import com.palantir.gradle.jdks.JdkPath.Extension;
import com.palantir.gradle.jdks.JdkRelease.Arch;
import java.util.Arrays;
import java.util.List;
import org.immutables.value.Value;

final class AzulZuluJdkDistribution implements JdkDistribution {
// See https://docs.azul.com/core/zulu-openjdk/versioning-and-naming for flag details.
private static final ImmutableSet<String> BUNDLE_FLAGS =
ImmutableSet.of("ea", "embvm", "cp1", "cp2", "cp3", "c2", "criu", "cr", "crac");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a criu version of the JDK?? Interesting....

Copy link
Contributor Author

@j-baker j-baker Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth saying: some of these flags are discontinued! (embvm is one). One only works for 32-bit ARM. The docs are very clear that just because a flag exists doesn't necessarily mean you can acquire a JVM with it set!


@Override
public String defaultBaseUrl() {
return "https://cdn.azul.com/zulu/bin";
Expand Down Expand Up @@ -84,16 +91,26 @@ private static Extension extension(Os operatingSystem) {
}

static ZuluVersionSplit splitCombinedVersion(String combinedVersion) {
String[] split = combinedVersion.split("-", -1);
List<String> split = Arrays.asList(combinedVersion.split("-", -1));

if (split.size() < 2) {
throw new IllegalArgumentException(String.format(
"Expected %s to split into at least two parts, split into %d", combinedVersion, split.size()));
}

int endOfFlags = 1;
while (endOfFlags < split.size() && BUNDLE_FLAGS.contains(split.get(endOfFlags))) {
endOfFlags++;
}

if (split.length != 2) {
if (endOfFlags == split.size()) {
throw new IllegalArgumentException(
String.format("Expected %s to split into two parts, split into %d", combinedVersion, split.length));
String.format("Expected %s to split into two versions, split into one.", combinedVersion));
}

return ZuluVersionSplit.builder()
.zuluVersion(split[0])
.javaVersion(split[1])
.zuluVersion(String.join("-", split.subList(0, endOfFlags)))
.javaVersion(String.join("-", split.subList(endOfFlags, split.size())))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ void zulu_version_combination_survives_roundtrip() {
assertThat(versionSplit.zuluVersion()).isEqualTo("11.22.33");
}

@Test
void zulu_version_combination_supports_bundle_flags() {
ZuluVersionSplit versionSplit = AzulZuluJdkDistribution.splitCombinedVersion(
ZuluVersionUtils.combineZuluVersions("19.0.21-ea", "19.0.0-ea.6"));
assertThat(versionSplit.zuluVersion()).isEqualTo("19.0.21-ea");
assertThat(versionSplit.javaVersion()).isEqualTo("19.0.0-ea.6");
}

@Test
void jdk_path_linux_x86_64() {
AzulZuluJdkDistribution distribution = new AzulZuluJdkDistribution();
Expand Down