@@ -24,9 +24,13 @@ abstract partial class Step_InstallOpenJDK : StepWithDownloadProgress, IBuildInv
24
24
Path . Combine ( "include" , "jni.h" ) ,
25
25
} ;
26
26
27
- public Step_InstallOpenJDK ( string description )
27
+ bool AllowJIJavaHomeMatch = false ;
28
+
29
+ public Step_InstallOpenJDK ( string description , bool allowJIJavaHomeMatch = false )
28
30
: base ( description )
29
- { }
31
+ {
32
+ AllowJIJavaHomeMatch = allowJIJavaHomeMatch ;
33
+ }
30
34
31
35
protected abstract string ProductName { get ; }
32
36
protected abstract string JdkInstallDir { get ; }
@@ -55,7 +59,22 @@ protected override async Task<bool> Execute (Context context)
55
59
return true ;
56
60
}
57
61
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 } ") ;
59
78
Uri jdkURL = JdkUrl ;
60
79
if ( jdkURL == null )
61
80
throw new InvalidOperationException ( $ "{ ProductName } URL must not be null") ;
@@ -196,9 +215,9 @@ bool OpenJDKExistsAndIsValid (string installDir, out string? installedVersion)
196
215
return false ;
197
216
}
198
217
218
+ installedVersion = cv ;
199
219
string xaVersionFile = Path . Combine ( installDir , XAVersionInfoFile ) ;
200
220
if ( ! File . Exists ( xaVersionFile ) ) {
201
- installedVersion = cv ;
202
221
Log . DebugLine ( $ "Unable to find .NET for Android version file { xaVersionFile } ") ;
203
222
return false ;
204
223
}
@@ -215,8 +234,6 @@ bool OpenJDKExistsAndIsValid (string installDir, out string? installedVersion)
215
234
return false ;
216
235
}
217
236
218
- installedVersion = $ "{ cv } r{ rv } ";
219
-
220
237
if ( ! Version . TryParse ( cv , out Version ? cversion ) || cversion == null ) {
221
238
Log . DebugLine ( $ "Unable to parse { ProductName } version from: { cv } ") ;
222
239
return false ;
@@ -271,8 +288,8 @@ class Step_InstallMicrosoftOpenJDK : Step_InstallOpenJDK {
271
288
272
289
const string _ProductName = "Microsoft OpenJDK" ;
273
290
274
- public Step_InstallMicrosoftOpenJDK ( )
275
- : base ( $ "Installing { _ProductName } ")
291
+ public Step_InstallMicrosoftOpenJDK ( bool allowJIJavaHomeMatch = false )
292
+ : base ( $ "Installing { _ProductName } ", allowJIJavaHomeMatch )
276
293
{
277
294
}
278
295
0 commit comments