2021-01-18 19:45:17 +07:00
function Get-JavaVersions {
$defaultJavaPath = $env:JAVA_HOME
$javaVersions = Get-Item env : JAVA_HOME_ * _X64
$sortRules = @ {
2023-12-04 10:50:53 +01:00
Expression = { [ Int32 ] $_ . Name . Split ( " _ " ) [ 2 ] }
2021-01-18 19:45:17 +07:00
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
2022-08-10 13:55:34 +01: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/runner-images/issues/3014
2021-03-27 10:50:50 +03:00
$versionInPath = ( Split-Path $javaPath ) -replace " \w:\\.*\\ "
$version = $versionInPath -replace '-' , '+'
2021-01-18 19:45:17 +07:00
$defaultPostfix = ( $javaPath -eq $defaultJavaPath ) ? " (default) " : " "
[ PSCustomObject ] @ {
2023-08-03 10:32:48 +02:00
" Version " = $version + $defaultPostfix
2021-01-18 19:45:17 +07:00
" Environment Variable " = $_ . Name
}
}
2023-12-04 10:50:53 +01:00
}