Skip to content

Commit

Permalink
[ci] Skip JDK install if near match is found in $(JI_JAVA_HOME) (#9585)
Browse files Browse the repository at this point in the history
The JDK install step has been updated to optionally skip installation
if a close enough match is found in the $(JI_JAVA_HOME) directory. This
should allow us to skip JDK provisioning on our test jobs.
  • Loading branch information
pjcollins authored Dec 4, 2024
1 parent 65906e0 commit bf1a482
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected Scenario_AndroidTestDependencies (string name, string description)
protected override void AddSteps (Context context)
{
Steps.Add (new Step_InstallDotNetPreview ());
Steps.Add (new Step_InstallMicrosoftOpenJDK ());
Steps.Add (new Step_InstallMicrosoftOpenJDK (allowJIJavaHomeMatch: true));
Steps.Add (new Step_Android_SDK_NDK (AndroidSdkNdkType));

// disable installation of missing programs...
Expand Down
33 changes: 25 additions & 8 deletions build-tools/xaprepare/xaprepare/Steps/Step_InstallAdoptOpenJDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ abstract partial class Step_InstallOpenJDK : StepWithDownloadProgress, IBuildInv
Path.Combine ("include", "jni.h"),
};

public Step_InstallOpenJDK (string description)
bool AllowJIJavaHomeMatch = false;

public Step_InstallOpenJDK (string description, bool allowJIJavaHomeMatch = false)
: base (description)
{}
{
AllowJIJavaHomeMatch = allowJIJavaHomeMatch;
}

protected abstract string ProductName {get;}
protected abstract string JdkInstallDir {get;}
Expand Down Expand Up @@ -55,7 +59,22 @@ protected override async Task<bool> Execute (Context context)
return true;
}

Log.StatusLine ($"{ProductName} {JdkVersion} r{JdkRelease} will be installed");
// Check for a JDK installed on CI with a matching major version to use for test jobs
var jiJavaHomeVarValue = Environment.GetEnvironmentVariable ("JI_JAVA_HOME");
if (AllowJIJavaHomeMatch && Directory.Exists (jiJavaHomeVarValue)) {
jdkInstallDir = jiJavaHomeVarValue;
OpenJDKExistsAndIsValid (jdkInstallDir, out installedVersion);
if (Version.TryParse (installedVersion, out Version? cversion) && cversion != null) {
if (cversion.Major == JdkVersion.Major) {
Log.Status ($"{ProductName} with version ");
Log.Status (installedVersion ?? "Unknown", ConsoleColor.Yellow);
Log.StatusLine (" already installed in: ", jdkInstallDir, tailColor: ConsoleColor.Cyan);
return true;
}
}
}

Log.StatusLine ($"{ProductName} {JdkVersion} r{JdkRelease} will be installed to {jdkInstallDir}");
Uri jdkURL = JdkUrl;
if (jdkURL == null)
throw new InvalidOperationException ($"{ProductName} URL must not be null");
Expand Down Expand Up @@ -196,9 +215,9 @@ bool OpenJDKExistsAndIsValid (string installDir, out string? installedVersion)
return false;
}

installedVersion = cv;
string xaVersionFile = Path.Combine (installDir, XAVersionInfoFile);
if (!File.Exists (xaVersionFile)) {
installedVersion = cv;
Log.DebugLine ($"Unable to find .NET for Android version file {xaVersionFile}");
return false;
}
Expand All @@ -215,8 +234,6 @@ bool OpenJDKExistsAndIsValid (string installDir, out string? installedVersion)
return false;
}

installedVersion = $"{cv} r{rv}";

if (!Version.TryParse (cv, out Version? cversion) || cversion == null) {
Log.DebugLine ($"Unable to parse {ProductName} version from: {cv}");
return false;
Expand Down Expand Up @@ -271,8 +288,8 @@ class Step_InstallMicrosoftOpenJDK : Step_InstallOpenJDK {

const string _ProductName = "Microsoft OpenJDK";

public Step_InstallMicrosoftOpenJDK ()
: base ($"Installing {_ProductName}")
public Step_InstallMicrosoftOpenJDK (bool allowJIJavaHomeMatch = false)
: base ($"Installing {_ProductName}", allowJIJavaHomeMatch)
{
}

Expand Down

0 comments on commit bf1a482

Please sign in to comment.