-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfoojay.lua
More file actions
56 lines (45 loc) · 1.52 KB
/
foojay.lua
File metadata and controls
56 lines (45 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local http = require("http")
local json = require("json")
local loongnix = require("loongnix")
local foojay = {}
local URL =
"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"
foojay.fetchtJdkList= function (distribution, version)
-- If on LoongArch architecture or loongson distribution is requested, use Loongnix
if loongnix.isLoongArch() or distribution == "loongson" then
return loongnix.fetchJdkList(version)
end
local os = RUNTIME.osType
local arch = RUNTIME.archType
if os == "darwin" then
os = "macos"
end
local archive_type = "tar.gz"
if os == "windows" then
archive_type = "zip"
if (arch == "amd64") then
arch = "x64"
end
end
local lib_c_type = ""
if os == "linux" then
lib_c_type = "glibc"
end
-- Convert arm64 to aarch64 for foojay API compatibility
if arch == "arm64" then
arch = "aarch64"
end
local reqUrl = URL:format(version, distribution, arch, archive_type, os, lib_c_type)
local resp, err = http.get({
url = reqUrl
})
if err ~= nil then
error("Failed to fetch jdk info from foojay: " .. err)
end
if resp.status_code ~= 200 then
error("Failed to fetch jdk info from foojay: status_code =>" .. resp.status_code)
end
local respBody = json.decode(resp.body)
return respBody.result
end
return foojay