Skip to content

Commit

Permalink
Support feature crac for Azul Zulu
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez committed Jul 20, 2023
1 parent b592cd1 commit 2c2b5ac
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 35 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/update-zulu-crac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Update Azul Zulu CRaC

on:
schedule:
- cron: 0 15 * * 1-5
workflow_dispatch:

jobs:
run:
name: "Run Java Migration for Azul Zulu CRaC"
strategy:
fail-fast: false
matrix:
java-version: [ 17 ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Java 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
cache: 'maven'
- name: Run azul-zulu
run: ./mvnw spring-boot:run -Dspring-boot.run.arguments="--foojay.java.distribution=zulu --foojay.distribution.version=${{ matrix.java-version }} --foojay.java.release-status=ga --foojay.java.features=crac"
env:
SDKMAN_RELEASE_CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
SDKMAN_RELEASE_CONSUMER_TOKEN: ${{ secrets.CONSUMER_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sdkman.automigration.adapters;

import io.sdkman.automigration.models.FoojayQueryParams;
import org.springframework.util.StringUtils;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -55,7 +56,8 @@ public static Map<String, List<String>> toQueryParams(FoojayQueryParams foojayQu
"architecture", List.of(foojayQueryParams.vendorOsProperties().architecture()),
"archive_type", List.of(foojayQueryParams.vendorOsProperties().archiveType()),
"distribution", List.of(foojayQueryParams.distribution()),
"javafx_bundled", List.of(String.valueOf(foojayQueryParams.javafxBundled())));
"javafx_bundled", List.of(String.valueOf(foojayQueryParams.javafxBundled())),
"feature", List.of(StringUtils.commaDelimitedListToStringArray(foojayQueryParams.features())));
// @formatter:on

return Stream
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/io/sdkman/automigration/entrypoints/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.List;

Expand All @@ -35,27 +36,37 @@ CommandLineRunner runner() {
var javafxBundled = this.environment.getProperty("foojay.java.javafx-bundled", Boolean.class, false);
var javaVersion = this.environment.getProperty("foojay.java.version", String.class);
var defaultCandidate = this.environment.getProperty("sdkman.default.candidate", Boolean.class);
var features = this.environment.getProperty("foojay.java.features", String.class);

var distributionConfigurationPropertyName = resolveConfigurationPropertyName(distribution, features);
var vendorProperties = Binder.get(this.environment)
.bind(ConfigurationPropertyName.of("sdkman").append(distribution.replace("_", "-")),
Bindable.of(VendorProperties.class))
.orElse(null);
.bind(distributionConfigurationPropertyName, Bindable.of(VendorProperties.class)).orElse(null);

process(vendorProperties.linux(), distribution, version, javaVersion, releaseStatus, "linux", javafxBundled,
defaultCandidate);
defaultCandidate, features);
process(vendorProperties.macos(), distribution, version, javaVersion, releaseStatus, "macos", javafxBundled,
defaultCandidate);
defaultCandidate, features);
process(vendorProperties.windows(), distribution, version, javaVersion, releaseStatus, "windows",
javafxBundled, defaultCandidate);
javafxBundled, defaultCandidate, features);
};
}

private static ConfigurationPropertyName resolveConfigurationPropertyName(String distribution, String features) {
var distributionConfigurationPropertyName = ConfigurationPropertyName.of("sdkman")
.append(distribution.replace("_", "-"));
if (StringUtils.hasText(features)) {
return distributionConfigurationPropertyName.append(features);
}
return distributionConfigurationPropertyName;
}

void process(List<VendorProperties.OS> os, String distribution, String version, String javaVersion,
String releaseStatus, String operatingSystem, boolean javafxBundled, Boolean defaultCandidate) {
String releaseStatus, String operatingSystem, boolean javafxBundled, Boolean defaultCandidate,
String features) {
if (os != null) {
os.stream().map(vendorProperties -> {
var foojayQueryParams = new FoojayQueryParams(distribution, version, javaVersion, releaseStatus,
operatingSystem, javafxBundled, vendorProperties);
operatingSystem, javafxBundled, features, vendorProperties);
return PackageAdapter.toQueryParams(foojayQueryParams);
}).forEach(queryParams -> this.javaMigration.execute(queryParams, defaultCandidate));
}
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/io/sdkman/automigration/logic/Version.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sdkman.automigration.logic;

import io.sdkman.automigration.wire.in.Feature;
import io.sdkman.automigration.wire.in.PackageResponse;

import java.util.Optional;
Expand All @@ -16,7 +17,8 @@ public static Optional<String> format(PackageResponse packageResponse) {
if (matcher.find()) {
var javaVersion = matcher.group();
return switch (packageResponse.distribution()) {
case "liberica", "zulu" -> javaFxVersion(javaVersion, packageResponse);
case "liberica" -> resolveLibericaVersion(javaVersion, packageResponse);
case "zulu" -> resolveZuluVersion(javaVersion, packageResponse);
case "oracle_open_jdk" -> openjdkVersion(javaVersion, packageResponse);
case "gluon_graalvm", "graalvm_ce8", "graalvm_ce11", "graalvm_ce17", "graalvm_ce19", "liberica_native",
"mandrel" ->
Expand All @@ -32,7 +34,7 @@ private static Optional<String> javaFxVersion(String javaVersion, PackageRespons
var javaVersionWithFxSuffix = "%s.fx".formatted(javaVersion);
return Optional.of(javaVersionWithFxSuffix);
}
return Optional.of(javaVersion);
return Optional.empty();
}

private static Optional<String> openjdkVersion(String javaVersion, PackageResponse packageResponse) {
Expand All @@ -48,4 +50,23 @@ private static Optional<String> graalVmVersion(String javaVersion, PackageRespon
return Optional.of("%s.r%s".formatted(javaVersion, packageResponse.jdkVersion()));
}

private static Optional<String> resolveLibericaVersion(String javaVersion, PackageResponse packageResponse) {
Optional<String> javaFxVersion = javaFxVersion(javaVersion, packageResponse);
if (javaFxVersion.isPresent()) {
return javaFxVersion;
}
return Optional.of(javaVersion);
}

private static Optional<String> resolveZuluVersion(String javaVersion, PackageResponse packageResponse) {
Optional<String> javaFxVersion = javaFxVersion(javaVersion, packageResponse);
if (javaFxVersion.isPresent()) {
return javaFxVersion;
}
else if (!packageResponse.feature().isEmpty() && packageResponse.feature().contains(new Feature("CRAC"))) {
return Optional.of("%s.crac".formatted(javaVersion));
}
return Optional.of(javaVersion);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package io.sdkman.automigration.models;

public record FoojayQueryParams(String distribution, String version, String javaVersion, String releaseStatus,
String os, boolean javafxBundled, VendorProperties.OS vendorOsProperties) {
String os, boolean javafxBundled, String features, VendorProperties.OS vendorOsProperties) {
}
4 changes: 4 additions & 0 deletions src/main/java/io/sdkman/automigration/wire/in/Feature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.sdkman.automigration.wire.in;

public record Feature(String name) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

// @formatter:off
public record PackageResponse(String distribution,
String architecture,
Expand All @@ -16,6 +18,7 @@ public record PackageResponse(String distribution,
String releaseStatus,
@JsonProperty("javafx_bundled")
boolean javafxBundled,
Links links) {
Links links,
List<Feature> feature) {
}
// @formatter:on
6 changes: 6 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,9 @@ sdkman.zulu.macos[1].architecture=arm64
sdkman.zulu.macos[1].archive-type=tar.gz
sdkman.zulu.windows[0].architecture=amd64
sdkman.zulu.windows[0].archive-type=zip

#Zulu CRaC
sdkman.zulu.crac.linux[0].architecture=amd64
sdkman.zulu.crac.linux[0].archive-type=tar.gz
sdkman.zulu.crac.linux[1].architecture=arm64
sdkman.zulu.crac.linux[1].archive-type=tar.gz
49 changes: 35 additions & 14 deletions src/test/java/io/sdkman/automigration/SdkmanDiscoMigrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.util.UriComponentsBuilder;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -63,13 +65,13 @@ void testWithDistributionsAndSdkmanReleaseWithChecksum() {
"sdkman.liberica.linux[1].archive-type=tar.gz").run(context -> {
var mockServer = context.getBean(MockRestServiceServer.class);
var commandLineRunner = context.getBean(CommandLineRunner.class);
foojayPackagesMockServer(mockServer, "8", TAR_GZ, LINUX, AMD64,
foojayPackagesMockServer(mockServer, "liberica", "8", TAR_GZ, LINUX, AMD64,
FoojayResponse.liberica80322amd64());
sdkmanBrokerMockServer(mockServer, "8.0.322-librca", HttpStatus.NOT_FOUND, LINUX_64);
foojayIdsMockServer(mockServer, FoojayResponse.idsResponseAmd64WithChecksum());
sdkmanReleaseMockServer(mockServer, SdkmanReleaseRequest.candidateAmd64WithNoChecksum());

foojayPackagesMockServer(mockServer, "8", TAR_GZ, LINUX, ARM_64,
foojayPackagesMockServer(mockServer, "liberica", "8", TAR_GZ, LINUX, ARM_64,
FoojayResponse.liberica80322arm64());
sdkmanBrokerMockServer(mockServer, "8.0.322-librca", HttpStatus.NOT_FOUND, LINUX_ARM64);
foojayIdsMockServer(mockServer, FoojayResponse.idsResponseArm64WithChecksum());
Expand All @@ -85,7 +87,7 @@ void testWithDistributionsAndSdkmanReleaseWithNoChecksum() {
"sdkman.release.consumer-token=any-token").run(context -> {
var mockServer = context.getBean(MockRestServiceServer.class);
var commandLineRunner = context.getBean(CommandLineRunner.class);
foojayPackagesMockServer(mockServer, "8", TAR_GZ, LINUX, AMD64,
foojayPackagesMockServer(mockServer, "liberica", "8", TAR_GZ, LINUX, AMD64,
FoojayResponse.liberica80322amd64());
sdkmanBrokerMockServer(mockServer, "8.0.322-librca", HttpStatus.NOT_FOUND, LINUX_64);
foojayIdsMockServer(mockServer, FoojayResponse.idsResponseWithNoChecksum());
Expand All @@ -100,7 +102,7 @@ void testWithEmptyDistributions() {
this.contextRunner.run(context -> {
var mockServer = context.getBean(MockRestServiceServer.class);
var commandLineRunner = context.getBean(CommandLineRunner.class);
foojayPackagesMockServer(mockServer, "18", TAR_GZ, LINUX, AMD64, FoojayResponse.empty());
foojayPackagesMockServer(mockServer, "liberica", "18", TAR_GZ, LINUX, AMD64, FoojayResponse.empty());
commandLineRunner.run();
mockServer.verify();
});
Expand All @@ -111,7 +113,8 @@ void testWithDistributionsAndVersionFoundInSdkmanBroker() {
this.contextRunner.withPropertyValues("foojay.distribution.version=8").run(context -> {
var mockServer = context.getBean(MockRestServiceServer.class);
var commandLineRunner = context.getBean(CommandLineRunner.class);
foojayPackagesMockServer(mockServer, "8", TAR_GZ, LINUX, AMD64, FoojayResponse.liberica80322amd64());
foojayPackagesMockServer(mockServer, "liberica", "8", TAR_GZ, LINUX, AMD64,
FoojayResponse.liberica80322amd64());
sdkmanBrokerMockServer(mockServer, "8.0.322-librca", HttpStatus.FOUND, LINUX_64);
commandLineRunner.run();
mockServer.verify();
Expand All @@ -123,7 +126,7 @@ void testWithDistributionsAndVersionIsNull() {
this.contextRunner.withPropertyValues("foojay.distribution.version=8").run(context -> {
var mockServer = context.getBean(MockRestServiceServer.class);
var commandLineRunner = context.getBean(CommandLineRunner.class);
foojayPackagesMockServer(mockServer, "8", TAR_GZ, LINUX, AMD64, FoojayResponse.liberica8());
foojayPackagesMockServer(mockServer, "liberica", "8", TAR_GZ, LINUX, AMD64, FoojayResponse.liberica8());
commandLineRunner.run();
mockServer.verify();
});
Expand All @@ -137,7 +140,7 @@ void testWithGraalVmDistributionsAndSdkmanReleaseWithNoChecksum() {
"sdkman.release.consumer-token=any-token").run(context -> {
var mockServer = context.getBean(MockRestServiceServer.class);
var commandLineRunner = context.getBean(CommandLineRunner.class);
foojayPackagesMockServer(mockServer, "22", TAR_GZ, LINUX, AMD64,
foojayPackagesMockServer(mockServer, "liberica", "22", TAR_GZ, LINUX, AMD64,
FoojayResponse.libericaNik80322amd64());
sdkmanBrokerMockServer(mockServer, "22.1.r17-nik", HttpStatus.NOT_FOUND, LINUX_64);
foojayIdsMockServer(mockServer, FoojayResponse.libericaNikIdsResponseWithNoChecksum());
Expand All @@ -153,7 +156,7 @@ void shouldReleaseDefaultCandidate() {
"sdkman.release.consumer-token=any-token", "sdkman.default.candidate=true").run(context -> {
var mockServer = context.getBean(MockRestServiceServer.class);
var commandLineRunner = context.getBean(CommandLineRunner.class);
foojayPackagesMockServer(mockServer, "8", TAR_GZ, LINUX, AMD64,
foojayPackagesMockServer(mockServer, "liberica", "8", TAR_GZ, LINUX, AMD64,
FoojayResponse.liberica80322amd64());
sdkmanBrokerMockServer(mockServer, "8.0.322-librca", HttpStatus.NOT_FOUND, LINUX_64);
foojayIdsMockServer(mockServer, FoojayResponse.idsResponseWithNoChecksum());
Expand All @@ -163,6 +166,24 @@ void shouldReleaseDefaultCandidate() {
});
}

@Test
void shouldReturnCandidateWhenFeaturesIsUsed() {
this.contextRunner.withPropertyValues("foojay.distribution.version=17", "sdkman.release.consumer-key=any-key",
"sdkman.release.consumer-token=any-token", "foojay.java.distribution=zulu", "foojay.java.features=crac",
"sdkman.zulu.crac.linux[0].architecture=amd64", "sdkman.zulu.crac.linux[0].archive-type=tar.gz")
.run(context -> {
var mockServer = context.getBean(MockRestServiceServer.class);
var commandLineRunner = context.getBean(CommandLineRunner.class);
foojayPackagesMockServer(mockServer, "zulu", "17", TAR_GZ, LINUX, AMD64,
Files.readString(Path.of("src/test/resources/feature-zulu-crac-response.json")));
sdkmanBrokerMockServer(mockServer, "17.0.7.crac-zulu", HttpStatus.NOT_FOUND, LINUX_64);
foojayIdsMockServer(mockServer, FoojayResponse.zuluCracIdsResponse());
sdkmanReleaseMockServer(mockServer, SdkmanReleaseRequest.zuluCracCandidate());
commandLineRunner.run();
mockServer.verify();
});
}

private void sdkmanReleaseMockServer(MockRestServiceServer mockServer, String request) {
// @formatter:off
mockServer.expect(ExpectedCount.once(), requestTo("http://localhost/release"))
Expand All @@ -188,24 +209,24 @@ private void foojayIdsMockServer(MockRestServiceServer mockServer, String respon
.andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(response));
}

private void foojayPackagesMockServer(MockRestServiceServer mockServer, String version, String archiveType,
String os, String architecture, String response) {
private void foojayPackagesMockServer(MockRestServiceServer mockServer, String distribution, String version,
String archiveType, String os, String architecture, String response) {
mockServer.expect(ExpectedCount.once(), request -> {
var uriComponents = UriComponentsBuilder.fromUri(request.getURI()).build();
var expectedQueryParams = uriComponents.getQueryParams().containsKey("jdk_version")
? graalVmDistributionQueryParams(version, archiveType, os, architecture)
: javaDistributionQueryParams(version, archiveType, os, architecture);
: javaDistributionQueryParams(distribution, version, archiveType, os, architecture);
assertThat(uriComponents.getPath()).isEqualTo("/disco/v3.0/packages");
assertThat(uriComponents.getQueryParams()).containsAllEntriesOf(expectedQueryParams);

}).andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON).body(response));
}

private static Map<String, List<String>> javaDistributionQueryParams(String version, String archiveType, String os,
String architecture) {
private static Map<String, List<String>> javaDistributionQueryParams(String distribution, String version,
String archiveType, String os, String architecture) {
// @formatter:off
return Map.ofEntries(entry("distribution", List.of("liberica")),
return Map.ofEntries(entry("distribution", List.of(distribution)),
entry("javafx_bundled", List.of("false")),
entry("directly_downloadable", List.of("true")),
entry("libc_type", List.of("glibc", "c_std_lib", "libc")),
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/io/sdkman/automigration/fixtures/FoojayResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,23 @@ public static String libericaNikIdsResponseWithNoChecksum() {
""";
}

public static String zuluCracIdsResponse() {
return """
{
"result":[
{
"filename":"zulu17.42.19-ca-crac-jdk17.0.7-linux_x64.tar.gz",
"direct_download_uri":"https://cdn.azul.com/zulu/bin/zulu17.42.21-ca-crac-jdk17.0.7-linux_x64.tar.gz",
"download_site_uri":"",
"signature_uri":"",
"checksum_uri":"",
"checksum":"",
"checksum_type":"sha1"
}
],
"message":""
}
""";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ public static String defaultCandidateAmd64WithNoChecksum() {
""";
}

public static String zuluCracCandidate() {
return """
{
"candidate": "java",
"version": "17.0.7.crac",
"vendor": "zulu",
"url": "https://cdn.azul.com/zulu/bin/zulu17.42.21-ca-crac-jdk17.0.7-linux_x64.tar.gz",
"platform": "LINUX_64"
}
""";
}

}
Loading

0 comments on commit 2c2b5ac

Please sign in to comment.