Skip to content

Commit

Permalink
feat: support search all java sdks (#5)
Browse files Browse the repository at this point in the history
- `vfox search java all` list all java sdks, version-fox/vfox#174
- fix #3
  • Loading branch information
gythialy authored Apr 7, 2024
1 parent 45b0aed commit 7af0e8b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ vfox install [email protected] # Use openjdk as default distribution.
vfox install [email protected] # Use graalvm as distribution.

# view all available versions
vfox search java all # view all java sdks
vfox search java # view all for openjdk
vfox search java graal # view all for graalvm
```
Expand Down
1 change: 1 addition & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vfox install [email protected] # 默认使用openjdk
vfox install [email protected] # 使用graalvm

# 查看所有可用版本
vfox search java all # 查看所有sdk版本
vfox search java # 查看所有openjdk版本
vfox search java graal # 查看所有graalvm版本
```
Expand Down
41 changes: 27 additions & 14 deletions hooks/available.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,39 @@ local shortname = require("shortname")
--- @param ctx table Empty table used as context, for future extension
--- @return table Descriptions of available versions and accompanying tool descriptions
function PLUGIN:Available(ctx)
local distribution = ctx.args[1] or "open"
if not shortname[distribution] then
error("Unsupport distribution: " .. distribution)
local distribution = ctx.args[1]
local jdks = {}

if distribution and distribution == "all" then
for short, dist in pairs(shortname) do
local tempJdks = foojay.fetchtJdkList(dist, "")
for _, jdk in ipairs(tempJdks) do
jdk.short = short
table.insert(jdks, jdk)
end
end
else
jdks = foojay.fetchtJdkList(shortname[distribution] or error("Unsupported distribution: " .. distribution), "")
end
local jdks = foojay.fetchtJdkList(shortname[distribution], "")

local result = {}
local seen = {}
for _, jdk in ipairs(jdks) do
local v = jdk.java_version
if distribution ~= "open" then
v = v .. "-" .. distribution
local short = jdk.short
if short and short ~= "open" then
v = v .. "-" .. short
end
local note = ""
if jdk.term_of_support == "lts" then
note = "LTS"

if not seen[v] then
seen[v] = true
-- check if version exists
table.insert(result, {
version = v,
note = jdk.term_of_support == "lts" and "LTS" or ""
})
end
table.insert(result, {
version = v,
note = note,
})

end
return result
end
end
2 changes: 1 addition & 1 deletion metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PLUGIN = {}
--- Plugin name
PLUGIN.name = "java"
--- Plugin version
PLUGIN.version = "0.1.1"
PLUGIN.version = "0.1.2"
--- Plugin homepage
PLUGIN.homepage = "https://github.com/version-fox/vfox-java"
--- Plugin license, please choose a correct license according to your needs.
Expand Down

0 comments on commit 7af0e8b

Please sign in to comment.