mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 06:08:07 +00:00
[Windows] Add adoptium to javatools installer (#3985)
This commit is contained in:
@@ -7,10 +7,11 @@ function Set-JavaPath {
|
|||||||
param (
|
param (
|
||||||
[string] $Version,
|
[string] $Version,
|
||||||
[string] $Architecture = "x64",
|
[string] $Architecture = "x64",
|
||||||
[switch] $Default
|
[switch] $Default,
|
||||||
|
[string] $VendorName
|
||||||
)
|
)
|
||||||
|
|
||||||
$javaPathPattern = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_Adopt_jdk/${Version}*/${Architecture}"
|
$javaPathPattern = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_${VendorName}_jdk/${Version}*/${Architecture}"
|
||||||
$javaPath = (Get-Item -Path $javaPathPattern).FullName
|
$javaPath = (Get-Item -Path $javaPathPattern).FullName
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($javaPath)) {
|
if ([string]::IsNullOrEmpty($javaPath)) {
|
||||||
@@ -23,6 +24,7 @@ function Set-JavaPath {
|
|||||||
|
|
||||||
if ($Default)
|
if ($Default)
|
||||||
{
|
{
|
||||||
|
# Clean up any other Java folders from PATH to make sure that they won't conflict with each other
|
||||||
$currentPath = Get-MachinePath
|
$currentPath = Get-MachinePath
|
||||||
|
|
||||||
$pathSegments = $currentPath.Split(';')
|
$pathSegments = $currentPath.Split(';')
|
||||||
@@ -47,14 +49,21 @@ function Set-JavaPath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Install-JavaFromAdoptOpenJDK {
|
function Install-JavaJDK {
|
||||||
param(
|
param(
|
||||||
[string] $JDKVersion,
|
[string] $JDKVersion,
|
||||||
[string] $Architecture = "x64"
|
[string] $Architecture = "x64",
|
||||||
|
[string] $VendorName
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get Java version from adopt openjdk api
|
# Get Java version from api
|
||||||
$assetUrl = Invoke-RestMethod -Uri "https://api.adoptopenjdk.net/v3/assets/latest/${JDKVersion}/hotspot"
|
if ($VendorName -eq "Temurin-Hotspot") {
|
||||||
|
$assetUrl = Invoke-RestMethod -Uri "https://api.adoptium.net/v3/assets/latest/${JDKVersion}/hotspot"
|
||||||
|
} elseif ($VendorName -eq "Adopt") {
|
||||||
|
$assetUrl = Invoke-RestMethod -Uri "https://api.adoptopenjdk.net/v3/assets/latest/${JDKVersion}/hotspot"
|
||||||
|
} else {
|
||||||
|
throw "$VendorName is invalid vendor name. 'Adopt' and 'Temurin-Hotspot' are allowed values"
|
||||||
|
}
|
||||||
$asset = $assetUrl | Where-Object {
|
$asset = $assetUrl | Where-Object {
|
||||||
$_.binary.os -eq "windows" `
|
$_.binary.os -eq "windows" `
|
||||||
-and $_.binary.architecture -eq $Architecture `
|
-and $_.binary.architecture -eq $Architecture `
|
||||||
@@ -68,13 +77,13 @@ function Install-JavaFromAdoptOpenJDK {
|
|||||||
# We have to replace '+' sign in the version to '-' due to the issue with incorrect path in Android builds https://github.com/actions/virtual-environments/issues/3014
|
# We have to replace '+' sign in the version to '-' due to the issue with incorrect path in Android builds https://github.com/actions/virtual-environments/issues/3014
|
||||||
$fullJavaVersion = $asset.version.semver -replace '\+', '-'
|
$fullJavaVersion = $asset.version.semver -replace '\+', '-'
|
||||||
# Create directories in toolcache path
|
# Create directories in toolcache path
|
||||||
$javaToolcachePath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_Adopt_jdk"
|
$javaToolcachePath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_${VendorName}_jdk"
|
||||||
$javaVersionPath = Join-Path -Path $javaToolcachePath -ChildPath $fullJavaVersion
|
$javaVersionPath = Join-Path -Path $javaToolcachePath -ChildPath $fullJavaVersion
|
||||||
$javaArchPath = Join-Path -Path $javaVersionPath -ChildPath $Architecture
|
$javaArchPath = Join-Path -Path $javaVersionPath -ChildPath $Architecture
|
||||||
|
|
||||||
if (-not (Test-Path $javaToolcachePath))
|
if (-not (Test-Path $javaToolcachePath))
|
||||||
{
|
{
|
||||||
Write-Host "Creating Adopt openjdk toolcache folder"
|
Write-Host "Creating ${VendorName} toolcache folder"
|
||||||
New-Item -ItemType Directory -Path $javaToolcachePath | Out-Null
|
New-Item -ItemType Directory -Path $javaToolcachePath | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,19 +96,38 @@ function Install-JavaFromAdoptOpenJDK {
|
|||||||
New-Item -ItemType File -Path $javaVersionPath -Name "$Architecture.complete" | Out-Null
|
New-Item -ItemType File -Path $javaVersionPath -Name "$Architecture.complete" | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
$jdkVersions = (Get-ToolsetContent).java.versions
|
$toolsetJava = (Get-ToolsetContent).java
|
||||||
$defaultVersion = (Get-ToolsetContent).java.default
|
$jdkVendors = $toolsetJava.vendors
|
||||||
|
$defaultVendor = $toolsetJava.default_vendor
|
||||||
|
$defaultVersion = $toolsetJava.default
|
||||||
|
|
||||||
foreach ($jdkVersion in $jdkVersions) {
|
foreach ($jdkVendor in $jdkVendors) {
|
||||||
Install-JavaFromAdoptOpenJDK -JDKVersion $jdkVersion
|
$jdkVendorName = $jdkVendor.name
|
||||||
|
$jdkVersionsToInstall = $jdkVendor.versions
|
||||||
|
|
||||||
|
$isDefaultVendor = $jdkVendorName -eq $defaultVendor
|
||||||
|
|
||||||
if ($jdkVersion -eq $defaultVersion) {
|
foreach ($jdkVersionToInstall in $jdkVersionsToInstall) {
|
||||||
Set-JavaPath -Version $jdkVersion -Default
|
$isDefaultVersion = $jdkVersionToInstall -eq $defaultVersion
|
||||||
} else {
|
|
||||||
Set-JavaPath -Version $jdkVersion
|
Install-JavaJDK -VendorName $jdkVendorName -JDKVersion $jdkVersionToInstall
|
||||||
|
|
||||||
|
if ($isDefaultVendor) {
|
||||||
|
if ($isDefaultVersion) {
|
||||||
|
Set-JavaPath -Version $jdkVersionToInstall -VendorName $jdkVendorName -Default
|
||||||
|
} else {
|
||||||
|
Set-JavaPath -Version $jdkVersionToInstall -VendorName $jdkVendorName
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Setup JAVA_HOME_13_X64 as this is the only Adopt version needed
|
||||||
|
# There is no jdk 13 on Windows 2022
|
||||||
|
if (-not (Test-IsWin22)) {
|
||||||
|
Set-JavaPath -Version "13" -VendorName "Adopt"
|
||||||
|
}
|
||||||
|
|
||||||
# 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
|
||||||
Choco-Install -PackageName ant -ArgumentList "-i"
|
Choco-Install -PackageName ant -ArgumentList "-i"
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ function Get-JavaVersions {
|
|||||||
$versionInPath = (Split-Path $javaPath) -replace "\w:\\.*\\"
|
$versionInPath = (Split-Path $javaPath) -replace "\w:\\.*\\"
|
||||||
$version = $versionInPath -replace '-', '+'
|
$version = $versionInPath -replace '-', '+'
|
||||||
$defaultPostfix = ($javaPath -eq $defaultJavaPath) ? " (default)" : ""
|
$defaultPostfix = ($javaPath -eq $defaultJavaPath) ? " (default)" : ""
|
||||||
|
$VendorName = ($javaPath -like '*Java_Adopt_jdk*') ? "Adopt OpenJDK" : "Eclipse Temurin"
|
||||||
|
|
||||||
[PSCustomObject] @{
|
[PSCustomObject] @{
|
||||||
"Version" = $version + $defaultPostfix
|
"Version" = $version + $defaultPostfix
|
||||||
"Vendor" = "Adopt OpenJDK"
|
"Vendor" = $VendorName
|
||||||
"Environment Variable" = $_.Name
|
"Environment Variable" = $_.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
Describe "Java" {
|
Describe "Java" {
|
||||||
[array]$jdkVersions = (Get-ToolsetContent).java.versions | ForEach-Object { @{Version = $_} }
|
$toolsetJava = (Get-ToolsetContent).java
|
||||||
$defaultVersion = (Get-ToolsetContent).java.default
|
$defaultVendor = $toolsetJava.default_vendor
|
||||||
|
$javaVendors = $toolsetJava.vendors
|
||||||
|
$defaultVersion = $toolsetJava.default
|
||||||
|
|
||||||
|
[array]$jdkVersions = ($javaVendors | Where-Object {$_.name -eq $defaultVendor}).versions | ForEach-Object { @{Version = $_} }
|
||||||
|
[array]$adoptJdkVersions = ($javaVendors | Where-Object {$_.name -eq "Adopt"}).versions | ForEach-Object { @{Version = $_} }
|
||||||
|
|
||||||
It "Java <DefaultJavaVersion> is default" -TestCases @(@{ DefaultJavaVersion = $defaultVersion }) {
|
It "Java <DefaultJavaVersion> is default" -TestCases @(@{ DefaultJavaVersion = $defaultVersion }) {
|
||||||
$actualJavaPath = Get-EnvironmentVariable "JAVA_HOME"
|
$actualJavaPath = Get-EnvironmentVariable "JAVA_HOME"
|
||||||
@@ -33,4 +38,16 @@ Describe "Java" {
|
|||||||
}
|
}
|
||||||
$result.Output[0] | Should -Match ([regex]::Escape("openjdk version `"${Version}."))
|
$result.Output[0] | Should -Match ([regex]::Escape("openjdk version `"${Version}."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Java Adopt Jdk <Version>" -TestCases $adoptJdkVersions {
|
||||||
|
$adoptPath = Join-Path (Get-ChildItem ${env:AGENT_TOOLSDIRECTORY}\Java_Adopt_jdk\${Version}*) "x64\bin\java"
|
||||||
|
|
||||||
|
$result = Get-CommandResult "`"$adoptPath`" -version"
|
||||||
|
$result.ExitCode | Should -Be 0
|
||||||
|
|
||||||
|
if ($Version -eq 8) {
|
||||||
|
$Version = "1.${Version}"
|
||||||
|
}
|
||||||
|
$result.Output[0] | Should -Match ([regex]::Escape("openjdk version `"${Version}."))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,8 +142,16 @@
|
|||||||
],
|
],
|
||||||
"java": {
|
"java": {
|
||||||
"default": "8",
|
"default": "8",
|
||||||
"versions": [
|
"default_vendor": "Temurin-Hotspot",
|
||||||
"8", "11", "13"
|
"vendors": [
|
||||||
|
{
|
||||||
|
"name": "Temurin-Hotspot",
|
||||||
|
"versions": [ "8", "11" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Adopt",
|
||||||
|
"versions": [ "8", "11", "13" ]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
|
|||||||
@@ -142,8 +142,16 @@
|
|||||||
],
|
],
|
||||||
"java": {
|
"java": {
|
||||||
"default": "8",
|
"default": "8",
|
||||||
"versions": [
|
"default_vendor": "Temurin-Hotspot",
|
||||||
"8", "11", "13"
|
"vendors": [
|
||||||
|
{
|
||||||
|
"name": "Temurin-Hotspot",
|
||||||
|
"versions": [ "8", "11" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Adopt",
|
||||||
|
"versions": [ "8", "11", "13" ]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
|
|||||||
@@ -106,8 +106,16 @@
|
|||||||
],
|
],
|
||||||
"java": {
|
"java": {
|
||||||
"default": "8",
|
"default": "8",
|
||||||
"versions": [
|
"default_vendor": "Temurin-Hotspot",
|
||||||
"8", "11"
|
"vendors": [
|
||||||
|
{
|
||||||
|
"name": "Temurin-Hotspot",
|
||||||
|
"versions": [ "8", "11" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Adopt",
|
||||||
|
"versions": [ "8", "11"]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
|
|||||||
Reference in New Issue
Block a user