From 4c63cca69336747cbddbb8086369237236b8f0bf Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Thu, 21 Nov 2024 15:31:25 +0100 Subject: [PATCH] We need to postpone resolving minimum java version from bwc branch to task execution phase --- .../gradle/internal/BwcSetupExtension.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcSetupExtension.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcSetupExtension.java index d7bf839817e12..f487381dcd068 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcSetupExtension.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcSetupExtension.java @@ -16,6 +16,7 @@ import org.gradle.api.Action; import org.gradle.api.GradleException; import org.gradle.api.Project; +import org.gradle.api.Task; import org.gradle.api.logging.LogLevel; import org.gradle.api.model.ObjectFactory; import org.gradle.api.provider.Property; @@ -103,10 +104,17 @@ private static TaskProvider createRunBwcGradleTask( loggedExec.dependsOn("checkoutBwcBranch"); loggedExec.getWorkingDir().set(checkoutDir.get()); - loggedExec.getNonTrackedEnvironment().put("JAVA_HOME", providerFactory.of(JavaHomeValueSource.class, spec -> { - spec.getParameters().getVersion().set(unreleasedVersionInfo.map(it -> it.version())); - spec.getParameters().getCheckoutDir().set(checkoutDir); - }).flatMap(s -> getJavaHome(objectFactory, toolChainService, Integer.parseInt(s)))); + + loggedExec.doFirst(new Action() { + @Override + public void execute(Task task) { + Provider minimumCompilerVersionValueSource = providerFactory.of(JavaHomeValueSource.class, spec -> { + spec.getParameters().getVersion().set(unreleasedVersionInfo.map(it -> it.version())); + spec.getParameters().getCheckoutDir().set(checkoutDir); + }).flatMap(s -> getJavaHome(objectFactory, toolChainService, Integer.parseInt(s))); + loggedExec.getNonTrackedEnvironment().put("JAVA_HOME", minimumCompilerVersionValueSource.get()); + } + }); if (isCi && OS.current() != OS.WINDOWS) { // TODO: Disabled for now until we can figure out why files are getting corrupted @@ -169,15 +177,8 @@ private static Provider getJavaHome(ObjectFactory objectFactory, JavaToo .map(launcher -> launcher.getMetadata().getInstallationPath().getAsFile().getAbsolutePath()); } - private static String readFromFile(File file) { - try { - return FileUtils.readFileToString(file).trim(); - } catch (IOException ioException) { - throw new GradleException("Cannot read java properties file.", ioException); - } - } - public static abstract class JavaHomeValueSource implements ValueSource { + public abstract static class JavaHomeValueSource implements ValueSource { private String minimumCompilerVersionPath(Version bwcVersion) { return (bwcVersion.onOrAfter(BUILD_TOOL_MINIMUM_VERSION)) @@ -185,6 +186,14 @@ private String minimumCompilerVersionPath(Version bwcVersion) { : "buildSrc/" + MINIMUM_COMPILER_VERSION_PATH; } + private static String readFromFile(File file) { + try { + return FileUtils.readFileToString(file).trim(); + } catch (IOException ioException) { + throw new GradleException("Cannot read java properties file.", ioException); + } + } + @Override public String obtain() { return readFromFile(