mirror of
https://github.com/actions/runner-images.git
synced 2025-12-12 20:26:49 +00:00
Switch Java installation to AdoptOpenJDK on Windows (#1067)
* Switch Java installation to AdoptOpenJDK * Minor fix * Setup env vars * Reworked * Add variable for java root path * Validation improvement * Minor fix * Minor fix
This commit is contained in:
committed by
GitHub
parent
6f246a3b4f
commit
98df997b11
@@ -8,11 +8,21 @@ Import-Module -Name ImageHelpers -Force
|
|||||||
function Set-JavaPath {
|
function Set-JavaPath {
|
||||||
param (
|
param (
|
||||||
[string] $Version,
|
[string] $Version,
|
||||||
|
[string] $JavaRootPath,
|
||||||
[switch] $Default
|
[switch] $Default
|
||||||
)
|
)
|
||||||
|
|
||||||
$filter = "*azure-jdk_${version}.*"
|
if ($Version -eq 7) {
|
||||||
$javaPath = (Get-ChildItem -Path 'C:\Program Files\Java' -Filter $filter | Sort-Object -Property Name -Descending | Select-Object -First 1).FullName
|
$matchedString = "azure-jdk_7"
|
||||||
|
} else {
|
||||||
|
$matchedString = "jdk-?$Version"
|
||||||
|
}
|
||||||
|
$javaPath = (Get-ChildItem -Path $JavaRootPath | Where-Object { $_ -match $matchedString}).FullName
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($javaPath)) {
|
||||||
|
Write-Host "Not found path to Java $Version"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Set JAVA_HOME_${Version}_X64 environmental variable as $javaPath"
|
Write-Host "Set JAVA_HOME_${Version}_X64 environmental variable as $javaPath"
|
||||||
setx JAVA_HOME_${Version}_X64 $javaPath /M
|
setx JAVA_HOME_${Version}_X64 $javaPath /M
|
||||||
@@ -43,26 +53,49 @@ function Set-JavaPath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download the Azul Systems Zulu JDKs
|
function Install-Java7FromAzul {
|
||||||
# See https://www.azul.com/downloads/azure-only/zulu/
|
param(
|
||||||
$azulJDKURLs = @(
|
[string] $DestinationPath
|
||||||
'https://repos.azul.com/azure-only/zulu/packages/zulu-7/7u232/zulu-7-azure-jdk_7.31.0.5-7.0.232-win_x64.zip',
|
)
|
||||||
'https://repos.azul.com/azure-only/zulu/packages/zulu-8/8u222/zulu-8-azure-jdk_8.40.0.25-8.0.222-win_x64.zip',
|
$azulJDK7URL = 'https://repos.azul.com/azure-only/zulu/packages/zulu-7/7u232/zulu-7-azure-jdk_7.31.0.5-7.0.232-win_x64.zip'
|
||||||
'https://repos.azul.com/azure-only/zulu/packages/zulu-11/11.0.4/zulu-11-azure-jdk_11.33.15-11.0.4-win_x64.zip',
|
$archivePath = Start-DownloadWithRetry -Url $azulJDK7URL -Name $([IO.Path]::GetFileName($azulJDK7URL))
|
||||||
'https://repos.azul.com/azure-only/zulu/packages/zulu-13/13.0.3/zulu-13-azure-jdk_13.31.11-13.0.3-win_x64.zip'
|
Extract-7Zip -Path $archivePath -DestinationPath $DestinationPath
|
||||||
)
|
|
||||||
|
|
||||||
foreach ($azulJDKURL in $azulJDKURLs)
|
|
||||||
{
|
|
||||||
$archivePath = Start-DownloadWithRetry -Url $azulJDKURL -Name $([IO.Path]::GetFileName($azulJDKURL))
|
|
||||||
Extract-7Zip -Path $archivePath -DestinationPath "C:\Program Files\Java\"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set PATH and env variables
|
function Install-JavaFromAdoptOpenJDK {
|
||||||
Set-JavaPath -Version 7
|
param(
|
||||||
Set-JavaPath -Version 8 -Default
|
[string] $JDKVersion,
|
||||||
Set-JavaPath -Version 11
|
[string] $DestinationPath
|
||||||
Set-JavaPath -Version 13
|
)
|
||||||
|
|
||||||
|
$assets = Invoke-RestMethod -Uri "https://api.adoptopenjdk.net/v3/assets/latest/$JDKVersion/hotspot"
|
||||||
|
$downloadUrl = ($assets | Where-Object {
|
||||||
|
$_.binary.os -eq "windows" `
|
||||||
|
-and $_.binary.architecture -eq "x64" `
|
||||||
|
-and $_.binary.image_type -eq "jdk"
|
||||||
|
}).binary.package.link
|
||||||
|
|
||||||
|
$archivePath = Start-DownloadWithRetry -Url $downloadUrl -Name $([IO.Path]::GetFileName($downloadUrl))
|
||||||
|
Extract-7Zip -Path $archivePath -DestinationPath $DestinationPath
|
||||||
|
}
|
||||||
|
|
||||||
|
$jdkVersions = @(7, 8, 11, 13)
|
||||||
|
$defaultVersion = 8
|
||||||
|
$javaRootPath = "C:\Program Files\Java\"
|
||||||
|
|
||||||
|
foreach ($jdkVersion in $jdkVersions) {
|
||||||
|
if ($jdkVersion -eq 7) {
|
||||||
|
Install-Java7FromAzul -DestinationPath $javaRootPath
|
||||||
|
} else {
|
||||||
|
Install-JavaFromAdoptOpenJDK -JDKVersion $jdkVersion -DestinationPath $javaRootPath
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($jdkVersion -eq $defaultVersion) {
|
||||||
|
Set-JavaPath -Version $jdkVersion -JavaRootPath $javaRootPath -Default
|
||||||
|
} else {
|
||||||
|
Set-JavaPath -Version $jdkVersion -JavaRootPath $javaRootPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Install Java tools
|
# Install Java tools
|
||||||
# Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK
|
# Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK
|
||||||
|
|||||||
@@ -17,9 +17,20 @@ Function Validate-JavaVersion {
|
|||||||
# Take 7 & 8 for versions 1.7 and 1.8
|
# Take 7 & 8 for versions 1.7 and 1.8
|
||||||
$versionNumber = $version.Split(".") | Select-Object -Last 1
|
$versionNumber = $version.Split(".") | Select-Object -Last 1
|
||||||
|
|
||||||
$javaBin = [System.Environment]::GetEnvironmentVariable("JAVA_HOME_${versionNumber}_X64") + "\bin;"
|
$javaPath = [System.Environment]::GetEnvironmentVariable("JAVA_HOME_${versionNumber}_X64")
|
||||||
|
if ([string]::IsNullOrEmpty($javaPath))
|
||||||
|
{
|
||||||
|
Write-Host "Environment variable 'JAVA_HOME_${versionNumber}_X64' is null"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$javaBin = "$javaPath\bin;"
|
||||||
$env:Path = $javaBin + $env:Path
|
$env:Path = $javaBin + $env:Path
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Validate-JavaVersion -Version $Version
|
||||||
|
}
|
||||||
|
|
||||||
$isJavaExists = $($(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*'
|
$isJavaExists = $($(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user