diff --git a/bin/refresh-java.ps1 b/bin/refresh-java.ps1 index 4d663de..7545956 100644 --- a/bin/refresh-java.ps1 +++ b/bin/refresh-java.ps1 @@ -13,19 +13,31 @@ $ConfigPath = "$PSScriptRoot\..\versions.json" # 1. Scan for Installed Java Versions function Get-JavaVersions { - $Paths = @($JavaRoot, "C:\Program Files\Eclipse Adoptium", "C:\Program Files\Amazon Corretto") + # Possible JDK install paths + $Paths = @( + $JavaRoot, + "C:\Program Files\Eclipse Adoptium", + "C:\Program Files\Amazon Corretto", + "C:\Program Files\Zulu" + ) $Found = @{} foreach ($Path in $Paths) { if (Test-Path $Path) { - Get-ChildItem $Path -Directory | Where-Object { $_.Name -match 'jdk[-_]?(\d+)' } | ForEach-Object { - $Ver = $Matches[1] + # Check for jdk installs, checks for not only jdk-# but also zulu-# and corretto-# + # Expression may need to be updated if other java versions use different formats for the name + Get-ChildItem $Path -Directory | Where-Object { $_.Name -match '(corretto|zulu|jdk)[-_]?(\d+)' } | ForEach-Object { + # We save the full name instead of just the number (eg. zulu-8, jdk-8, etc.) + # This is so we can have the same jdk version from different publishers and still + # Display/Choose from both (ex. jdk-8, zulu-8) + $Ver = $Matches[0] if (-not $Found.ContainsKey($Ver)) { $Found[$Ver] = $_.FullName } } } } + return $Found } @@ -34,7 +46,8 @@ $Versions = Get-JavaVersions # Handle listing if ($List -or ($null -eq $SwitchTo -and $false -eq $List)) { Write-Host "Available Java Versions:" -ForegroundColor Cyan - foreach ($v in ($Versions.Keys | Sort-Object {[int]$_})) { + # Sort first alphabetically then numerically, this makes each brand appear seperate while still being sorted + foreach ($v in ($Versions.Keys | Sort-Object { ($_ -split '-')[0] }, { [int]($_ -split '-')[1] })) { Write-Host " [$v] -> $($Versions[$v])" } if (Test-Path $SymlinkPath) {