Skip to content

Commit

Permalink
[Build] Make JdkDownload Plugin configuration cache compatible
Browse files Browse the repository at this point in the history
Also Fix zulu 8 download that we still use for testing old es versions
  • Loading branch information
breskeby committed Nov 20, 2024
1 parent db63a28 commit 0aea1df
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

package org.elasticsearch.gradle.internal


import spock.lang.Unroll
import com.github.tomakehurst.wiremock.WireMockServer

Expand All @@ -24,22 +23,19 @@ import java.nio.file.Paths
import java.util.regex.Matcher
import java.util.regex.Pattern

import static org.elasticsearch.gradle.internal.JdkDownloadPlugin.VENDOR_ADOPTIUM
import static org.elasticsearch.gradle.internal.JdkDownloadPlugin.VENDOR_OPENJDK
import static org.elasticsearch.gradle.internal.JdkDownloadPlugin.*

class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {

private static final String OPENJDK_VERSION_OLD = "1+99"
private static final String ADOPT_JDK_VERSION = "12.0.2+10"
private static final String ADOPT_JDK_VERSION_11 = "11.0.10+9"
private static final String ADOPT_JDK_VERSION_15 = "15.0.2+7"
private static final String AZUL_JDK_VERSION_8 = "8u302+b08"
private static final String AZUL_8_DISTRO_VERSION = "8.56.0.23"
private static final String OPEN_JDK_VERSION = "12.0.1+99@123456789123456789123456789abcde"
private static final Pattern JDK_HOME_LOGLINE = Pattern.compile("JDK HOME: (.*)")

def setup() {
configurationCacheCompatible = false
}

@Unroll
def "jdk #jdkVendor for #platform#suffix are downloaded and extracted"() {
given:
Expand All @@ -56,14 +52,16 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
version = '$jdkVersion'
platform = "$platform"
architecture = '$arch'
distributionVersion = '$distributionVersion'
}
}
def theJdks = jdks
// def theJdks = jdks
tasks.register("getJdk") {
dependsOn jdks.myJdk
def jdk = jdks.myJdk
doLast {
println "JDK HOME: " + theJdks.myJdk
println "JDK HOME: " + jdk
}
}
"""
Expand All @@ -78,22 +76,23 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
assertExtraction(result.output, expectedJavaBin);

where:
platform | arch | jdkVendor | jdkVersion | expectedJavaBin | suffix
"linux" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "bin/java" | ""
"linux" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "bin/java" | ""
"linux" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "bin/java" | "(old version)"
"windows" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "bin/java" | ""
"windows" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "bin/java" | ""
"windows" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "bin/java" | "(old version)"
"darwin" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "Contents/Home/bin/java" | ""
"darwin" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "Contents/Home/bin/java" | ""
"darwin" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "Contents/Home/bin/java" | "(old version)"
"mac" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | "Contents/Home/bin/java" | ""
"mac" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | "Contents/Home/bin/java" | "(old version)"
"darwin" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "Contents/Home/bin/java" | ""
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "bin/java" | ""
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION_11 | "bin/java" | "(jdk 11)"
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION_15 | "bin/java" | "(jdk 15)"
platform | arch | jdkVendor | jdkVersion | distributionVersion | expectedJavaBin | suffix
"linux" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | null | "bin/java" | ""
"linux" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | null | "bin/java" | ""
"linux" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | null | "bin/java" | "(old version)"
"windows" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | null | "bin/java" | ""
"windows" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | null | "bin/java" | ""
"windows" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | null | "bin/java" | "(old version)"
"darwin" | "x64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | null | "Contents/Home/bin/java" | ""
"darwin" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | null | "Contents/Home/bin/java" | ""
"darwin" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | null | "Contents/Home/bin/java" | "(old version)"
"mac" | "x64" | VENDOR_OPENJDK | OPEN_JDK_VERSION | null | "Contents/Home/bin/java" | ""
"mac" | "x64" | VENDOR_OPENJDK | OPENJDK_VERSION_OLD | null | "Contents/Home/bin/java" | "(old version)"
"darwin" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | null | "Contents/Home/bin/java" | ""
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | null | "bin/java" | ""
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION_11 | null | "bin/java" | "(jdk 11)"
"linux" | "aarch64" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION_15 | null | "bin/java" | "(jdk 15)"
"darwin" | "aarch64" | VENDOR_ZULU | AZUL_JDK_VERSION_8 | AZUL_8_DISTRO_VERSION | "Contents/Home/bin/java" | "(jdk 8)"
}

def "transforms are reused across projects"() {
Expand All @@ -118,9 +117,10 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
}
}
tasks.register("getJdk") {
dependsOn jdks.myJdk
def jdk = jdks.myJdk
dependsOn jdk
doLast {
println "JDK HOME: " + jdks.myJdk
println "JDK HOME: " + jdk
}
}
"""
Expand All @@ -137,7 +137,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
result.output.count("Unpacking linux-12.0.2-x64.tar.gz using ${SymbolicLinkPreservingUntarTransform.simpleName}") == 1

where:
platform | jdkVendor | jdkVersion | expectedJavaBin
platform | jdkVendor | jdkVersion | expectedJavaBin
"linux" | VENDOR_ADOPTIUM | ADOPT_JDK_VERSION | "bin/java"
}

Expand All @@ -159,6 +159,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
vendor = '$VENDOR_ADOPTIUM'
version = '$ADOPT_JDK_VERSION'
platform = "$platform"
distributionVersion = '$ADOPT_JDK_VERSION'
architecture = "x64"
}
}
Expand Down Expand Up @@ -204,6 +205,8 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
assert matcher.find() == true;
String jdkHome = matcher.group(1);
Path javaPath = Paths.get(jdkHome, javaBin);
println "canonical " + javaPath.toFile().getCanonicalPath()
Paths.get(jdkHome).toFile().listFiles().each { println it }
assert Files.exists(javaPath) == true;
true
}
Expand All @@ -221,15 +224,26 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
final String versionPath = isOld ? "jdk1/99" : "jdk12.0.1/123456789123456789123456789abcde/99";
final String filename = "openjdk-" + (isOld ? "1" : "12.0.1") + "_" + effectivePlatform + "-x64_bin." + extension(platform);
return "/java/GA/" + versionPath + "/GPL/" + filename;
} else if (vendor.equals(VENDOR_ZULU)) {
// we only have a single version of zulu currently in the tests
return "/zulu/bin/zulu8.56.0.23-ca-jdk8.0.302-macosx_aarch64.tar.gz"
}
}

private static byte[] filebytes(final String vendor, final String platform) throws IOException {
final String effectivePlatform = getPlatform(vendor, platform);
if (vendor.equals(VENDOR_ADOPTIUM)) {
return JdkDownloadPluginFuncTest.class.getResourceAsStream("fake_adoptium_" + effectivePlatform + "." + extension(platform)).getBytes()
return JdkDownloadPluginFuncTest.class.getResourceAsStream(
"fake_adoptium_" + effectivePlatform + "." + extension(platform)
).getBytes()
} else if (vendor.equals(VENDOR_OPENJDK)) {
JdkDownloadPluginFuncTest.class.getResourceAsStream("fake_openjdk_" + effectivePlatform + "." + extension(platform)).getBytes()
return JdkDownloadPluginFuncTest.class.getResourceAsStream(
"fake_openjdk_" + effectivePlatform + "." + extension(platform)
).getBytes()
} else {
// zulu
String resourcePath = "fake_zulu_" + effectivePlatform + "." + extension(platform)
return JdkDownloadPluginFuncTest.class.getResourceAsStream(resourcePath).getBytes()
}
}

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.gradle.api.Buildable;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.TaskDependency;
Expand All @@ -33,20 +34,22 @@ public class Jdk implements Buildable, Iterable<File> {
private static final Pattern LEGACY_VERSION_PATTERN = Pattern.compile("(\\d)(u\\d+)\\+(b\\d+?)(@([a-f0-9]{32}))?");

private final String name;
private final Configuration configuration;
private final FileCollection configuration;

private final Property<String> vendor;
private final Property<String> version;
private final Property<String> platform;
private final Property<String> architecture;
private final Property<String> distributionVersion;
private final String configurationName;
private String baseVersion;
private String major;
private String build;
private String hash;

Jdk(String name, Configuration configuration, ObjectFactory objectFactory) {
this.name = name;
this.configurationName = configuration.getName();
this.configuration = configuration;
this.vendor = objectFactory.property(String.class);
this.version = objectFactory.property(String.class);
Expand Down Expand Up @@ -137,7 +140,7 @@ public String getPath() {
}

public String getConfigurationName() {
return configuration.getName();
return configurationName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.attributes.Attribute;

import java.util.Arrays;

/**
* @deprecated We wanna get rid from this and custom jdk downloads via this plugin and
* make leverage the gradle toolchain resolver capabilities.
Expand All @@ -38,8 +36,8 @@ public class JdkDownloadPlugin implements Plugin<Project> {

private static final String REPO_NAME_PREFIX = "jdk_repo_";
private static final String EXTENSION_NAME = "jdks";
public static final String JDK_TRIMMED_PREFIX = "(jdk-?\\d.*)|(zulu-?\\d.+).jdk";
public static final String ZULU_LINUX_AARCH_PATTERN = "zulu.*linux_aarch64";
public static final String JDK_TRIMMED_PREFIX = "(jdk-?\\d.*)|(zulu-?\\d.*).jdk";
public static final String ZULU_LINUX_AARCH_PATTERN = "zulu.*_aarch64";

@Override
public void apply(Project project) {
Expand All @@ -66,7 +64,8 @@ public void apply(Project project) {
.attribute(jdkAttribute, true);
transformSpec.parameters(parameters -> {
parameters.setTrimmedPrefixPattern(JDK_TRIMMED_PREFIX);
parameters.setKeepStructureFor(Arrays.asList(ZULU_LINUX_AARCH_PATTERN));
// parameters.setAsFiletreeOutput(true);
// parameters.setKeepStructureFor(Arrays.asList(ZULU_LINUX_AARCH_PATTERN));
});
});

Expand Down

0 comments on commit 0aea1df

Please sign in to comment.