diff --git a/docs/e2e.md b/docs/e2e.md index 108b1c7..2a7abbc 100644 --- a/docs/e2e.md +++ b/docs/e2e.md @@ -99,10 +99,12 @@ JDK, so `java` can only come from what vfox installs: 5. After `vfox use --global`, the JDK on `PATH` reports the requested `java.version`, the runner's `os.arch` (`amd64` / `aarch64`, which also catches an x64 JDK emulated on Windows ARM64) and the distribution's - `java.vendor`. `JAVA_HOME` (and `GRAALVM_HOME` for GraalVM) holds that - same JDK, `javac` compiles a program that `java` then runs, the module - list carries JavaFX exactly for `-fx` builds, and `vfox current java` - reports the installed version. + `java.vendor`. `JAVA_HOME` holds that same JDK, `javac` compiles a + program that `java` then runs, the module list carries JavaFX exactly for + `-fx` builds, and `vfox current java` reports the installed version. A + `GRAALVM_HOME` set beforehand keeps its value, as users point it at a + GraalVM of their own; for GraalVM, the plugin used to replace it with + the JDK in use. 6. `PreUse` maps the spellings users type to the installed version without another download: the bare major (`java@21`, left to vfox core's fuzzy matching), the spec the JDK was installed with (`java@21.0.8-tem`, whose @@ -124,7 +126,7 @@ The default matrix runs every distribution against both vfox channels | `tem` | 21.0.8 | the common path (tar.gz on Linux, zip on Windows) | ✓ | ✓ | | `librca-fx` | 25.0.4 | JavaFX bundled builds (`-fx`) | ✓ | ✓ | | `jb` | 21.0.5 | the tar.gz path on Windows, which has no zip for it | ✓ | ✓ | -| `graalce` | 25.0.2 | `GRAALVM_HOME` | ✓ | | +| `graalce` | 25.0.2 | a `GRAALVM_HOME` set beforehand keeps its value | ✓ | | Every pinned release is published through Foojay for each platform its row runs on. OpenJDK and GraalVM Community ship no `windows-aarch64` build, so diff --git a/hooks/env_keys.lua b/hooks/env_keys.lua index 1f19a26..820d1bb 100644 --- a/hooks/env_keys.lua +++ b/hooks/env_keys.lua @@ -12,15 +12,16 @@ -- See the License for the specific language governing permissions and -- limitations under the License. -local strings = require("vfox.strings") --- Each SDK may have different environment variable configurations. --- This allows plugins to define custom environment variables (including PATH settings) --- Note: Be sure to distinguish between environment variable settings for different platforms! function PLUGIN:EnvKeys(ctx) local mainSdkInfo = ctx.main local path = mainSdkInfo.path - local shortname = strings.split(mainSdkInfo.version, "-")[2] - local envTable = { + -- No GRAALVM_HOME, even for GraalVM: users point it at a GraalVM of + -- their own, apart from JAVA_HOME, and GraalVM's Native Image build + -- plugins fall back to JAVA_HOME when it is unset. + return { { key = "JAVA_HOME", value = path, @@ -30,11 +31,4 @@ function PLUGIN:EnvKeys(ctx) value = path .. "/bin", }, } - if shortname == "graal" or shortname == "graalce" then - table.insert(envTable, { - key = "GRAALVM_HOME", - value = path, - }) - end - return envTable end diff --git a/tests/e2e/common/common.go b/tests/e2e/common/common.go index 91f4bb6..41afd0c 100644 --- a/tests/e2e/common/common.go +++ b/tests/e2e/common/common.go @@ -54,7 +54,8 @@ var DefaultVersions = map[string]string{ // installs from a tar.gz (vfox-java#58), and searching must list it too // (vfox-java#72). "jb": "21.0.5", - // GraalVM Community: the GRAALVM_HOME branch of hooks/env_keys.lua. + // GraalVM Community: vfox must leave GRAALVM_HOME alone even for + // GraalVM (vfox-java#27). "graalce": "25.0.2", } @@ -374,16 +375,6 @@ func Vendor(distribution string) (string, bool) { return d.vendor, ok } -// SetsGraalVMHome mirrors hooks/env_keys.lua: GraalVM distributions also -// export GRAALVM_HOME. -func SetsGraalVMHome(distribution string) bool { - switch Base(distribution) { - case "graal", "graalce": - return true - } - return false -} - // SearchArgs renders the `vfox search java` arguments listing the // distribution: none for OpenJDK (Available's default query), else the // short name, which lists the JavaFX builds too. diff --git a/tests/e2e/common/common_test.go b/tests/e2e/common/common_test.go index e42a1fb..d9edc2a 100644 --- a/tests/e2e/common/common_test.go +++ b/tests/e2e/common/common_test.go @@ -287,9 +287,6 @@ func TestDistributionFacts(t *testing.T) { if _, ok := Vendor("zulu"); ok { t.Error("Vendor(zulu) is known, want unknown") } - if !SetsGraalVMHome("graalce") || SetsGraalVMHome("tem") { - t.Error("SetsGraalVMHome must follow hooks/env_keys.lua") - } if !JavaFX("librca-fx") || JavaFX("tem") || Base("librca-fx") != "librca" { t.Error("JavaFX/Base mishandle the -fx suffix") } diff --git a/tests/e2e/linux/verify.go b/tests/e2e/linux/verify.go index 79f6ed3..1563a07 100644 --- a/tests/e2e/linux/verify.go +++ b/tests/e2e/linux/verify.go @@ -34,6 +34,10 @@ import ( // to stderr. const showSettings = "java -XshowSettings:properties -version 2>&1" +// userGraalVMHome is a GRAALVM_HOME set before activation: users point it at +// a GraalVM of their own, apart from JAVA_HOME. +const userGraalVMHome = "/opt/graalvm-for-native-image" + // verifySearch checks `vfox search java` (the plugin's Available hook) lists // the installed version under the name PreInstall gave it, marked // installed, with the JavaFX note for -fx builds. @@ -111,9 +115,9 @@ func legacyJava(ctx context.Context, t *testing.T, ctr tc.Container, identifier // verifyToolchain runs java and javac through the activate hook and checks // the JDK on PATH is the requested release, distribution, architecture and -// JavaFX flavour; that JAVA_HOME (and GRAALVM_HOME for GraalVM) resolves to -// that same JDK; that it compiles and runs a program; and that `vfox -// current` reports the installed version. +// JavaFX flavour; that JAVA_HOME resolves to that same JDK, while a +// GRAALVM_HOME set beforehand keeps its value; that it compiles and runs a +// program; and that `vfox current` reports the installed version. func verifyToolchain(ctx context.Context, t *testing.T, ctr tc.Container, distribution, version, installed, arch string) { t.Helper() out := execRetry(ctx, t, ctr, "java on PATH", activated(showSettings)) @@ -123,15 +127,13 @@ func verifyToolchain(ctx context.Context, t *testing.T, ctr tc.Container, distri // symlinks, while JAVA_HOME names vfox's link (~/.vfox/sdks/java). viaHome := common.JavaProperties(execOK(ctx, t, ctr, activated(`"$JAVA_HOME"/bin/`+showSettings))) require.Equal(t, props["java.home"], viaHome["java.home"], "$JAVA_HOME/bin/java must be the java on PATH") - homes := []string{"JAVA_HOME"} - if common.SetsGraalVMHome(distribution) { - homes = append(homes, "GRAALVM_HOME") - } - for _, name := range homes { - home := strings.TrimSpace(execOK(ctx, t, ctr, activated(fmt.Sprintf( - `test -n "$%s" && readlink --canonicalize "$%s"`, name, name)))) - require.Equalf(t, props["java.home"], home, "%s must resolve to the JDK root", name) - } + home := strings.TrimSpace(execOK(ctx, t, ctr, activated(`test -n "$JAVA_HOME" && readlink --canonicalize "$JAVA_HOME"`))) + require.Equal(t, props["java.home"], home, "JAVA_HOME must resolve to the JDK root") + // The plugin set GRAALVM_HOME to JAVA_HOME for GraalVM, replacing the + // user's (vfox-java#27). + graalvmHome := strings.TrimSpace(execOK(ctx, t, ctr, + "export GRAALVM_HOME="+shQuote(userGraalVMHome)+"; "+activated(`echo "$GRAALVM_HOME"`))) + require.Equal(t, userGraalVMHome, graalvmHome, "a GRAALVM_HOME set beforehand must keep its value") javac := strings.TrimSpace(execOK(ctx, t, ctr, activated("javac -version 2>&1"))) require.Equal(t, "javac "+version, javac, "javac -version") diff --git a/tests/e2e/windows/verify.go b/tests/e2e/windows/verify.go index 759ce7a..c6f9b6f 100644 --- a/tests/e2e/windows/verify.go +++ b/tests/e2e/windows/verify.go @@ -35,6 +35,10 @@ import ( // `2>&1` would instead wrap every line in an ErrorRecord. const showSettings = "-XshowSettings:properties -version" +// userGraalVMHome is a GRAALVM_HOME set before activation: users point it at +// a GraalVM of their own, apart from JAVA_HOME. +const userGraalVMHome = `C:\graalvm-for-native-image` + // verifySearch checks `vfox search java` (the plugin's Available hook) lists // the installed version under the name PreInstall gave it, marked // installed, with the JavaFX note for -fx builds. That includes releases @@ -124,24 +128,23 @@ func legacyJava(ctx context.Context, t *testing.T, ctr tc.Container, box slotBox // verifyToolchain runs java and javac through the activate + env hooks and // checks the JDK on PATH is the requested release, distribution, -// architecture and JavaFX flavour; that JAVA_HOME (and GRAALVM_HOME for -// GraalVM) holds that same JDK; that it compiles and runs a program; and -// that `vfox current` reports the installed version. +// architecture and JavaFX flavour; that JAVA_HOME holds that same JDK, +// while a GRAALVM_HOME set beforehand keeps its value; that it compiles and +// runs a program; and that `vfox current` reports the installed version. func verifyToolchain(ctx context.Context, t *testing.T, ctr tc.Container, box slotBox, activation, distribution, version, installed, arch string) { t.Helper() out := execRetry(ctx, t, ctr, "java on PATH", activatedEnv(activation, "java "+showSettings), box.vars...) props := common.CheckJava(t, out, distribution, version, arch, "java on PATH") require.NotEmpty(t, props["java.home"], "java on PATH: java.home") - homes := []string{"JAVA_HOME"} - if common.SetsGraalVMHome(distribution) { - homes = append(homes, "GRAALVM_HOME") - } - for _, name := range homes { - viaHome := common.JavaProperties(execOK(ctx, t, ctr, activatedEnv(activation, fmt.Sprintf( - `& (Join-Path $env:%s 'bin\java.exe') %s`, name, showSettings)), box.vars...)) - require.Equalf(t, props["java.home"], viaHome["java.home"], "%s\\bin\\java.exe must be the java on PATH", name) - } + viaHome := common.JavaProperties(execOK(ctx, t, ctr, activatedEnv(activation, + `& (Join-Path $env:JAVA_HOME 'bin\java.exe') `+showSettings), box.vars...)) + require.Equal(t, props["java.home"], viaHome["java.home"], `JAVA_HOME\bin\java.exe must be the java on PATH`) + // The plugin set GRAALVM_HOME to JAVA_HOME for GraalVM, replacing the + // user's (vfox-java#27). + graalvmHome := strings.TrimSpace(execOK(ctx, t, ctr, + "$env:GRAALVM_HOME = "+pwshQuote(userGraalVMHome)+"\r\n"+activatedEnv(activation, "$env:GRAALVM_HOME"), box.vars...)) + require.Equal(t, userGraalVMHome, graalvmHome, "a GRAALVM_HOME set beforehand must keep its value") javac := strings.TrimSpace(execOK(ctx, t, ctr, activatedEnv(activation, "javac -version"), box.vars...)) require.Equal(t, "javac "+version, javac, "javac -version")