Skip to content

Commit bf1a482

Browse files
authored
[ci] Skip JDK install if near match is found in $(JI_JAVA_HOME) (#9585)
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.
1 parent 65906e0 commit bf1a482

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

build-tools/xaprepare/xaprepare/Scenarios/Scenario_AndroidTestDependencies.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected Scenario_AndroidTestDependencies (string name, string description)
1818
protected override void AddSteps (Context context)
1919
{
2020
Steps.Add (new Step_InstallDotNetPreview ());
21-
Steps.Add (new Step_InstallMicrosoftOpenJDK ());
21+
Steps.Add (new Step_InstallMicrosoftOpenJDK (allowJIJavaHomeMatch: true));
2222
Steps.Add (new Step_Android_SDK_NDK (AndroidSdkNdkType));
2323

2424
// disable installation of missing programs...

build-tools/xaprepare/xaprepare/Steps/Step_InstallAdoptOpenJDK.cs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ abstract partial class Step_InstallOpenJDK : StepWithDownloadProgress, IBuildInv
2424
Path.Combine ("include", "jni.h"),
2525
};
2626

27-
public Step_InstallOpenJDK (string description)
27+
bool AllowJIJavaHomeMatch = false;
28+
29+
public Step_InstallOpenJDK (string description, bool allowJIJavaHomeMatch = false)
2830
: base (description)
29-
{}
31+
{
32+
AllowJIJavaHomeMatch = allowJIJavaHomeMatch;
33+
}
3034

3135
protected abstract string ProductName {get;}
3236
protected abstract string JdkInstallDir {get;}
@@ -55,7 +59,22 @@ protected override async Task<bool> Execute (Context context)
5559
return true;
5660
}
5761

58-
Log.StatusLine ($"{ProductName} {JdkVersion} r{JdkRelease} will be installed");
62+
// Check for a JDK installed on CI with a matching major version to use for test jobs
63+
var jiJavaHomeVarValue = Environment.GetEnvironmentVariable ("JI_JAVA_HOME");
64+
if (AllowJIJavaHomeMatch && Directory.Exists (jiJavaHomeVarValue)) {
65+
jdkInstallDir = jiJavaHomeVarValue;
66+
OpenJDKExistsAndIsValid (jdkInstallDir, out installedVersion);
67+
if (Version.TryParse (installedVersion, out Version? cversion) && cversion != null) {
68+
if (cversion.Major == JdkVersion.Major) {
69+
Log.Status ($"{ProductName} with version ");
70+
Log.Status (installedVersion ?? "Unknown", ConsoleColor.Yellow);
71+
Log.StatusLine (" already installed in: ", jdkInstallDir, tailColor: ConsoleColor.Cyan);
72+
return true;
73+
}
74+
}
75+
}
76+
77+
Log.StatusLine ($"{ProductName} {JdkVersion} r{JdkRelease} will be installed to {jdkInstallDir}");
5978
Uri jdkURL = JdkUrl;
6079
if (jdkURL == null)
6180
throw new InvalidOperationException ($"{ProductName} URL must not be null");
@@ -196,9 +215,9 @@ bool OpenJDKExistsAndIsValid (string installDir, out string? installedVersion)
196215
return false;
197216
}
198217

218+
installedVersion = cv;
199219
string xaVersionFile = Path.Combine (installDir, XAVersionInfoFile);
200220
if (!File.Exists (xaVersionFile)) {
201-
installedVersion = cv;
202221
Log.DebugLine ($"Unable to find .NET for Android version file {xaVersionFile}");
203222
return false;
204223
}
@@ -215,8 +234,6 @@ bool OpenJDKExistsAndIsValid (string installDir, out string? installedVersion)
215234
return false;
216235
}
217236

218-
installedVersion = $"{cv} r{rv}";
219-
220237
if (!Version.TryParse (cv, out Version? cversion) || cversion == null) {
221238
Log.DebugLine ($"Unable to parse {ProductName} version from: {cv}");
222239
return false;
@@ -271,8 +288,8 @@ class Step_InstallMicrosoftOpenJDK : Step_InstallOpenJDK {
271288

272289
const string _ProductName = "Microsoft OpenJDK";
273290

274-
public Step_InstallMicrosoftOpenJDK ()
275-
: base ($"Installing {_ProductName}")
291+
public Step_InstallMicrosoftOpenJDK (bool allowJIJavaHomeMatch = false)
292+
: base ($"Installing {_ProductName}", allowJIJavaHomeMatch)
276293
{
277294
}
278295

0 commit comments

Comments
 (0)