mirror of
https://github.com/actions/runner-images-sangeeth.git
synced 2025-12-17 07:16:46 +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 (
|
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_${VendorName}_jdk/${Version}*/${Architecture}"
|
$javaPathPattern = Join-Path -Path $env:AGENT_TOOLSDIRECTORY -ChildPath "Java_Temurin-Hotspot_jdk/${Version}*/${Architecture}"
|
||||||
$javaPath = (Get-Item -Path $javaPathPattern).FullName
|
$javaPath = (Get-Item -Path $javaPathPattern).FullName
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($javaPath)) {
|
if ([string]::IsNullOrEmpty($javaPath)) {
|
||||||
@@ -22,18 +21,15 @@ function Set-JavaPath {
|
|||||||
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
|
||||||
|
|
||||||
if ($Default)
|
if ($Default) {
|
||||||
{
|
|
||||||
# Clean up any other Java folders from PATH to make sure that they won't conflict with each other
|
# 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(';')
|
||||||
$newPathSegments = @()
|
$newPathSegments = @()
|
||||||
|
|
||||||
foreach ($pathSegment in $pathSegments)
|
foreach ($pathSegment in $pathSegments) {
|
||||||
{
|
if ($pathSegment -notlike '*java*') {
|
||||||
if ($pathSegment -notlike '*java*')
|
|
||||||
{
|
|
||||||
$newPathSegments += $pathSegment
|
$newPathSegments += $pathSegment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,18 +48,12 @@ function Set-JavaPath {
|
|||||||
function Install-JavaJDK {
|
function Install-JavaJDK {
|
||||||
param(
|
param(
|
||||||
[string] $JDKVersion,
|
[string] $JDKVersion,
|
||||||
[string] $Architecture = "x64",
|
[string] $Architecture = "x64"
|
||||||
[string] $VendorName
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get Java version from api
|
# Get Java version from api
|
||||||
if ($VendorName -eq "Temurin-Hotspot") {
|
|
||||||
$assetUrl = Invoke-RestMethod -Uri "https://api.adoptium.net/v3/assets/latest/${JDKVersion}/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 `
|
||||||
@@ -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
|
# 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 '\+', '-'
|
$fullJavaVersion = $asset.version.semver -replace '\+', '-'
|
||||||
# Create directories in toolcache path
|
# 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
|
$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 Temurin-Hotspot toolcache folder"
|
||||||
Write-Host "Creating ${VendorName} toolcache folder"
|
|
||||||
New-Item -ItemType Directory -Path $javaToolcachePath | Out-Null
|
New-Item -ItemType Directory -Path $javaToolcachePath | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,35 +88,19 @@ function Install-JavaJDK {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$toolsetJava = (Get-ToolsetContent).java
|
$toolsetJava = (Get-ToolsetContent).java
|
||||||
$jdkVendors = $toolsetJava.vendors
|
|
||||||
$defaultVendor = $toolsetJava.default_vendor
|
|
||||||
$defaultVersion = $toolsetJava.default
|
$defaultVersion = $toolsetJava.default
|
||||||
|
$jdkVersionsToInstall = $toolsetJava.versions
|
||||||
|
|
||||||
foreach ($jdkVendor in $jdkVendors) {
|
foreach ($jdkVersionToInstall in $jdkVersionsToInstall) {
|
||||||
$jdkVendorName = $jdkVendor.name
|
|
||||||
$jdkVersionsToInstall = $jdkVendor.versions
|
|
||||||
|
|
||||||
$isDefaultVendor = $jdkVendorName -eq $defaultVendor
|
|
||||||
|
|
||||||
foreach ($jdkVersionToInstall in $jdkVersionsToInstall) {
|
|
||||||
$isDefaultVersion = $jdkVersionToInstall -eq $defaultVersion
|
$isDefaultVersion = $jdkVersionToInstall -eq $defaultVersion
|
||||||
|
|
||||||
Install-JavaJDK -VendorName $jdkVendorName -JDKVersion $jdkVersionToInstall
|
Install-JavaJDK -JDKVersion $jdkVersionToInstall
|
||||||
|
|
||||||
if ($isDefaultVendor) {
|
|
||||||
if ($isDefaultVersion) {
|
if ($isDefaultVersion) {
|
||||||
Set-JavaPath -Version $jdkVersionToInstall -VendorName $jdkVendorName -Default
|
Set-JavaPath -Version $jdkVersionToInstall -Default
|
||||||
} else {
|
} else {
|
||||||
Set-JavaPath -Version $jdkVersionToInstall -VendorName $jdkVendorName
|
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
|
# Install Java tools
|
||||||
|
|||||||
@@ -13,11 +13,9 @@ 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" = $VendorName
|
|
||||||
"Environment Variable" = $_.Name
|
"Environment Variable" = $_.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
Describe "Java" {
|
Describe "Java" {
|
||||||
$toolsetJava = (Get-ToolsetContent).java
|
$toolsetJava = (Get-ToolsetContent).java
|
||||||
$defaultVendor = $toolsetJava.default_vendor
|
|
||||||
$javaVendors = $toolsetJava.vendors
|
|
||||||
$defaultVersion = $toolsetJava.default
|
$defaultVersion = $toolsetJava.default
|
||||||
|
$jdkVersions = $toolsetJava.versions
|
||||||
|
|
||||||
[array]$jdkVersions = ($javaVendors | Where-Object {$_.name -eq $defaultVendor}).versions | ForEach-Object { @{Version = $_} }
|
[array]$testCases = $jdkVersions | 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"
|
||||||
@@ -25,7 +23,7 @@ Describe "Java" {
|
|||||||
"$ToolName -version" | Should -ReturnZeroExitCode
|
"$ToolName -version" | Should -ReturnZeroExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Java <Version>" -TestCases $jdkVersions {
|
It "Java <Version>" -TestCases $testCases {
|
||||||
$javaVariableValue = Get-EnvironmentVariable "JAVA_HOME_${Version}_X64"
|
$javaVariableValue = Get-EnvironmentVariable "JAVA_HOME_${Version}_X64"
|
||||||
$javaVariableValue | Should -Not -BeNullOrEmpty
|
$javaVariableValue | Should -Not -BeNullOrEmpty
|
||||||
$javaPath = Join-Path $javaVariableValue "bin\java"
|
$javaPath = Join-Path $javaVariableValue "bin\java"
|
||||||
@@ -39,17 +37,4 @@ Describe "Java" {
|
|||||||
$outputPattern = "openjdk version `"${Version}"
|
$outputPattern = "openjdk version `"${Version}"
|
||||||
$result.Output[0] | Should -Match $outputPattern
|
$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,18 +147,8 @@
|
|||||||
],
|
],
|
||||||
"java": {
|
"java": {
|
||||||
"default": "8",
|
"default": "8",
|
||||||
"default_vendor": "Temurin-Hotspot",
|
|
||||||
"vendors": [
|
|
||||||
{
|
|
||||||
"name": "Temurin-Hotspot",
|
|
||||||
"versions": [ "8", "11", "17" ]
|
"versions": [ "8", "11", "17" ]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Adopt",
|
|
||||||
"versions": [ "8", "11", "13" ]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"android": {
|
"android": {
|
||||||
"platform_min_version": "19",
|
"platform_min_version": "19",
|
||||||
"build_tools_min_version": "19.1.0",
|
"build_tools_min_version": "19.1.0",
|
||||||
|
|||||||
@@ -128,18 +128,8 @@
|
|||||||
],
|
],
|
||||||
"java": {
|
"java": {
|
||||||
"default": "8",
|
"default": "8",
|
||||||
"default_vendor": "Temurin-Hotspot",
|
|
||||||
"vendors": [
|
|
||||||
{
|
|
||||||
"name": "Temurin-Hotspot",
|
|
||||||
"versions": [ "8", "11", "17" ]
|
"versions": [ "8", "11", "17" ]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Adopt",
|
|
||||||
"versions": [ "8", "11"]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"android": {
|
"android": {
|
||||||
"platform_min_version": "27",
|
"platform_min_version": "27",
|
||||||
"build_tools_min_version": "27.0.0",
|
"build_tools_min_version": "27.0.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user