Skip to content

Commit

Permalink
[7.17] Update to Gradle 7.6 (#89796) (#92235)
Browse files Browse the repository at this point in the history
* Fix TestResultProcessor api changes
* Fix inputs for generateProviderManifest
* Ignore tests for now until gradle has fixed reporting issue
* Fix dependency substitution in example plugins build
* Use right java bin path on windows
* Add hint to task onlyif when no docker is available
  • Loading branch information
breskeby committed Dec 8, 2022
1 parent 6a20678 commit fc43f01
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 107 deletions.
5 changes: 3 additions & 2 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=db9c8211ed63f61f60292c69e80d89196f9eb36665e369e7f00ac4cc841c2219
distributionSha256Sum=312eb12875e1747e05c2f81a4789902d7e4ec5defbd1eefeaccc08acf096505d
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ if (BuildParams.getIsRuntimeJavaHomeSet()) {
configure(allprojects) {
project.tasks.withType(Test).configureEach { Test test ->
if (BuildParams.getIsRuntimeJavaHomeSet()) {
test.executable = "${BuildParams.runtimeJavaHome}/bin/java"
test.executable = "${BuildParams.runtimeJavaHome}/bin/java" +
(OS.current() == OS.WINDOWS ? '.exe' : '')
}
}
}
Expand All @@ -36,7 +37,8 @@ if (BuildParams.getIsRuntimeJavaHomeSet()) {
configure(allprojects) {
project.tasks.withType(Test).configureEach { Test test ->
test.dependsOn(rootProject.jdks.provisioned_runtime)
test.executable = rootProject.jdks.provisioned_runtime.getBinJavaPath()
test.executable = "${BuildParams.runtimeJavaHome}/bin/java" +
(OS.current() == OS.WINDOWS ? '.exe' : '')
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void apply(Project project) {
DockerSupportPlugin.DOCKER_SUPPORT_SERVICE_NAME
);
distributionDownloadPlugin.setDockerAvailability(
dockerSupport.map(dockerSupportService -> dockerSupportService.getDockerAvailability().isAvailable)
dockerSupport.map(dockerSupportService -> dockerSupportService.getDockerAvailability().isAvailable())
);
registerInternalDistributionResolutions(DistributionDownloadPlugin.getRegistrationsContainer(project));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public abstract class DockerSupportService implements BuildService<DockerSupport
private static final Logger LOGGER = Logging.getLogger(DockerSupportService.class);
// Defines the possible locations of the Docker CLI. These will be searched in order.
private static final String[] DOCKER_BINARIES = { "/usr/bin/docker", "/usr/local/bin/docker" };
private static final String[] DOCKER_COMPOSE_BINARIES = { "/usr/local/bin/docker-compose", "/usr/bin/docker-compose" };
private static final String[] DOCKER_COMPOSE_BINARIES = {
"/usr/local/bin/docker-compose",
"/usr/bin/docker-compose",
"/usr/libexec/docker/cli-plugins/docker-compose" };
private static final Version MINIMUM_DOCKER_VERSION = Version.fromString("17.05.0");

private final ExecOperations execOperations;
Expand All @@ -67,6 +70,7 @@ public DockerSupportService(ExecOperations execOperations) {
public DockerAvailability getDockerAvailability() {
if (this.dockerAvailability == null) {
String dockerPath = null;
String dockerComposePath = null;
Result lastResult = null;
Version version = null;
boolean isVersionHighEnough = false;
Expand Down Expand Up @@ -98,13 +102,15 @@ public DockerAvailability getDockerAvailability() {
Optional<String> composePath = getDockerComposePath();
if (lastResult.isSuccess() && composePath.isPresent()) {
isComposeAvailable = runCommand(composePath.get(), "version").isSuccess();
dockerComposePath = composePath.get();
}

// Now let's check if buildx is available and what supported platforms exist
if (lastResult.isSuccess()) {
Result buildxResult = runCommand(dockerPath, "buildx", "inspect", "--bootstrap");
if (buildxResult.isSuccess()) {
supportedArchitectures = buildxResult.stdout.lines()
supportedArchitectures = buildxResult.stdout()
.lines()
.filter(l -> l.startsWith("Platforms:"))
.map(l -> l.substring(10))
.flatMap(l -> Arrays.stream(l.split(",")).filter(not(String::isBlank)))
Expand All @@ -128,6 +134,7 @@ public DockerAvailability getDockerAvailability() {
isComposeAvailable,
isVersionHighEnough,
dockerPath,
dockerComposePath,
version,
lastResult,
supportedArchitectures
Expand Down Expand Up @@ -180,8 +187,11 @@ void failIfDockerUnavailable(List<String> tasks) {
// Some other problem, print the error
final String message = String.format(
Locale.ROOT,
"a problem occurred while using Docker from [%s]%s yet it is required to run the following task%s: \n%s\n"
+ "the problem is that Docker exited with exit code [%d] with standard error output:\n%s",
"""
a problem occurred while using Docker from [%s]%s yet it is required to run the following task%s:
%s
the problem is that Docker exited with exit code [%d] with standard error output:
%s""",
availability.path,
availability.version == null ? "" : " v" + availability.version,
tasks.size() > 1 ? "s" : "",
Expand Down Expand Up @@ -331,8 +341,8 @@ private Result runCommand(String... args) {
/**
* An immutable class that represents the results of a Docker search from {@link #getDockerAvailability()}}.
*/
public static class DockerAvailability {
/**
public record DockerAvailability(
/*
* Indicates whether Docker is available and meets the required criteria.
* True if, and only if, Docker is:
* <ul>
Expand All @@ -342,76 +352,38 @@ public static class DockerAvailability {
* <li>Can execute a command that requires privileges</li>
* </ul>
*/
public final boolean isAvailable;
boolean isAvailable,

/**
* True if docker-compose is available.
*/
public final boolean isComposeAvailable;
// True if docker-compose is available.
boolean isComposeAvailable,

/**
* True if the installed Docker version is &gt;= 17.05
*/
public final boolean isVersionHighEnough;
// True if the installed Docker version is &gt,= 17.05
boolean isVersionHighEnough,

/**
* The path to the Docker CLI, or null
*/
public final String path;
// The path to the Docker CLI, or null
String path,

/**
* The installed Docker version, or null
*/
public final Version version;
// The path to the Docker Compose CLI, or null
String dockerComposePath,

/**
* Information about the last command executes while probing Docker, or null.
*/
final Result lastCommand;
// The installed Docker version, or null
Version version,

// Information about the last command executes while probing Docker, or null.
Result lastCommand,

// Supported build architectures
public final Set<Architecture> supportedArchitectures;

DockerAvailability(
boolean isAvailable,
boolean isComposeAvailable,
boolean isVersionHighEnough,
String path,
Version version,
Result lastCommand,
Set<Architecture> supportedArchitectures
) {
this.isAvailable = isAvailable;
this.isComposeAvailable = isComposeAvailable;
this.isVersionHighEnough = isVersionHighEnough;
this.path = path;
this.version = version;
this.lastCommand = lastCommand;
this.supportedArchitectures = supportedArchitectures;
}
}
Set<Architecture> supportedArchitectures
) {}

/**
* This class models the result of running a command. It captures the exit code, standard output and standard error.
*/
private static class Result {
final int exitCode;
final String stdout;
final String stderr;

Result(int exitCode, String stdout, String stderr) {
this.exitCode = exitCode;
this.stdout = stdout;
this.stderr = stderr;
}
private record Result(int exitCode, String stdout, String stderr) {

boolean isSuccess() {
return exitCode == 0;
}

public String toString() {
return "exitCode = [" + exitCode + "] " + "stdout = [" + stdout.trim() + "] " + "stderr = [" + stderr.trim() + "]";
}
}

interface Parameters extends BuildServiceParameters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.elasticsearch.gradle.internal.conventions.info.GitInfo;
import org.elasticsearch.gradle.internal.conventions.info.ParallelDetector;
import org.elasticsearch.gradle.internal.conventions.util.Util;
import org.elasticsearch.gradle.util.GradleUtils;
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
Expand All @@ -24,6 +26,9 @@
import org.gradle.internal.jvm.inspection.JvmInstallationMetadata;
import org.gradle.internal.jvm.inspection.JvmMetadataDetector;
import org.gradle.internal.jvm.inspection.JvmVendor;
import org.gradle.jvm.toolchain.JavaLanguageVersion;
import org.gradle.jvm.toolchain.JavaToolchainSpec;
import org.gradle.jvm.toolchain.JvmVendorSpec;
import org.gradle.jvm.toolchain.internal.InstallationLocation;
import org.gradle.jvm.toolchain.internal.JavaInstallationRegistry;
import org.gradle.util.GradleVersion;
Expand All @@ -41,6 +46,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -49,7 +55,6 @@
public class GlobalBuildInfoPlugin implements Plugin<Project> {
private static final Logger LOGGER = Logging.getLogger(GlobalBuildInfoPlugin.class);
private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/elasticsearch/Version.java";
private static Boolean _isBundledJdkSupported = null;

private final JavaInstallationRegistry javaInstallationRegistry;
private final JvmMetadataDetector metadataDetector;
Expand Down Expand Up @@ -80,16 +85,23 @@ public void apply(Project project) {
JavaVersion minimumRuntimeVersion = JavaVersion.toVersion(getResourceContents("/minimumRuntimeVersion"));

File runtimeJavaHome = findRuntimeJavaHome();
boolean isRuntimeJavaHomeSet = Jvm.current().getJavaHome().equals(runtimeJavaHome) == false;

File rootDir = project.getRootDir();
GitInfo gitInfo = GitInfo.gitInfo(rootDir);

BuildParams.init(params -> {
params.reset();
params.setRuntimeJavaHome(runtimeJavaHome);
params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion));
params.setIsRuntimeJavaHomeSet(Jvm.current().getJavaHome().equals(runtimeJavaHome) == false);
JvmInstallationMetadata runtimeJdkMetaData = metadataDetector.getMetadata(getJavaInstallation(runtimeJavaHome).getLocation());
params.setRuntimeJavaVersion(
determineJavaVersion(
"runtime java.home",
runtimeJavaHome,
isRuntimeJavaHomeSet ? minimumRuntimeVersion : Jvm.current().getJavaVersion()
)
);
params.setIsRuntimeJavaHomeSet(isRuntimeJavaHomeSet);
JvmInstallationMetadata runtimeJdkMetaData = metadataDetector.getMetadata(getJavaInstallation(runtimeJavaHome));
params.setRuntimeJavaDetails(formatJavaVendorDetails(runtimeJdkMetaData));
params.setJavaVersions(getAvailableJavaVersions());
params.setMinimumCompilerVersion(minimumCompilerVersion);
Expand All @@ -103,14 +115,18 @@ public void apply(Project project) {
params.setDefaultParallel(ParallelDetector.findDefaultParallel(project));
params.setInFipsJvm(Util.getBooleanProperty("tests.fips.enabled", false));
params.setIsSnapshotBuild(Util.getBooleanProperty("build.snapshot", true));
params.setBwcVersions(providers.provider(() -> resolveBwcVersions(rootDir)));
AtomicReference<BwcVersions> cache = new AtomicReference<>();
params.setBwcVersions(providers.provider(() -> cache.updateAndGet(val -> val == null ? resolveBwcVersions(rootDir) : val)));
});

// Enforce the minimum compiler version
assertMinimumCompilerVersion(minimumCompilerVersion);

// Print global build info header just before task execution
project.getGradle().getTaskGraph().whenReady(graph -> logGlobalBuildInfo());
// Only do this if we are the root build of a composite
if (GradleUtils.isIncludedBuild(project) == false) {
project.getGradle().getTaskGraph().whenReady(graph -> logGlobalBuildInfo());
}
}

private String formatJavaVendorDetails(JvmInstallationMetadata runtimeJdkMetaData) {
Expand All @@ -136,33 +152,39 @@ private void logGlobalBuildInfo() {
final String osVersion = System.getProperty("os.version");
final String osArch = System.getProperty("os.arch");
final Jvm gradleJvm = Jvm.current();
JvmInstallationMetadata gradleJvmMetadata = metadataDetector.getMetadata(gradleJvm.getJavaHome());
JvmInstallationMetadata gradleJvmMetadata = metadataDetector.getMetadata(getJavaInstallation(gradleJvm.getJavaHome()));
final String gradleJvmVendorDetails = gradleJvmMetadata.getVendor().getDisplayName();
final String gradleJvmImplementationVersion = gradleJvmMetadata.getImplementationVersion();
final String gradleJvmImplementationVersion = gradleJvmMetadata.getJvmVersion();
LOGGER.quiet("=======================================");
LOGGER.quiet("Elasticsearch Build Hamster says Hello!");
LOGGER.quiet(" Gradle Version : " + GradleVersion.current().getVersion());
LOGGER.quiet(" OS Info : " + osName + " " + osVersion + " (" + osArch + ")");
if (BuildParams.getIsRuntimeJavaHomeSet()) {
JvmInstallationMetadata runtimeJvm = metadataDetector.getMetadata(BuildParams.getRuntimeJavaHome());
JvmInstallationMetadata runtimeJvm = metadataDetector.getMetadata(getJavaInstallation(BuildParams.getRuntimeJavaHome()));
final String runtimeJvmVendorDetails = runtimeJvm.getVendor().getDisplayName();
final String runtimeJvmImplementationVersion = runtimeJvm.getImplementationVersion();
LOGGER.quiet(" Runtime JDK Version : " + runtimeJvmImplementationVersion + " (" + runtimeJvmVendorDetails + ")");
final String runtimeJvmImplementationVersion = runtimeJvm.getJvmVersion();
final String runtimeVersion = runtimeJvm.getRuntimeVersion();
final String runtimeExtraDetails = runtimeJvmVendorDetails + ", " + runtimeVersion;
LOGGER.quiet(" Runtime JDK Version : " + runtimeJvmImplementationVersion + " (" + runtimeExtraDetails + ")");
LOGGER.quiet(" Runtime java.home : " + BuildParams.getRuntimeJavaHome());
LOGGER.quiet(" Gradle JDK Version : " + gradleJvmImplementationVersion + " (" + gradleJvmVendorDetails + ")");
LOGGER.quiet(" Gradle java.home : " + gradleJvm.getJavaHome());
} else {
LOGGER.quiet(" JDK Version : " + gradleJvmImplementationVersion + " (" + gradleJvmVendorDetails + ")");
LOGGER.quiet(" JAVA_HOME : " + gradleJvm.getJavaHome());
}
String javaToolchainHome = System.getenv("JAVA_TOOLCHAIN_HOME");
if (javaToolchainHome != null) {
LOGGER.quiet(" JAVA_TOOLCHAIN_HOME : " + javaToolchainHome);
}
LOGGER.quiet(" Random Testing Seed : " + BuildParams.getTestSeed());
LOGGER.quiet(" In FIPS 140 mode : " + BuildParams.isInFipsJvm());
LOGGER.quiet("=======================================");
}

private JavaVersion determineJavaVersion(String description, File javaHome, JavaVersion requiredVersion) {
InstallationLocation installation = getJavaInstallation(javaHome);
JavaVersion actualVersion = metadataDetector.getMetadata(installation.getLocation()).getLanguageVersion();
JavaVersion actualVersion = metadataDetector.getMetadata(installation).getLanguageVersion();
if (actualVersion.isCompatibleWith(requiredVersion) == false) {
throwInvalidJavaHomeException(
description,
Expand Down Expand Up @@ -195,10 +217,9 @@ private boolean isSameFile(File javaHome, InstallationLocation installationLocat
*/
private List<JavaHome> getAvailableJavaVersions() {
return getAvailableJavaInstallationLocationSteam().map(installationLocation -> {
File installationDir = installationLocation.getLocation();
JvmInstallationMetadata metadata = metadataDetector.getMetadata(installationDir);
JvmInstallationMetadata metadata = metadataDetector.getMetadata(installationLocation);
int actualVersion = Integer.parseInt(metadata.getLanguageVersion().getMajorVersion());
return JavaHome.of(actualVersion, providers.provider(() -> installationDir));
return JavaHome.of(actualVersion, providers.provider(() -> installationLocation.getLocation()));
}).collect(Collectors.toList());
}

Expand Down Expand Up @@ -249,8 +270,13 @@ private File findRuntimeJavaHome() {
if (runtimeJavaProperty != null) {
return new File(findJavaHome(runtimeJavaProperty));
}

return System.getenv("RUNTIME_JAVA_HOME") == null ? Jvm.current().getJavaHome() : new File(System.getenv("RUNTIME_JAVA_HOME"));
String env = System.getenv("RUNTIME_JAVA_HOME");
if (env != null) {
return new File(env);
}
// fall back to tool chain if set.
env = System.getenv("JAVA_TOOLCHAIN_HOME");
return env == null ? Jvm.current().getJavaHome() : new File(env);
}

private String findJavaHome(String version) {
Expand Down Expand Up @@ -316,13 +342,28 @@ private static class ErrorTraceMetadataDetector implements JvmMetadataDetector {
}

@Override
public JvmInstallationMetadata getMetadata(File file) {
JvmInstallationMetadata metadata = delegate.getMetadata(file);
public JvmInstallationMetadata getMetadata(InstallationLocation installationLocation) {
JvmInstallationMetadata metadata = delegate.getMetadata(installationLocation);
if (metadata instanceof JvmInstallationMetadata.FailureInstallationMetadata) {
throw new GradleException("Jvm Metadata cannot be resolved for " + metadata.getJavaHome().toString());
}
return metadata;
}
}

private static class MetadataBasedToolChainMatcher implements Action<JavaToolchainSpec> {
private final JvmVendorSpec expectedVendorSpec;
private final JavaLanguageVersion expectedJavaLanguageVersion;

public MetadataBasedToolChainMatcher(JvmInstallationMetadata metadata) {
expectedVendorSpec = JvmVendorSpec.matching(metadata.getVendor().getRawVendor());
expectedJavaLanguageVersion = JavaLanguageVersion.of(metadata.getLanguageVersion().getMajorVersion());
}

@Override
public void execute(JavaToolchainSpec spec) {
spec.getVendor().set(expectedVendorSpec);
spec.getLanguageVersion().set(expectedJavaLanguageVersion);
}
}
}

0 comments on commit fc43f01

Please sign in to comment.