Skip to content
Merged
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
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Support for multiple JDK distributions, such as: Oracle, Graalvm, Eclipse & more

# Usage

**Parameter Format**: `x.y.z-distribution`
**Parameter Format**: `x.y.z-distribution` or `x.y.z-distribution-fx` (for JavaFX bundled versions)

```shell
# add plugin for vfox
Expand All @@ -21,13 +21,34 @@ vfox install java@17.0.17-tem # Temurin
vfox install java@17.0.17-zulu # Zulu
vfox install java@17-graal # GraalVM (latest 17.x)

# install JavaFX bundled versions (use -fx suffix after distribution)
vfox install java@21.0.5-zulu-fx # Zulu with JavaFX
vfox install java@21.0.5-librca-fx # Liberica with JavaFX

# view all available versions
vfox search java # view all openjdk versions
vfox search java tem # view all temurin versions
vfox search java zulu # view all zulu versions
vfox search java graal # view all graalvm versions
```

## JavaFX Support

Some distributions provide JDK versions bundled with JavaFX. These versions are displayed with the `-fx` suffix after the distribution name in the version list and marked with "JavaFX" in the notes. To install a JavaFX bundled version, add `-fx` after the distribution name:

```shell
# List versions (JavaFX versions will show -fx suffix)
vfox search java zulu
# Example output:
# 21.0.5-zulu
# 21.0.5-zulu-fx # JavaFX
# 17.0.13-zulu
# 17.0.13-zulu-fx # JavaFX

# Install JavaFX bundled version
vfox install java@21.0.5-zulu-fx
```

# Supported JDK Distributions

> Thanks [SDKMAN](https://sdkman.io/jdks)!
Expand Down
23 changes: 22 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# 使用

**参数格式**: x.y.z-distribution
**参数格式**: `x.y.z-distribution` 或 `x.y.z-distribution-fx` (带 JavaFX 的版本)

```shell
# 添加插件
Expand All @@ -18,12 +18,33 @@ vfox add java
vfox install java@x.y.z # 默认使用openjdk
vfox install java@x.y.z-graal # 使用graalvm

# 安装带 JavaFX 的版本 (在发行版名称后添加 -fx 后缀)
vfox install java@21.0.5-zulu-fx # 带 JavaFX 的 Zulu
vfox install java@21.0.5-librca-fx # 带 JavaFX 的 Liberica

# 查看所有可用版本
vfox search java all # 查看所有sdk版本
vfox search java # 查看所有openjdk版本
vfox search java graal # 查看所有graalvm版本
```

## JavaFX 支持

部分发行版提供了捆绑 JavaFX 的 JDK 版本。这些版本在版本列表中会在发行版名称后显示 `-fx` 后缀,并在备注中标注 "JavaFX"。安装带 JavaFX 的版本时,需要在发行版名称后添加 `-fx`:

```shell
# 查看版本列表 (带 JavaFX 的版本会显示 -fx 后缀)
vfox search java zulu
# 示例输出:
# 21.0.5-zulu
# 21.0.5-zulu-fx # JavaFX
# 17.0.13-zulu
# 17.0.13-zulu-fx # JavaFX

# 安装带 JavaFX 的版本
vfox install java@21.0.5-zulu-fx
```

# 支持的JDK发行版

> Thanks [SDKMAN](https://sdkman.io/jdks)!
Expand Down
32 changes: 20 additions & 12 deletions hooks/available.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ local distribution_version_parser = require("distribution_version")
function PLUGIN:Available(ctx)
local query = ctx.args[1] or "open"
local jdks = {}
local distribution = nil

if query == "all" then
for _, distribution in ipairs(distribution_version_parser.distributions) do
local tempJdks = foojay.fetchtJdkList(distribution.name, "")
for _, dist in ipairs(distribution_version_parser.distributions) do
local tempJdks = foojay.fetchtJdkList(dist.name, "")
for _, jdk in ipairs(tempJdks) do
jdk.short = distribution.short_name
jdk.short = dist.short_name
table.insert(jdks, jdk)
end
end
else
local distribution = distribution_version_parser.parse_distribution(query)
distribution = distribution_version_parser.parse_distribution(query)
if not distribution then
error("Unsupported distribution: " .. query)
end
Expand All @@ -29,24 +30,31 @@ function PLUGIN:Available(ctx)
for _, jdk in ipairs(jdks) do
local v = jdk.java_version
local short = jdk.short

-- Add -fx suffix for JavaFX bundled versions (after distribution name)
local fx_suffix = ""
if jdk.javafx_bundled == true then
fx_suffix = "-fx"
end

if query == "all" then
v = v .. "-" .. short
v = v .. "-" .. short .. fx_suffix
elseif query == "open" then
v = v
v = v .. fx_suffix
else
local distribution = distribution_version_parser.parse_distribution(query)
if not distribution then
error("Unsupported distribution: " .. query)
end
v = v .. "-" .. distribution.short_name
v = v .. "-" .. distribution.short_name .. fx_suffix
end

if not seen[v] then
seen[v] = true
-- check if version exists
local note = jdk.term_of_support == "lts" and "LTS" or ""
if jdk.javafx_bundled == true then
note = note == "" and "JavaFX" or note .. ", JavaFX"
end
table.insert(result, {
version = v,
note = jdk.term_of_support == "lts" and "LTS" or ""
note = note
})
end

Expand Down
31 changes: 29 additions & 2 deletions hooks/pre_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,41 @@ function PLUGIN:PreInstall(ctx)
if not jdks or #jdks == 0 then
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]

-- Filter JDKs based on JavaFX requirement
local filtered_jdks = {}
for _, jdk in ipairs(jdks) do
local jdk_has_fx = jdk.javafx_bundled == true
if distribution_version.javafx_bundled == jdk_has_fx then
table.insert(filtered_jdks, jdk)
end
end

if #filtered_jdks == 0 then
local fx_msg = distribution_version.javafx_bundled and " with JavaFX" or " without JavaFX"
error("No JDK found for " .. ctx.version .. fx_msg .. " on " .. RUNTIME.osType .. "/" .. RUNTIME.archType .. ". Please check available versions with 'vfox search java'")
end

local jdk = filtered_jdks[1]
local info = json.decode(httpGet(jdk.links.pkg_info_uri, "Failed to fetch jdk info")).result[1]
-- TODO: checksum
-- local checksum = info.checksum
-- if checksum == "" and info.checksum_uri ~= "" then
-- checksum = httpGet(info.checksum_uri, "Failed to fetch checksum")
-- end
local finalV = distribution_version.distribution.short_name == "open" and jdk.java_version or jdk.java_version .. "-" .. distribution_version.distribution.short_name

-- Build final version string with fx suffix if needed (after distribution name)
local fx_suffix = ""
if jdk.javafx_bundled == true then
fx_suffix = "-fx"
end

local finalV
if distribution_version.distribution.short_name == "open" then
finalV = jdk.java_version .. fx_suffix
else
finalV = jdk.java_version .. "-" .. distribution_version.distribution.short_name .. fx_suffix
end
return {
-- [info.checksum_type] = checksum,
url = info.direct_download_uri,
Expand Down
8 changes: 8 additions & 0 deletions lib/distribution_version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ function distribution_version.parse_version (arg)
local version_parts = strings.split(arg, "-")
local version
local distribution
local javafx_bundled = false

-- Check if the last part is "fx" and remove it, setting javafx_bundled flag
if version_parts[#version_parts] == "fx" then
javafx_bundled = true
table.remove(version_parts)
end

if not version_parts[2] then
-- no parts, check if we got a distribution name without version
Expand Down Expand Up @@ -90,6 +97,7 @@ function distribution_version.parse_version (arg)
return {
version = version,
distribution = distribution,
javafx_bundled = javafx_bundled,
}
end

Expand Down