From 9ac7978050d4d42c787f8f6dec1e633f8ae4cd79 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 19:01:46 +0000 Subject: [PATCH 1/3] Initial plan From 8191e0bc4d07020c02060ec2ba2eaaf96a727204 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 19:08:28 +0000 Subject: [PATCH 2/3] Add LoongArch (loong64) architecture support via Loongnix JDK distribution Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com> --- README.md | 11 ++- README_CN.md | 12 ++- hooks/pre_install.lua | 11 +++ lib/distribution_version.lua | 1 + lib/foojay.lua | 5 ++ lib/loongnix.lua | 151 +++++++++++++++++++++++++++++++++++ metadata.lua | 1 + 7 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 lib/loongnix.lua diff --git a/README.md b/README.md index abe22ad..7a9ca48 100644 --- a/README.md +++ b/README.md @@ -180,8 +180,17 @@ $ vfox install java@x.y.z-jb $ 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 java@x.y.z-loong +$ vfox search java loong +``` + # Thanks - [SDKMAN](https://github.com/sdkman/) -- [foojayio](https://github.com/foojayio/discoapi) \ No newline at end of file +- [foojayio](https://github.com/foojayio/discoapi) +- [Loongnix](https://www.loongnix.cn/) \ No newline at end of file diff --git a/README_CN.md b/README_CN.md index 80b2e77..6305137 100644 --- a/README_CN.md +++ b/README_CN.md @@ -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) \ No newline at end of file +- [foojayio](https://github.com/foojayio/discoapi) +- [Loongnix 龙芯开源社区](https://www.loongnix.cn/) \ No newline at end of file diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua index 1ca4f43..85b9bd7 100644 --- a/hooks/pre_install.lua +++ b/hooks/pre_install.lua @@ -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" or distribution_version.distribution.name == "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 diff --git a/lib/distribution_version.lua b/lib/distribution_version.lua index 5ad2120..d2d2850 100644 --- a/lib/distribution_version.lua +++ b/lib/distribution_version.lua @@ -19,6 +19,7 @@ local short_name = { ["trava"] = "trava", ["zulu"] = "zulu", ["jb"] = "jetbrains", + ["loong"] = "loongson", } local long_name={} diff --git a/lib/foojay.lua b/lib/foojay.lua index a7ab348..de06aa5 100644 --- a/lib/foojay.lua +++ b/lib/foojay.lua @@ -1,5 +1,6 @@ local http = require("http") local json = require("json") +local loongnix = require("loongnix") local foojay = {} @@ -7,6 +8,10 @@ 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 diff --git a/lib/loongnix.lua b/lib/loongnix.lua new file mode 100644 index 0000000..8470c26 --- /dev/null +++ b/lib/loongnix.lua @@ -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-jdk8ub-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 diff --git a/metadata.lua b/metadata.lua index 5bd8abf..702bcbc 100644 --- a/metadata.lua +++ b/metadata.lua @@ -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" } From 7399eaeb502fb654b99435369b7d2fdf44bd3a4a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 18 Jan 2026 19:10:33 +0000 Subject: [PATCH 3/3] Fix code review feedback: remove variable redeclaration in foojay.lua and simplify condition Co-authored-by: bytemain <13938334+bytemain@users.noreply.github.com> --- hooks/pre_install.lua | 2 +- lib/foojay.lua | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua index 85b9bd7..43411f0 100644 --- a/hooks/pre_install.lua +++ b/hooks/pre_install.lua @@ -20,7 +20,7 @@ function PLUGIN:PreInstall(ctx) local jdk = jdks[1] -- Check if this is a Loongson JDK (from Loongnix) - if jdk.distribution == "loongson" or distribution_version.distribution.name == "loongson" then + if jdk.distribution == "loongson" then local finalV = jdk.java_version .. "-" .. distribution_version.distribution.short_name return { url = jdk.download_url, diff --git a/lib/foojay.lua b/lib/foojay.lua index de06aa5..a5511c5 100644 --- a/lib/foojay.lua +++ b/lib/foojay.lua @@ -33,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