Skip to content

Commit

Permalink
We need to postpone resolving minimum java version from bwc branch to…
Browse files Browse the repository at this point in the history
… task execution phase
  • Loading branch information
breskeby committed Nov 22, 2024
1 parent d0552a0 commit 4c63cca
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,10 +104,17 @@ private static TaskProvider<LoggedExec> 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<Task>() {
@Override
public void execute(Task task) {
Provider<String> 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
Expand Down Expand Up @@ -169,22 +177,23 @@ private static Provider<String> 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<String, JavaHomeValueSource.Params> {
public abstract static class JavaHomeValueSource implements ValueSource<String, JavaHomeValueSource.Params> {

private String minimumCompilerVersionPath(Version bwcVersion) {
return (bwcVersion.onOrAfter(BUILD_TOOL_MINIMUM_VERSION))
? "build-tools-internal/" + MINIMUM_COMPILER_VERSION_PATH
: "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(
Expand Down

0 comments on commit 4c63cca

Please sign in to comment.