Skip to content

Commit

Permalink
Support Zulu bundle flags (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-baker authored Jul 29, 2022
1 parent 63c6275 commit 32f86ff
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
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");

@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

0 comments on commit 32f86ff

Please sign in to comment.