Skip to content

Commit fe577ba

Browse files
authored
Supports installation commands like vfox install java@26.ea.1-graal (#57)
1 parent 478e097 commit fe577ba

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

hooks/pre_install.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ function PLUGIN:PreInstall(ctx)
3333
end
3434

3535
local jdk = filtered_jdks[1]
36+
if not jdk.links or not jdk.links.pkg_info_uri then
37+
error("Invalid JDK package info: missing download links for " .. ctx.version)
38+
end
3639
local info = json.decode(httpGet(jdk.links.pkg_info_uri, "Failed to fetch jdk info")).result[1]
3740
-- TODO: checksum
3841
-- local checksum = info.checksum

lib/distribution_version.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ function distribution_version.parse_distribution (name)
5555
end
5656

5757

58+
--- Converts user-input version format to Foojay API format
59+
--- Examples: "26.ea.1" -> "26-ea+1", "26.ea" -> "26-ea", "25.0.3" -> "25.0.3"
60+
--- @param version string User-input version
61+
--- @return string Converted version for Foojay API
62+
function distribution_version.convert_version_for_api(version)
63+
-- Handle EA version format: "X.ea.Y" -> "X-ea+Y"
64+
local ea_version, ea_build = version:match("^(%d+)%.ea%.(%d+)$")
65+
if ea_version and ea_build then
66+
return ea_version .. "-ea+" .. ea_build
67+
end
68+
69+
-- Handle EA version format without build number: "X.ea" -> "X-ea"
70+
local ea_version_only = version:match("^(%d+)%.ea$")
71+
if ea_version_only then
72+
return ea_version_only .. "-ea"
73+
end
74+
75+
-- Return as-is for normal versions
76+
return version
77+
end
78+
5879
function distribution_version.parse_version (arg)
5980
local version_parts = strings.split(arg, "-")
6081
local version
@@ -94,6 +115,9 @@ function distribution_version.parse_version (arg)
94115
end
95116
end
96117

118+
-- Convert version format for Foojay API
119+
version = distribution_version.convert_version_for_api(version)
120+
97121
return {
98122
version = version,
99123
distribution = distribution,

lib/foojay.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local json = require("json")
44
local foojay = {}
55

66
local URL =
7-
"https://api.foojay.io/disco/v3.0/packages/jdks?version=%s&distribution=%s&architecture=%s&archive_type=%s&operating_system=%s&lib_c_type=%s&release_status=ga&directly_downloadable=true"
7+
"https://api.foojay.io/disco/v3.0/packages/jdks?version=%s&distribution=%s&architecture=%s&archive_type=%s&operating_system=%s&lib_c_type=%s&directly_downloadable=true"
88

99
--- Detects the libc type on Linux systems (glibc or musl)
1010
--- @return string "glibc" or "musl"

0 commit comments

Comments
 (0)