Skip to content

Commit 7af0e8b

Browse files
authored
feat: support search all java sdks (#5)
- `vfox search java all` list all java sdks, version-fox/vfox#174 - fix #3
1 parent 45b0aed commit 7af0e8b

4 files changed

Lines changed: 30 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ vfox install java@x.y.z # Use openjdk as default distribution.
2020
vfox install java@x.y.z-graal # Use graalvm as distribution.
2121

2222
# view all available versions
23+
vfox search java all # view all java sdks
2324
vfox search java # view all for openjdk
2425
vfox search java graal # view all for graalvm
2526
```

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ vfox install java@x.y.z # 默认使用openjdk
1919
vfox install java@x.y.z-graal # 使用graalvm
2020

2121
# 查看所有可用版本
22+
vfox search java all # 查看所有sdk版本
2223
vfox search java # 查看所有openjdk版本
2324
vfox search java graal # 查看所有graalvm版本
2425
```

hooks/available.lua

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,39 @@ local shortname = require("shortname")
55
--- @param ctx table Empty table used as context, for future extension
66
--- @return table Descriptions of available versions and accompanying tool descriptions
77
function PLUGIN:Available(ctx)
8-
local distribution = ctx.args[1] or "open"
9-
if not shortname[distribution] then
10-
error("Unsupport distribution: " .. distribution)
8+
local distribution = ctx.args[1]
9+
local jdks = {}
10+
11+
if distribution and distribution == "all" then
12+
for short, dist in pairs(shortname) do
13+
local tempJdks = foojay.fetchtJdkList(dist, "")
14+
for _, jdk in ipairs(tempJdks) do
15+
jdk.short = short
16+
table.insert(jdks, jdk)
17+
end
18+
end
19+
else
20+
jdks = foojay.fetchtJdkList(shortname[distribution] or error("Unsupported distribution: " .. distribution), "")
1121
end
12-
local jdks = foojay.fetchtJdkList(shortname[distribution], "")
1322

1423
local result = {}
24+
local seen = {}
1525
for _, jdk in ipairs(jdks) do
1626
local v = jdk.java_version
17-
if distribution ~= "open" then
18-
v = v .. "-" .. distribution
27+
local short = jdk.short
28+
if short and short ~= "open" then
29+
v = v .. "-" .. short
1930
end
20-
local note = ""
21-
if jdk.term_of_support == "lts" then
22-
note = "LTS"
31+
32+
if not seen[v] then
33+
seen[v] = true
34+
-- check if version exists
35+
table.insert(result, {
36+
version = v,
37+
note = jdk.term_of_support == "lts" and "LTS" or ""
38+
})
2339
end
24-
table.insert(result, {
25-
version = v,
26-
note = note,
27-
})
40+
2841
end
2942
return result
30-
end
43+
end

metadata.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PLUGIN = {}
55
--- Plugin name
66
PLUGIN.name = "java"
77
--- Plugin version
8-
PLUGIN.version = "0.1.1"
8+
PLUGIN.version = "0.1.2"
99
--- Plugin homepage
1010
PLUGIN.homepage = "https://github.com/version-fox/vfox-java"
1111
--- Plugin license, please choose a correct license according to your needs.

0 commit comments

Comments
 (0)