mirror of
https://github.com/actions/runner-images.git
synced 2025-12-12 12:06:59 +00:00
[Windows] Fix java 11 installation (#887)
* Fix java 11 installation, add tests * change java installation to use function * remove extra line
This commit is contained in:
@@ -5,21 +5,20 @@
|
|||||||
|
|
||||||
Import-Module -Name ImageHelpers -Force
|
Import-Module -Name ImageHelpers -Force
|
||||||
|
|
||||||
# Download the Azul Systems Zulu JDKs
|
function Set-JavaPath {
|
||||||
# See https://www.azul.com/downloads/azure-only/zulu/
|
param (
|
||||||
$azulJDKURLs = @(
|
[string] $Version,
|
||||||
'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',
|
[switch] $Default
|
||||||
'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',
|
|
||||||
'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',
|
|
||||||
'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'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach ($azulJDKURL in $azulJDKURLs)
|
$filter = "*azure-jdk_${version}.*"
|
||||||
{
|
$javaPath = (Get-ChildItem -Path 'C:\Program Files\Java' -Filter $filter | Sort-Object -Property Name -Descending | Select-Object -First 1).FullName
|
||||||
$archivePath = Start-DownloadWithRetry -Url $azulJDKURL -Name $([IO.Path]::GetFileName($azulJDKURL))
|
|
||||||
Expand-Archive -Path $archivePath -DestinationPath "C:\Program Files\Java\"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Write-Host "Set JAVA_HOME_${Version}_X64 environmental variable as $javaPath"
|
||||||
|
setx JAVA_HOME_${Version}_X64 $javaPath /M
|
||||||
|
|
||||||
|
if ($Default)
|
||||||
|
{
|
||||||
$currentPath = Get-MachinePath
|
$currentPath = Get-MachinePath
|
||||||
|
|
||||||
$pathSegments = $currentPath.Split(';')
|
$pathSegments = $currentPath.Split(';')
|
||||||
@@ -33,28 +32,37 @@ foreach ($pathSegment in $pathSegments)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$java7Installs = Get-ChildItem -Path 'C:\Program Files\Java' -Filter '*azure-jdk*7*' | Sort-Object -Property Name -Descending | Select-Object -First 1
|
|
||||||
$latestJava7Install = $java7Installs.FullName;
|
|
||||||
|
|
||||||
$java8Installs = Get-ChildItem -Path 'C:\Program Files\Java' -Filter '*azure-jdk*8*' | Sort-Object -Property Name -Descending | Select-Object -First 1
|
|
||||||
$latestJava8Install = $java8Installs.FullName;
|
|
||||||
|
|
||||||
$java11Installs = Get-ChildItem -Path 'C:\Program Files\Java' -Filter '*azure-jdk*11*' | Sort-Object -Property Name -Descending | Select-Object -First 1
|
|
||||||
$latestJava11Install = $java11Installs.FullName;
|
|
||||||
|
|
||||||
$java13Installs = Get-ChildItem -Path 'C:\Program Files\Java' -Filter '*azure-jdk*13*' | Sort-Object -Property Name -Descending | Select-Object -First 1
|
|
||||||
$latestJava13Install = $java13Installs.FullName;
|
|
||||||
|
|
||||||
$newPath = [string]::Join(';', $newPathSegments)
|
$newPath = [string]::Join(';', $newPathSegments)
|
||||||
$newPath = $latestJava8Install + '\bin;' + $newPath
|
$newPath = $javaPath + '\bin;' + $newPath
|
||||||
|
|
||||||
|
Write-Host "Add $javaPath\bin to PATH"
|
||||||
Set-MachinePath -NewPath $newPath
|
Set-MachinePath -NewPath $newPath
|
||||||
|
|
||||||
setx JAVA_HOME $latestJava8Install /M
|
Write-Host "Set JAVA_HOME environmental variable as $javaPath"
|
||||||
setx JAVA_HOME_7_X64 $latestJava7Install /M
|
setx JAVA_HOME $javaPath /M
|
||||||
setx JAVA_HOME_8_X64 $latestJava8Install /M
|
}
|
||||||
setx JAVA_HOME_11_X64 $latestJava11Install /M
|
}
|
||||||
setx JAVA_HOME_13_X64 $latestJava13Install /M
|
|
||||||
|
# Download the Azul Systems Zulu JDKs
|
||||||
|
# See https://www.azul.com/downloads/azure-only/zulu/
|
||||||
|
$azulJDKURLs = @(
|
||||||
|
'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',
|
||||||
|
'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',
|
||||||
|
'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'
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
Set-JavaPath -Version 7
|
||||||
|
Set-JavaPath -Version 8 -Default
|
||||||
|
Set-JavaPath -Version 11
|
||||||
|
Set-JavaPath -Version 13
|
||||||
|
|
||||||
# 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
|
||||||
|
|||||||
@@ -3,6 +3,52 @@
|
|||||||
## Desc: Validate various JDKs and java tools
|
## Desc: Validate various JDKs and java tools
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
Function Validate-JavaVersion {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)] [string] $Version,
|
||||||
|
[switch] $Default
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Checking Java $version"
|
||||||
|
|
||||||
|
# Set Path to get Java
|
||||||
|
if (-not $Default)
|
||||||
|
{
|
||||||
|
# Take 7 & 8 for versions 1.7 and 1.8
|
||||||
|
$versionNumber = $version.Split(".") | Select-Object -Last 1
|
||||||
|
|
||||||
|
$javaBin = [System.Environment]::GetEnvironmentVariable("JAVA_HOME_${versionNumber}_X64") + "\bin;"
|
||||||
|
$env:Path = $javaBin + $env:Path
|
||||||
|
}
|
||||||
|
|
||||||
|
$isJavaExists = $($(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*'
|
||||||
|
|
||||||
|
if ($isJavaExists)
|
||||||
|
{
|
||||||
|
$javaVersion = $matches.version
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host "Java $version was not found"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$isJavaCorrect = $javaVersion.StartsWith($version)
|
||||||
|
|
||||||
|
if($isJavaCorrect)
|
||||||
|
{
|
||||||
|
Write-Host "Java $javaVersion found"
|
||||||
|
# Reset Path to the default one in case we need to check the default Java later
|
||||||
|
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
||||||
|
return $javaVersion
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host "Expected Java $version, but found $javaVersion"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if((Get-Command -Name 'java') -and (Get-Command -Name 'mvn') -and (Get-Command -Name 'ant') -and (Get-Command -Name 'gradle'))
|
if((Get-Command -Name 'java') -and (Get-Command -Name 'mvn') -and (Get-Command -Name 'ant') -and (Get-Command -Name 'gradle'))
|
||||||
{
|
{
|
||||||
Write-Host "Java $(java -version) on path"
|
Write-Host "Java $(java -version) on path"
|
||||||
@@ -16,32 +62,12 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Write-Host "Checking installed Java versions"
|
||||||
|
|
||||||
if( $( $(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*' )
|
$java7Version = Validate-JavaVersion -Version "1.7"
|
||||||
{
|
$java8Version = Validate-JavaVersion -Version "1.8" -Default
|
||||||
$javaVersion = $Matches.version
|
$java11Version = Validate-JavaVersion -Version "11"
|
||||||
}
|
$java13Version = Validate-JavaVersion -Version "13"
|
||||||
|
|
||||||
$env:Path = $env:JAVA_HOME_7_X64 + "\bin;" + $env:Path
|
|
||||||
|
|
||||||
if( $( $(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*' )
|
|
||||||
{
|
|
||||||
$java7Version = $Matches.version
|
|
||||||
}
|
|
||||||
|
|
||||||
$env:Path = $env:JAVA_HOME_11_X64 + "\bin;" + $env:Path
|
|
||||||
|
|
||||||
if( $( $(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*' )
|
|
||||||
{
|
|
||||||
$java11Version = $Matches.version
|
|
||||||
}
|
|
||||||
|
|
||||||
$env:Path = $env:JAVA_HOME_13_X64 + "\bin;" + $env:Path
|
|
||||||
|
|
||||||
if( $( $(& $env:comspec "/s /c java -version 2>&1") | Out-String) -match '^(?<vendor>.+) version "(?<version>.+)".*' )
|
|
||||||
{
|
|
||||||
$java13Version = $Matches.version
|
|
||||||
}
|
|
||||||
|
|
||||||
if( $(ant -version) -match 'Apache Ant\(TM\) version (?<version>.*) compiled.*' )
|
if( $(ant -version) -match 'Apache Ant\(TM\) version (?<version>.*) compiled.*' )
|
||||||
{
|
{
|
||||||
@@ -62,7 +88,7 @@ if( $( $(gradle -version) | Out-String) -match 'Gradle (?<version>.*)' )
|
|||||||
$SoftwareName = "Java Development Kit"
|
$SoftwareName = "Java Development Kit"
|
||||||
|
|
||||||
$Description = @"
|
$Description = @"
|
||||||
#### $javaVersion (default)
|
#### $java8Version (default)
|
||||||
|
|
||||||
_Environment:_
|
_Environment:_
|
||||||
* JAVA_HOME: location of JDK
|
* JAVA_HOME: location of JDK
|
||||||
|
|||||||
Reference in New Issue
Block a user