mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-14 22:09:26 +00:00
[Windows] Remove AdoptOpenJDK (#8026)
This commit is contained in:
committed by
GitHub
parent
e1d1163c15
commit
974c7589b9
@@ -7,11 +7,10 @@ function Set-JavaPath {
|
||||
param (
|
||||
[string] $Version,
|
||||
[string] $Architecture = "x64",
|
||||
[switch] $Default,
|
||||
[string] $VendorName
|
||||
[switch] $Default
|
||||
)
|
||||
|
||||
$javaPathPattern = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_${VendorName}_jdk/${Version}*/${Architecture}"
|
||||
$javaPathPattern = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_Temurin-Hotspot_jdk/${Version}*/${Architecture}"
|
||||
$javaPath = (Get-Item -Path $javaPathPattern).FullName
|
||||
|
||||
if ([string]::IsNullOrEmpty($javaPath)) {
|
||||
@@ -22,18 +21,15 @@ function Set-JavaPath {
|
||||
Write-Host "Set 'JAVA_HOME_${Version}_X64' environmental variable as $javaPath"
|
||||
setx JAVA_HOME_${Version}_X64 $javaPath /M
|
||||
|
||||
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
|
||||
|
||||
$pathSegments = $currentPath.Split(';')
|
||||
$newPathSegments = @()
|
||||
|
||||
foreach ($pathSegment in $pathSegments)
|
||||
{
|
||||
if ($pathSegment -notlike '*java*')
|
||||
{
|
||||
foreach ($pathSegment in $pathSegments) {
|
||||
if ($pathSegment -notlike '*java*') {
|
||||
$newPathSegments += $pathSegment
|
||||
}
|
||||
}
|
||||
@@ -52,22 +48,16 @@ function Set-JavaPath {
|
||||
function Install-JavaJDK {
|
||||
param(
|
||||
[string] $JDKVersion,
|
||||
[string] $Architecture = "x64",
|
||||
[string] $VendorName
|
||||
[string] $Architecture = "x64"
|
||||
)
|
||||
|
||||
# Get Java version from api
|
||||
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"
|
||||
}
|
||||
$assetUrl = Invoke-RestMethod -Uri "https://api.adoptium.net/v3/assets/latest/${JDKVersion}/hotspot"
|
||||
|
||||
$asset = $assetUrl | Where-Object {
|
||||
$_.binary.os -eq "windows" `
|
||||
-and $_.binary.architecture -eq $Architecture `
|
||||
-and $_.binary.image_type -eq "jdk"
|
||||
-and $_.binary.architecture -eq $Architecture `
|
||||
-and $_.binary.image_type -eq "jdk"
|
||||
}
|
||||
|
||||
# Download and extract java binaries to temporary folder
|
||||
@@ -77,13 +67,12 @@ function Install-JavaJDK {
|
||||
# We have to replace '+' sign in the version to '-' due to the issue with incorrect path in Android builds https://github.com/actions/runner-images/issues/3014
|
||||
$fullJavaVersion = $asset.version.semver -replace '\+', '-'
|
||||
# Create directories in toolcache path
|
||||
$javaToolcachePath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_${VendorName}_jdk"
|
||||
$javaToolcachePath = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_Temurin-Hotspot_jdk"
|
||||
$javaVersionPath = Join-Path -Path $javaToolcachePath -ChildPath $fullJavaVersion
|
||||
$javaArchPath = Join-Path -Path $javaVersionPath -ChildPath $Architecture
|
||||
|
||||
if (-not (Test-Path $javaToolcachePath))
|
||||
{
|
||||
Write-Host "Creating ${VendorName} toolcache folder"
|
||||
if (-not (Test-Path $javaToolcachePath)) {
|
||||
Write-Host "Creating Temurin-Hotspot toolcache folder"
|
||||
New-Item -ItemType Directory -Path $javaToolcachePath | Out-Null
|
||||
}
|
||||
|
||||
@@ -99,37 +88,21 @@ function Install-JavaJDK {
|
||||
}
|
||||
|
||||
$toolsetJava = (Get-ToolsetContent).java
|
||||
$jdkVendors = $toolsetJava.vendors
|
||||
$defaultVendor = $toolsetJava.default_vendor
|
||||
$defaultVersion = $toolsetJava.default
|
||||
$jdkVersionsToInstall = $toolsetJava.versions
|
||||
|
||||
foreach ($jdkVendor in $jdkVendors) {
|
||||
$jdkVendorName = $jdkVendor.name
|
||||
$jdkVersionsToInstall = $jdkVendor.versions
|
||||
foreach ($jdkVersionToInstall in $jdkVersionsToInstall) {
|
||||
$isDefaultVersion = $jdkVersionToInstall -eq $defaultVersion
|
||||
|
||||
$isDefaultVendor = $jdkVendorName -eq $defaultVendor
|
||||
Install-JavaJDK -JDKVersion $jdkVersionToInstall
|
||||
|
||||
foreach ($jdkVersionToInstall in $jdkVersionsToInstall) {
|
||||
$isDefaultVersion = $jdkVersionToInstall -eq $defaultVersion
|
||||
|
||||
Install-JavaJDK -VendorName $jdkVendorName -JDKVersion $jdkVersionToInstall
|
||||
|
||||
if ($isDefaultVendor) {
|
||||
if ($isDefaultVersion) {
|
||||
Set-JavaPath -Version $jdkVersionToInstall -VendorName $jdkVendorName -Default
|
||||
} else {
|
||||
Set-JavaPath -Version $jdkVersionToInstall -VendorName $jdkVendorName
|
||||
}
|
||||
}
|
||||
if ($isDefaultVersion) {
|
||||
Set-JavaPath -Version $jdkVersionToInstall -Default
|
||||
} else {
|
||||
Set-JavaPath -Version $jdkVersionToInstall
|
||||
}
|
||||
}
|
||||
|
||||
# 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
|
||||
# Force chocolatey to ignore dependencies on Ant and Maven or else they will download the Oracle JDK
|
||||
Choco-Install -PackageName ant -ArgumentList "-i"
|
||||
|
||||
@@ -13,11 +13,9 @@ function Get-JavaVersions {
|
||||
$versionInPath = (Split-Path $javaPath) -replace "\w:\\.*\\"
|
||||
$version = $versionInPath -replace '-', '+'
|
||||
$defaultPostfix = ($javaPath -eq $defaultJavaPath) ? " (default)" : ""
|
||||
$VendorName = ($javaPath -like '*Java_Adopt_jdk*') ? "Adopt OpenJDK" : "Eclipse Temurin"
|
||||
|
||||
[PSCustomObject] @{
|
||||
"Version" = $version + $defaultPostfix
|
||||
"Vendor" = $VendorName
|
||||
"Version" = $version + $defaultPostfix
|
||||
"Environment Variable" = $_.Name
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
Describe "Java" {
|
||||
$toolsetJava = (Get-ToolsetContent).java
|
||||
$defaultVendor = $toolsetJava.default_vendor
|
||||
$javaVendors = $toolsetJava.vendors
|
||||
$defaultVersion = $toolsetJava.default
|
||||
$jdkVersions = $toolsetJava.versions
|
||||
|
||||
[array]$jdkVersions = ($javaVendors | Where-Object {$_.name -eq $defaultVendor}).versions | ForEach-Object { @{Version = $_} }
|
||||
[array]$adoptJdkVersions = ($javaVendors | Where-Object {$_.name -eq "Adopt"}).versions | ForEach-Object { @{Version = $_} }
|
||||
[array]$testCases = $jdkVersions | ForEach-Object { @{Version = $_ } }
|
||||
|
||||
It "Java <DefaultJavaVersion> is default" -TestCases @(@{ DefaultJavaVersion = $defaultVersion }) {
|
||||
$actualJavaPath = Get-EnvironmentVariable "JAVA_HOME"
|
||||
@@ -25,7 +23,7 @@ Describe "Java" {
|
||||
"$ToolName -version" | Should -ReturnZeroExitCode
|
||||
}
|
||||
|
||||
It "Java <Version>" -TestCases $jdkVersions {
|
||||
It "Java <Version>" -TestCases $testCases {
|
||||
$javaVariableValue = Get-EnvironmentVariable "JAVA_HOME_${Version}_X64"
|
||||
$javaVariableValue | Should -Not -BeNullOrEmpty
|
||||
$javaPath = Join-Path $javaVariableValue "bin\java"
|
||||
@@ -39,17 +37,4 @@ Describe "Java" {
|
||||
$outputPattern = "openjdk version `"${Version}"
|
||||
$result.Output[0] | Should -Match $outputPattern
|
||||
}
|
||||
|
||||
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}"
|
||||
}
|
||||
$outputPattern = "openjdk version `"${Version}"
|
||||
$result.Output[0] | Should -Match $outputPattern
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,17 +147,7 @@
|
||||
],
|
||||
"java": {
|
||||
"default": "8",
|
||||
"default_vendor": "Temurin-Hotspot",
|
||||
"vendors": [
|
||||
{
|
||||
"name": "Temurin-Hotspot",
|
||||
"versions": [ "8", "11", "17" ]
|
||||
},
|
||||
{
|
||||
"name": "Adopt",
|
||||
"versions": [ "8", "11", "13" ]
|
||||
}
|
||||
]
|
||||
"versions": [ "8", "11", "17" ]
|
||||
},
|
||||
"android": {
|
||||
"platform_min_version": "19",
|
||||
|
||||
@@ -128,17 +128,7 @@
|
||||
],
|
||||
"java": {
|
||||
"default": "8",
|
||||
"default_vendor": "Temurin-Hotspot",
|
||||
"vendors": [
|
||||
{
|
||||
"name": "Temurin-Hotspot",
|
||||
"versions": [ "8", "11", "17" ]
|
||||
},
|
||||
{
|
||||
"name": "Adopt",
|
||||
"versions": [ "8", "11"]
|
||||
}
|
||||
]
|
||||
"versions": [ "8", "11", "17" ]
|
||||
},
|
||||
"android": {
|
||||
"platform_min_version": "27",
|
||||
|
||||
Reference in New Issue
Block a user