Skip to content
Draft
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,17 @@ $ vfox install [email protected]
$ vfox search java jb
```

## Loongson (Loongnix)
Loongson JDK is the OpenJDK distribution optimized for LoongArch (loong64) architecture from Loongnix. It supports JDK 8, 11, 17, and 21 LTS versions on Linux systems with LoongArch64 processors. This distribution is automatically used when running on LoongArch architecture.

```shell
$ vfox install [email protected]
$ vfox search java loong
```


# Thanks

- [SDKMAN](https://github.com/sdkman/)
- [foojayio](https://github.com/foojayio/discoapi)
- [foojayio](https://github.com/foojayio/discoapi)
- [Loongnix](https://www.loongnix.cn/)
12 changes: 11 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,17 @@ $ vfox install java x.y.z-jb
$ vfox search java jb
```

## Loongson (龙芯/Loongnix)

龙芯 JDK 是针对 LoongArch(loong64/龙架构)架构优化的 OpenJDK 发行版,来自 Loongnix 龙芯开源社区。支持 Linux 系统上的 JDK 8、11、17 和 21 LTS 版本。在 LoongArch 架构上运行时会自动使用此发行版。

```shell
$ vfox install java x.y.z-loong
$ vfox search java loong
```

# 感谢

- [SDKMAN](https://github.com/sdkman/)
- [foojayio](https://github.com/foojayio/discoapi)
- [foojayio](https://github.com/foojayio/discoapi)
- [Loongnix 龙芯开源社区](https://www.loongnix.cn/)
11 changes: 11 additions & 0 deletions hooks/pre_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ function PLUGIN:PreInstall(ctx)
error("No JDK found for " .. ctx.version .. " on " .. RUNTIME.osType .. "/" .. RUNTIME.archType .. ". Please check available versions with 'vfox search java'")
end
local jdk = jdks[1]

-- Check if this is a Loongson JDK (from Loongnix)
if jdk.distribution == "loongson" then
local finalV = jdk.java_version .. "-" .. distribution_version.distribution.short_name
return {
url = jdk.download_url,
version = finalV,
note = jdk.major_version
}
end

local info = json.decode(httpGet(jdk.links.pkg_info_uri, "Failed to fetch jdk info")).result[1]
-- TODO: checksum
-- local checksum = info.checksum
Expand Down
1 change: 1 addition & 0 deletions lib/distribution_version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local short_name = {
["trava"] = "trava",
["zulu"] = "zulu",
["jb"] = "jetbrains",
["loong"] = "loongson",
}

local long_name={}
Expand Down
6 changes: 5 additions & 1 deletion lib/foojay.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
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
Expand All @@ -28,7 +33,6 @@ foojay.fetchtJdkList= function (distribution, version)
end

-- Convert arm64 to aarch64 for foojay API compatibility
local arch = RUNTIME.archType
if arch == "arm64" then
arch = "aarch64"
end
Expand Down
151 changes: 151 additions & 0 deletions lib/loongnix.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
local http = require("http")
local strings = require("vfox.strings")

local loongnix = {}

local FTP_BASE_URL = "http://ftp.loongnix.cn/Java/"

-- Supported major versions on Loongnix
local SUPPORTED_VERSIONS = {8, 11, 17, 21}

-- Parse FTP directory listing to extract tar.gz files
local function parseFtpListing(html)
local files = {}
-- Match href links that end with .tar.gz and contain loongarch64
for filename in string.gmatch(html, 'href="([^"]*loongarch64%.tar%.gz)"') do
table.insert(files, filename)
end
return files
end

-- Parse version info from Loongnix filename
-- Format examples:
-- loongson8.1.11-jdk8u332b09-linux-loongarch64.tar.gz
-- loongson11.6.26-fx-jdk11.0.16_8-linux-loongarch64.tar.gz
-- loongson17.11.21-fx-jdk17.0.12_7-linux-loongarch64.tar.gz
-- loongson21.1.0-fx-jdk21_35-linux-loongarch64.tar.gz
local function parseFilename(filename, majorVersion)
local javaVersion

if majorVersion == 8 then
-- Pattern: loongson8.x.x-jdk8u<update>b<build>-linux-loongarch64.tar.gz
local update, build = string.match(filename, "jdk8u(%d+)b(%d+)")
if update then
javaVersion = "8.0." .. update
end
else
-- Pattern: loongsonXX.x.x-fx-jdkXX.Y.Z_N-linux-loongarch64.tar.gz
-- or: loongsonXX.x.x-jdkXX.Y.Z_N-linux-loongarch64.tar.gz
local major, minor, patch = string.match(filename, "jdk(%d+)%.(%d+)%.(%d+)")
if major then
javaVersion = major .. "." .. minor .. "." .. patch
end
end

return javaVersion
end

-- Fetch JDK list for a specific major version
local function fetchVersionList(majorVersion)
local url = FTP_BASE_URL .. "openjdk" .. majorVersion .. "/"

local resp, err = http.get({
url = url
})

if err ~= nil then
return nil, "Failed to fetch from Loongnix: " .. err
end

if resp.status_code ~= 200 then
return nil, "Failed to fetch from Loongnix: status_code => " .. resp.status_code
end

local files = parseFtpListing(resp.body)
local jdks = {}

for _, filename in ipairs(files) do
local javaVersion = parseFilename(filename, majorVersion)
if javaVersion then
table.insert(jdks, {
java_version = javaVersion,
major_version = majorVersion,
filename = filename,
download_url = url .. filename,
term_of_support = (majorVersion == 8 or majorVersion == 11 or majorVersion == 17 or majorVersion == 21) and "lts" or "",
distribution = "loongson"
})
end
end

return jdks
end

-- Fetch JDK list from Loongnix FTP
-- @param version: specific version to filter (optional, can be empty string or major version like "17")
loongnix.fetchJdkList = function(version)
local os = RUNTIME.osType
local arch = RUNTIME.archType

-- Loongnix only supports Linux on loongarch64
if os ~= "linux" then
return {}
end

-- Check for loongarch64 architecture (might be reported as loong64 or loongarch64)
if arch ~= "loong64" and arch ~= "loongarch64" then
return {}
end

local allJdks = {}

-- Determine which versions to fetch
local versionsToFetch = SUPPORTED_VERSIONS

-- If a specific major version is requested, only fetch that one
if version and version ~= "" then
local majorVersion = tonumber(string.match(version, "^(%d+)"))
if majorVersion then
local found = false
for _, v in ipairs(SUPPORTED_VERSIONS) do
if v == majorVersion then
found = true
break
end
end
if found then
versionsToFetch = {majorVersion}
end
end
end

for _, majorVersion in ipairs(versionsToFetch) do
local jdks, err = fetchVersionList(majorVersion)
if jdks then
for _, jdk in ipairs(jdks) do
table.insert(allJdks, jdk)
end
end
end

-- Filter by specific version if provided
if version and version ~= "" then
local filtered = {}
for _, jdk in ipairs(allJdks) do
if strings.has_prefix(jdk.java_version, version) or jdk.java_version == version then
table.insert(filtered, jdk)
end
end
return filtered
end

return allJdks
end

-- Check if Loongnix should be used based on architecture
loongnix.isLoongArch = function()
local arch = RUNTIME.archType
return arch == "loong64" or arch == "loongarch64"
end

return loongnix
1 change: 1 addition & 0 deletions metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ PLUGIN.notes = {
" - GraalVM: x.y.z-graal",
" - Temurin: x.y.z-tem",
" - Zulu: x.y.z-zulu",
" - Loongson: x.y.z-loong (LoongArch/loong64 only)",
"Others please see: https://github.com/version-fox/vfox-java"

}