From 0499a202f5b987ed1e1a36511b21c4e156dea59e Mon Sep 17 00:00:00 2001 From: "Joshua J. Nett" Date: Tue, 25 Aug 2026 10:15:07 -0500 Subject: [PATCH] Add support for Zulu JDK in Java version scanner Add support for Zulu JDK as well as adding support for conflicting JDK versions from different publishers. (May still have issues with Eclipse vs Oracle since they both are labeled jdk-#) --- bin/refresh-java.ps1 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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) {