Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions bin/refresh-java.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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) {
Expand Down