[Windows] Move preinstalled java distributions to the toolcache directory (#2903)

* Move installation to toolcache folder

* Change Set-JavaPath function

* remove old java report function

* Change report function to output full semver

* small improvments

* nitpicks + remove java root path

* Adoptium -> Adopt
This commit is contained in:
Mikhail Timofeev
2021-03-16 17:16:16 +03:00
committed by GitHub
parent ef6e8c905f
commit 0cf21e4512
3 changed files with 40 additions and 49 deletions

View File

@@ -1,12 +1,3 @@
function Get-JavaFullVersion {
param($JavaRootPath)
$javaBinPath = Join-Path "$javaRootPath" "/bin/java"
$javaVersionOutput = (Get-CommandResult "`"$javaBinPath`" -version").Output
$matchResult = $javaVersionOutput | Select-String '^openjdk version \"([\d\._]+)\"'
return $matchResult.Matches.Groups[1].Value
}
function Get-JavaVersions {
$defaultJavaPath = $env:JAVA_HOME
$javaVersions = Get-Item env:JAVA_HOME_*_X64
@@ -17,7 +8,8 @@ function Get-JavaVersions {
return $javaVersions | Sort-Object $sortRules | ForEach-Object {
$javaPath = $_.Value
$version = Get-JavaFullVersion "$javaPath"
# Take semver from the java path
$version = (Split-Path $javaPath) -replace "\w:\\.*\\"
$defaultPostfix = ($javaPath -eq $defaultJavaPath) ? " (default)" : ""
[PSCustomObject] @{