2021-01-18 19:45:17 +07:00
function Get-JavaVersions {
$defaultJavaPath = $env:JAVA_HOME
$javaVersions = Get-Item env : JAVA_HOME_ * _X64
$sortRules = @ {
Expression = { [ Int32 ] $_ . Name . Split ( "_" )[ 2 ] }
Descending = $false
}
return $javaVersions | Sort-Object $sortRules | ForEach-Object {
$javaPath = $_ . Value
2021-03-16 17:16:16 +03:00
# Take semver from the java path
2021-03-27 10:50:50 +03:00
# The path contains '-' sign in the version number instead of '+' due to the following issue, need to substitute it back https://github.com/actions/virtual-environments/issues/3014
$versionInPath = ( Split-Path $javaPath ) -replace "\w:\\.*\\"
$version = $versionInPath -replace '-' , '+'
2021-01-18 19:45:17 +07:00
$defaultPostfix = ( $javaPath -eq $defaultJavaPath ) ? " (default)" : ""
[ PSCustomObject ] @ {
"Version" = $version + $defaultPostfix
2021-03-27 10:50:50 +03:00
"Vendor" = "Adopt OpenJDK"
2021-01-18 19:45:17 +07:00
"Environment Variable" = $_ . Name
}
}
}