Skip to content

Commit 625b333

Browse files
authored
Generic approach to install java 8 on macOS (#46593)
* Added separte step to install java8 * Install java 8 in the install-latest-jdk template and set java_home * Check null for the Java_Home * Cleaned up code
1 parent 8f8b4aa commit 625b333

File tree

4 files changed

+38
-49
lines changed

4 files changed

+38
-49
lines changed

eng/pipelines/templates/jobs/ci.tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ jobs:
110110
ServiceDirectory: ${{parameters.ServiceDirectory}}
111111
ExcludePaths: ${{parameters.ExcludePaths}}
112112

113-
- template: /eng/pipelines/templates/steps/install-java8-macos.yml
114-
115113
- template: /eng/common/testproxy/test-proxy-tool.yml
116114
parameters:
117115
runProxy: true

eng/pipelines/templates/steps/install-java8-macos.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

eng/pipelines/templates/steps/install-latest-jdk.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,13 @@ steps:
3131
Write-Host "Latest JDK: $Env:JAVA_HOME_${{ parameters.LatestJdkFeatureVersion }}_X64"
3232
displayName: 'Verify Latest JDK Install'
3333
condition: eq(variables['IsLatestNonLtsJdk'], 'true')
34+
35+
- task: PowerShell@2
36+
displayName: 'Install JDK 8 on macOS'
37+
inputs:
38+
pwsh: true
39+
arguments: >
40+
-JdkFeatureVersion 8
41+
workingDirectory: $(Agent.BuildDirectory)
42+
filePath: eng/scripts/Install-Latest-JDK.ps1
43+
condition: eq(variables['Agent.OS'], 'Darwin')

eng/scripts/Install-Latest-JDK.ps1

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ if ($IsWindows) {
1616
$os = "linux"
1717
}
1818

19+
$jdkFeatureVersionJavaHome = "JAVA_HOME_" + $JdkFeatureVersion + "_X64"
20+
Write-Host "Checking if $jdkFeatureVersionJavaHome is already set and exists..."
21+
$javaHomeValue = [System.Environment]::GetEnvironmentVariable($jdkFeatureVersionJavaHome)
22+
if ($javaHomeValue) {
23+
$jdkBinPath = Join-Path -Path $javaHomeValue -ChildPath "bin/java"
24+
if (Test-Path -Path $jdkBinPath) {
25+
Write-Host "$jdkFeatureVersionJavaHome is already set to $javaHomeValue"
26+
exit 0
27+
}
28+
} else {
29+
Write-Host "$jdkFeatureVersionJavaHome is not set, proceeding with installation..."
30+
}
31+
1932
$getInstalls = "$adoptiumApiUrl/v3/assets/latest/$JdkFeatureVersion/hotspot?architecture=x64&image_type=jdk&os=$os&vendor=eclipse"
2033
$jdkUnzipName = "jdk-$JdkFeatureVersion"
2134

@@ -43,11 +56,22 @@ if (!(Test-Path -Path $jdkUnzipName -PathType container)) {
4356
}
4457

4558
$javaHome = (Convert-Path $jdkUnzipName)
46-
Write-Host "Latest JDK: $javaHome"
4759

60+
if ($IsMacOS) {
61+
# On macOS, the JDK is inside a subdirectory of the unzipped folder.
62+
$correctJavaHome = Join-Path -Path $javaHome -ChildPath "Contents/Home"
63+
$javaBinPath = Join-Path -Path $correctJavaHome -ChildPath "bin/java"
64+
if (Test-Path $javaBinPath) {
65+
$javaHome = $correctJavaHome
66+
Write-Host "Updated JAVA_HOME on macOS: $correctJavaHome"
67+
} else {
68+
Write-Error "Failed to find Java at: $correctJavaHome"
69+
exit 1
70+
}
71+
}
72+
73+
Write-Host "Latest JDK: $javaHome"
4874
Write-Host "Current JAVA_HOME: $Env:JAVA_HOME"
4975
Write-Host "##vso[task.setvariable variable=JAVA_HOME;]$javaHome"
50-
Write-Host "Updated JAVA_HOME: $Env:JAVA_HOME"
51-
52-
$jdkFeatureVersionJavaHome = "JAVA_HOME_" + $JdkFeatureVersion + "_X64"
76+
Write-Host "Updated JAVA_HOME to : $javaHome"
5377
Write-Host "##vso[task.setvariable variable=$jdkFeatureVersionJavaHome;]$javaHome"

0 commit comments

Comments
 (0)