Skip to content

Commit 57e0af6

Browse files
authored
feat: add VFOX_JAVA_GITHUB_MIRROR to download JDKs from GitHub through a mirror such as gh-proxy.org (#116)
1 parent 97eb83d commit 57e0af6

25 files changed

Lines changed: 532 additions & 18 deletions

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/pre_use_test.lua
4141
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/parse_legacy_file_test.lua
4242
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/loongnix_test.lua
43+
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/github_mirror_test.lua
4344
- name: Test macOS Java home normalization
4445
run: go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/post_install_test.lua
4546
macos-layout:

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ Zulu, Liberica, Liberica NIK and Corretto (Java 8 only) have builds with JavaFX
8686

8787
vfox reads the `java=` line of SDKMAN's `.sdkmanrc` through this plugin and selects a JDK that is already installed. See [docs/sdkmanrc.md](docs/sdkmanrc.md) for details.
8888

89+
## GitHub mirror
90+
91+
Most distributions download from GitHub. If that is slow where you are, `export VFOX_JAVA_GITHUB_MIRROR=https://gh-proxy.org/` sends these downloads through a mirror. See [docs/mirror.md](docs/mirror.md) for details.
92+
93+
Unreleased: release 0.6.2 has no mirror setting.
94+
8995
## Querying Foojay
9096

9197
To see which JDKs exist for your platform, ask Foojay yourself. [docs/foojay.md](docs/foojay.md) has the Swagger UI and the commands.

‎README_CN.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ Zulu、Liberica、Liberica NIK 和 Corretto(只有 Java 8)提供内置 JavaF
8686

8787
vfox 通过这个插件读取 SDKMAN 的 `.sdkmanrc` 里的 `java=` 一行,并选中已经安装的 JDK。详见 [docs/zh-CN/sdkmanrc.md](docs/zh-CN/sdkmanrc.md)。
8888

89+
## GitHub 镜像
90+
91+
大多数发行版从 GitHub 下载。如果你那里下载很慢,执行 `export VFOX_JAVA_GITHUB_MIRROR=https://gh-proxy.org/`,这些下载就会经过镜像。详见 [docs/zh-CN/mirror.md](docs/zh-CN/mirror.md)。
92+
93+
未发布:0.6.2 没有镜像设置。
94+
8995
## 查询 Foojay
9096

9197
想知道你的平台上有哪些 JDK,可以自己去问 Foojay。[docs/zh-CN/foojay.md](docs/zh-CN/foojay.md) 里有 Swagger UI 和查询命令。

‎docs/changes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ What changed in each release, as a user notices it. GitHub's release pages list
1414
- A 25.0 name that release 0.6.2 installed after Foojay's change can hold a feature release: `25.0.4.1-graal` is GraalVM 25.4.4.1.1, `25.0.4-graal` is 25.2.4 and `25.0.3-graal` is 25.1.3, and the same goes for these names with `-graalce`. vfox does not install a name it already has, so if the GraalVM version that `java -version` prints differs from the name, `vfox uninstall` it and install it again. `25.0.4.1-graalce`, `25.0.4-graalce` and `25.0.3-graalce` no longer install at all, as GraalVM Community's 25.0 line ends with `25.0.2`.
1515
- A bare major such as `java@21-tem` asks Foojay what `vfox search` asks and installs the newest release of the major that the search lists. Release 0.6.2 has Foojay pick it (`latest=available`), and as Foojay caches each question on its own, for half an hour after a release that can install a build `vfox search` does not list yet. Dragonwell 11 on Windows x64 and on Linux x64 with musl now installs the Extended build of 11.0.32, as `java@11.0.32-albba` does, where 0.6.2 installs the Standard one for `java@11-albba` ([#113](https://github.com/version-fox/vfox-java/issues/113)).
1616
- `vfox use java@25-graal` and a `.sdkmanrc` holding `java=25-graal` select the newest installed build of Oracle GraalVM's 25.0 line, the build `vfox install java@25-graal` installs. Release 0.6.2 selects the newest installed release of 25, which is a monthly feature release as soon as one is installed: with `25.0.5-graal` and `25.4.4.1.1-graal` installed, `vfox use java@25-graal` selected the second, while `vfox install java@25-graal` reported the first as installed. A feature release is selected by its full version (`java@25.4.4.1.1-graal`), or by the bare major where nothing else of 25 is installed. A `.sdkmanrc` naming a 25.0 release that is not installed, such as `java=25.0.3-graal`, falls back the same way. `java=25.4.4+1-graal`, which names a feature release as SDKMAN does, still takes the newest installed release of 25. GraalVM Community is not affected, as its feature releases are what it still ships ([#110](https://github.com/version-fox/vfox-java/issues/110)).
17+
- `VFOX_JAVA_GITHUB_MIRROR` sends the downloads from GitHub through a mirror, as in `export VFOX_JAVA_GITHUB_MIRROR=https://gh-proxy.org/`. Foojay links the JDKs of most distributions to GitHub Releases (Temurin, Liberica and GraalVM Community among them). github.com is slow or out of reach in some regions. The value is a prefix that goes in front of the GitHub URL. Downloads from other hosts do not change. See [mirror.md](mirror.md).
1718

1819
## 0.6.2 (2026-10-18)
1920

‎docs/development.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ hooks/pre_use.lua vfox use: map what was typed to an installed nam
1414
hooks/parse_legacy_file.lua .sdkmanrc
1515
lib/distribution_version.lua distribution names, parsing of specs, GraalVM feature releases
1616
lib/foojay.lua the Foojay request, and fixes to what it answers
17+
lib/github_mirror.lua the mirror of the downloads from GitHub
1718
lib/installed_version.lua matching against installed names
1819
lib/loongnix.lua the Loongnix archive
1920
tests/*_test.lua offline hook tests
@@ -37,6 +38,7 @@ vfox loads `metadata.lua`, calls a hook when a command needs it, and puts `PLUGI
3738
A few contracts that cost time to find:
3839

3940
- `PreInstall` returns `url`, `version` and `note`. `version` becomes the name of the install, which is why it carries the build number. The package's checksum is not passed on yet (`TODO: checksum` in `hooks/pre_install.lua`), and vfox prints a warning for that.
41+
- For a package from Foojay, `url` is its `direct_download_uri`, behind `$VFOX_JAVA_GITHUB_MIRROR` when it is on GitHub (`lib/github_mirror.lua`, [mirror.md](mirror.md)). vfox downloads from `http://` and `https://` addresses and takes anything else for a file on disk. It names the download after the last part of the URL's path and unpacks it by the extension of that name, which a prefix in front of the URL does not change.
4042
- `PreUse` returns a table or `nil`. For a bare major it returns `nil` so that vfox matches it itself. vfox 1.0.13 and later reject a bare string such as `""`.
4143
- `ParseLegacyFile` calls `ctx.getInstalledVersions()` with no argument. vfox 1.x binds it as a Go `func() []string` and rejects the extra argument that `ctx:getInstalledVersions()` adds. vfox ignores errors from this hook, so the failure is silent.
4244
- vfox hands over the installed versions sorted as strings, descending: `21.0.8+9-tem`, `21.0.12+8-tem`, `21.0.1+12-tem`. The first one that starts with a release is not the right one, so `lib/installed_version.lua` compares numbers one by one.
@@ -71,10 +73,11 @@ go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/pre_install_test.lua
7173
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/pre_use_test.lua
7274
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/parse_legacy_file_test.lua
7375
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/loongnix_test.lua
76+
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/github_mirror_test.lua
7477
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/post_install_test.lua
7578
```
7679

77-
Run them from the repository root. All five load `tests/support.lua`, which stubs `vfox.strings`, and `tests/pre_install_test.lua` and `tests/loongnix_test.lua` stub `http` and `json` themselves. `tests/pre_install_test.lua` keeps Foojay's answers in a table at the top, keyed by `<distribution> [<version>]`, with `windows` or `macos` in front for those systems. Add the answer a new case needs there, and note the day you observed it. Lint, license headers and the container tests are in [e2e.md](e2e.md#local-checks).
80+
Run them from the repository root. All six load `tests/support.lua`, which stubs `vfox.strings`, and `tests/pre_install_test.lua` and `tests/loongnix_test.lua` stub `http` and `json` themselves. `tests/pre_install_test.lua` keeps Foojay's answers in a table at the top, keyed by `<distribution> [<version>]`, with `windows` or `macos` in front for those systems. Add the answer a new case needs there, and note the day you observed it. Lint, license headers and the container tests are in [e2e.md](e2e.md#local-checks).
7881

7982
To call a single hook against the real Foojay, vfox 1.0.13 and later has `vfox plugin run`. It does not register the plugin, and `--os` and `--arch` answer for another platform:
8083

‎docs/e2e.md‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ JDK, so `java` can only come from what vfox installs:
8181
(`<version>+99`, e.g. `21.0.8+99-tem`), proving the lookup keeps the
8282
build number: Foojay reads an unencoded `+` as a space and drops the
8383
build, and the release's newest build would install instead.
84+
85+
On the Temurin rows an install through a mirror that does not exist must
86+
fail too. With `VFOX_JAVA_GITHUB_MIRROR=https://invalid.example.invalid`
87+
the mirror goes in front of Temurin's GitHub URL, so `vfox install` fails on
88+
the download, and its error must name the URL it asked for: the mirror, a
89+
slash and the GitHub URL. Before the plugin read the variable, it downloaded
90+
the JDK from github.com and the install succeeded. Nothing is downloaded,
91+
and no mirror that works is run.
8492
3. On the GraalVM Community rows, Oracle GraalVM's bare major `25-graal`
8593
installs the newest build of its 25.0 line (`25.0.5-graal` on
8694
2026-10-20), the line Oracle's own `25/latest` download follows, not one
@@ -204,13 +212,13 @@ JDK, so `java` can only come from what vfox installs:
204212
The default matrix runs every distribution against both vfox channels
205213
(`latest`, `main`):
206214

207-
| Distribution | Release | Covers | amd64 | arm64 |
208-
| ------------ | ------- | ---------------------------------------------------------------------------------------------- | ----- | ----- |
209-
| `open` | 25.0.2 | the default distribution, versions without a suffix | ✓ | |
210-
| `tem` | 21.0.8 | the common path (tar.gz on Linux, zip on Windows); the name and number checks of items 4 and 6 | ✓ | ✓ |
211-
| `librca-fx` | 25.0.4 | JavaFX bundled builds (`-fx`) | ✓ | ✓ |
212-
| `jb` | 21.0.5 | the tar.gz path on Windows, which has no zip for it | ✓ | ✓ |
213-
| `graalce` | 25.0.2 | a `GRAALVM_HOME` set beforehand keeps its value; Oracle GraalVM's `25-graal` | ✓ | |
215+
| Distribution | Release | Covers | amd64 | arm64 |
216+
| ------------ | ------- | --------------------------------------------------------------------------------------------------------- | ----- | ----- |
217+
| `open` | 25.0.2 | the default distribution, versions without a suffix | ✓ | |
218+
| `tem` | 21.0.8 | the common path (tar.gz on Linux, zip on Windows); the mirror, name and number checks of items 2, 4 and 6 | ✓ | ✓ |
219+
| `librca-fx` | 25.0.4 | JavaFX bundled builds (`-fx`) | ✓ | ✓ |
220+
| `jb` | 21.0.5 | the tar.gz path on Windows, which has no zip for it | ✓ | ✓ |
221+
| `graalce` | 25.0.2 | a `GRAALVM_HOME` set beforehand keeps its value; Oracle GraalVM's `25-graal` | ✓ | |
214222

215223
Every pinned release is published through Foojay for each platform its row
216224
runs on. OpenJDK and GraalVM Community ship no `windows-aarch64` build, so
@@ -388,6 +396,7 @@ go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/pre_install_test.lua
388396
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/pre_use_test.lua
389397
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/parse_legacy_file_test.lua
390398
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/loongnix_test.lua
399+
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/github_mirror_test.lua
391400
go run github.com/yuin/gopher-lua/cmd/glua@v1.1.1 tests/post_install_test.lua
392401
```
393402

‎docs/foojay.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ For a bare major such as `21` the answer lists every release, and the plugin tak
3535

3636
A bare major asks what searching asks so that installing sees the builds `vfox search` lists. Foojay's answers are cached per question, and two questions can get answers of different ages: half an hour after Oracle GraalVM 25.0.5 reached Foojay on 2026-10-20, GitHub's runners got it from a lookup with `distribution_version=25` but not from a search, and `vfox install java@25-graal` took a build that `vfox search java graal` did not list ([#113](https://github.com/version-fox/vfox-java/issues/113)).
3737

38-
The answer is a list of packages. The plugin names a release after `java_version` (Mandrel and Liberica NIK after `distribution_version`, Oracle GraalVM and GraalVM Community after GraalVM's own version), adds `-fx` where `javafx_bundled` is true, marks it LTS where `term_of_support` is `lts`, and prefers a `zip` over a `tar.gz` of the same version on Windows. It leaves out the JREs, installer bundles and RHEL 6 builds that Foojay lists among OJDKBuild's Windows JDKs, and the JDK 11 builds of Gluon GraalVM's 22.x releases, see [distributions.md](distributions.md). For the install it then fetches the package's `links.pkg_info_uri` and downloads its `direct_download_uri`, which is a vendor's own server (GitHub Releases for Temurin). That record also holds a `checksum`. The plugin does not pass it on, so vfox prints `WARNING: Checksum is not provided, skip verify...` and does not verify the download.
38+
The answer is a list of packages. The plugin names a release after `java_version` (Mandrel and Liberica NIK after `distribution_version`, Oracle GraalVM and GraalVM Community after GraalVM's own version), adds `-fx` where `javafx_bundled` is true, marks it LTS where `term_of_support` is `lts`, and prefers a `zip` over a `tar.gz` of the same version on Windows. It leaves out the JREs, installer bundles and RHEL 6 builds that Foojay lists among OJDKBuild's Windows JDKs, and the JDK 11 builds of Gluon GraalVM's 22.x releases, see [distributions.md](distributions.md). For the install it then fetches the package's `links.pkg_info_uri` and downloads its `direct_download_uri`, which is a vendor's own server (GitHub Releases for Temurin). That record also holds a `checksum`. The plugin does not pass it on, so vfox prints `WARNING: Checksum is not provided, skip verify...` and does not verify the download. Unreleased: a download from GitHub can go through a mirror, see [mirror.md](mirror.md).
3939

4040
`vfox search` differs from the raw list in a few ways. It lists a name once where Foojay has two records for it, and it leaves the LTS note off GraalVM's feature releases (see [distributions.md](distributions.md#behavior-of-oracle-graalvm-and-graalvm-community)). It only lists GA releases.
4141

‎docs/mirror.md‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# GitHub mirror
2+
3+
[中文](zh-CN/mirror.md) | [English](mirror.md)
4+
5+
Unreleased: release 0.6.2 has no mirror setting.
6+
7+
Foojay links the JDKs of most distributions to GitHub Releases, so `vfox install java@21-tem` downloads from `github.com`. If github.com is slow or unreachable where you are, set `VFOX_JAVA_GITHUB_MIRROR` and the plugin sends these downloads through a GitHub mirror.
8+
9+
The value is a URL prefix. The plugin puts it in front of the GitHub URL, and adds a `/` if the value does not end in one. For Temurin 21.0.8 on Linux x64:
10+
11+
| `VFOX_JAVA_GITHUB_MIRROR` | vfox downloads |
12+
| --- | --- |
13+
| not set | `https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8%2B9/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz` |
14+
| `https://gh-proxy.org/` | `https://gh-proxy.org/https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8%2B9/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz` |
15+
16+
[gh-proxy](https://gh-proxy.org/) takes URLs in this form, and so does any service that takes the GitHub URL after its own address. The plugin does not run any of them and cannot vouch for them. The value must start with `http://` or `https://`. vfox takes any other address for a file on disk, so a download from GitHub stops with `VFOX_JAVA_GITHUB_MIRROR must start with http:// or https://` instead.
17+
18+
## Set it
19+
20+
In bash or zsh, for the current shell:
21+
22+
```bash
23+
export VFOX_JAVA_GITHUB_MIRROR=https://gh-proxy.org/
24+
```
25+
26+
Put the same line in `~/.bashrc` or `~/.zshrc` to keep it. In PowerShell:
27+
28+
```powershell
29+
$env:VFOX_JAVA_GITHUB_MIRROR = "https://gh-proxy.org/"
30+
```
31+
32+
To set it for every terminal opened afterwards:
33+
34+
```powershell
35+
[Environment]::SetEnvironmentVariable('VFOX_JAVA_GITHUB_MIRROR', 'https://gh-proxy.org/', 'User')
36+
```
37+
38+
Then install as usual, `vfox install java@21-tem`. To go back to github.com, unset the variable.
39+
40+
## What goes through the mirror
41+
42+
Only downloads from `https://github.com/`. A JDK on any other host downloads from there as before, and the requests to Foojay do not change.
43+
44+
Where Foojay links each distribution (2026-10-21):
45+
46+
| Short names | Download from |
47+
| --- | --- |
48+
| `tem`, `librca`, `sem`, `semcrt`, `sapmchn`, `kona`, `albba`, `mandrel`, `trava`, `adpt`, `adptj9`, `eliya`, `ojdkbld`, `gln`, `grl8`, `grl11`, `grl16`, `grl17`, `grl19` | GitHub |
49+
| `graalce` | GitHub, except the monthly feature releases that `java@25-graalce` installs, which come from Oracle's GraalVM Download Service. `java@25.4.4.1-graalce` is the same file from GitHub |
50+
| `nik` | GitHub for the newer releases, BellSoft's server for the older ones |
51+
| `open` | jdk.java.net, except JDK 8 and most 11.x builds, which come from GitHub |
52+
| `zulu`, `amzn`, `ms`, `oracle`, `graal`, `jb`, `bsg`, `opnlgc`, `rdht` | the vendor's server or a CDN, not GitHub |
53+
54+
Loongnix (`lnxabi1`, `lnxabi2`) downloads from ftp.loongnix.cn and is not mirrored.
55+
56+
To see where one release downloads from, ask Foojay for its package and read `direct_download_uri`. It is mirrored if it starts with `https://github.com/`. [foojay.md](foojay.md) has the queries for other platforms.
57+
58+
```bash
59+
curl -s 'https://api.foojay.io/disco/v3.0/packages/jdks?distribution=temurin&version=21.0.8&architecture=amd64&operating_system=linux&lib_c_type=glibc&archive_type=tar.gz&directly_downloadable=true' \
60+
| jq -r '.result[0].links.pkg_info_uri' | xargs curl -s | jq -r '.result[0].direct_download_uri'
61+
```
62+
63+
```
64+
https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.8%2B9/OpenJDK21U-jdk_x64_linux_hotspot_21.0.8_9.tar.gz
65+
```
66+
67+
## Notes
68+
69+
- The plugin gives vfox no checksum, so vfox does not verify the download (`WARNING: Checksum is not provided, skip verify...`, see [foojay.md](foojay.md#what-the-plugin-asks)). Through a mirror, the archive is whatever the mirror serves. Use one you trust.
70+
- The variable only changes where `vfox install` downloads a JDK from. `vfox add java` does not use it. For a proxy that covers all of vfox, see [Network](troubleshooting.md#network).

0 commit comments

Comments
 (0)