Skip to content

Commit 8021721

Browse files
authored
fix: select early-access builds that .sdkmanrc names as vfox list java shows them (#96)
1 parent 3b38e44 commit 8021721

5 files changed

Lines changed: 52 additions & 26 deletions

File tree

‎docs/e2e.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ JDK, so `java` can only come from what vfox installs:
9393
OpenJDK's (`28.0.0.0+ea.20-open`), must select that build:
9494
`java=21.0.0.0+ea.1-tem` selects `21-ea+1-tem`, not the release, which
9595
`ParseLegacyFile` took while it understood only SDKMAN's older
96-
`21.ea.1-tem`. jdk.java.net removes each early-access build within weeks,
97-
so that install is faked: its `bin` holds a stand-in `java` that only
98-
prints the name. On Windows the file is written with CRLF line endings.
96+
`21.ea.1-tem`. So must the installed name itself (`java=21-ea+1-tem`),
97+
for which `ParseLegacyFile`, unable to parse it, selected nothing, while
98+
`vfox use` selects it. jdk.java.net removes each early-access build within
99+
weeks, so that install is faked: its `bin` holds a stand-in `java` that
100+
only prints the name. On Windows the file is written with CRLF line
101+
endings.
99102
5. After `vfox use --global`, the JDK on `PATH` reports the requested
100103
`java.version`, the runner's `os.arch` (`amd64` / `aarch64`, which also
101104
catches an x64 JDK emulated on Windows ARM64) and the distribution's

‎hooks/parse_legacy_file.lua‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function PLUGIN:ParseLegacyFile(ctx)
5454

5555
for line in io.lines(filepath) do
5656
if strings.has_prefix(line, "java=") then
57-
javaVersion = plugin_spelling(strings.trim_prefix(line, "java="))
57+
javaVersion = strings.trim_prefix(line, "java=")
5858
break
5959
end
6060
end
@@ -63,7 +63,23 @@ function PLUGIN:ParseLegacyFile(ctx)
6363
return {}
6464
end
6565

66-
local distributionVersion = distribution_version_parser.parse_version(javaVersion)
66+
--- Get the list of versions of the current plugin installed
67+
--- (a plain call: vfox 1.x rejects the extra ctx argument of ctx:...).
68+
--- vfox sorts it as strings, descending (21.0.8+9-tem, 21.0.12+8-tem,
69+
--- 21.0.1+12-tem), so the first match is not the one to take.
70+
local installed = {}
71+
for _, v in ipairs(ctx.getInstalledVersions()) do
72+
installed[v] = true
73+
end
74+
75+
--- An installed version written as vfox lists it selects itself, as in
76+
--- vfox use, even one that parse_version cannot read: an early-access
77+
--- build (28-ea+19, 28-ea+18-zulu).
78+
if installed[javaVersion] then
79+
return { version = javaVersion }
80+
end
81+
82+
local distributionVersion = distribution_version_parser.parse_version(plugin_spelling(javaVersion))
6783
if not distributionVersion then
6884
return {}
6985
end
@@ -82,15 +98,6 @@ function PLUGIN:ParseLegacyFile(ctx)
8298
--- JavaFX builds: 21.0.8+9-tem, 21.0.12+7-zulu-fx, 25.0.2+10.
8399
local suffix = (vendor == "open" and "" or "-" .. vendor) .. (distributionVersion.javafx_bundled and "-fx" or "")
84100

85-
--- Get the list of versions of the current plugin installed
86-
--- (a plain call: vfox 1.x rejects the extra ctx argument of ctx:...).
87-
--- vfox sorts it as strings, descending (21.0.8+9-tem, 21.0.12+8-tem,
88-
--- 21.0.1+12-tem), so the first match is not the one to take.
89-
local installed = {}
90-
for _, v in ipairs(ctx.getInstalledVersions()) do
91-
installed[v] = true
92-
end
93-
94101
--- The version itself (21.0.5+63130-jb), else the release itself or its
95102
--- newest build, as SDKMAN's build numbers count its own rebuilds
96103
--- (21.0.12+1.1-tem), else the newest installed release of the major

‎tests/e2e/linux/verify.go‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ func verifySearch(ctx context.Context, t *testing.T, ctr tc.Container, distribut
6262
// itself (e.g. java=21.0.8+9-tem), while vfox lists an empty install of
6363
// another release first (see common.Decoy). SDKMAN's identifier of an
6464
// early-access build (e.g. java=21.0.0.0+ea.1-tem) must then select a faked
65-
// install of that build (see common.EarlyAccess), not the release. It runs
66-
// before any `vfox use`, so java can only come from the legacy file.
65+
// install of that build (see common.EarlyAccess), not the release, and so
66+
// must its installed name (e.g. java=21-ea+1-tem). It runs before any
67+
// `vfox use`, so java can only come from the legacy file.
6768
func verifyLegacyFile(ctx context.Context, t *testing.T, ctr tc.Container, distribution, version, installed, arch string) {
6869
t.Helper()
6970
// vfox counts a version as installed once its directory holds
@@ -93,10 +94,13 @@ func verifyLegacyFile(ctx context.Context, t *testing.T, ctr tc.Container, distr
9394
bin := eaDir + "/" + shQuote("java-"+ea) + "/bin"
9495
execOK(ctx, t, ctr, fmt.Sprintf("mkdir --parents %s && printf '%%s' %s > %s/java && chmod +x %s/java",
9596
bin, shQuote("#!/bin/sh\necho "+shQuote(ea)+"\n"), bin, bin))
96-
identifier := common.EarlyAccessIdentifier(distribution, version)
97-
out := legacyJava(ctx, t, ctr, identifier)
98-
require.Containsf(t, out, ea, ".sdkmanrc java=%s must select %s, not %s", identifier, ea, installed)
99-
t.Logf("PASS .sdkmanrc java=%s selects %s, not %s", identifier, ea, installed)
97+
// ParseLegacyFile could not parse the installed name, so it selected
98+
// nothing for it, while `vfox use` selects it (vfox-java#91).
99+
for _, identifier := range []string{common.EarlyAccessIdentifier(distribution, version), ea} {
100+
out := legacyJava(ctx, t, ctr, identifier)
101+
require.Containsf(t, out, ea, ".sdkmanrc java=%s must select %s, not %s", identifier, ea, installed)
102+
t.Logf("PASS .sdkmanrc java=%s selects %s, not %s", identifier, ea, installed)
103+
}
100104
execOK(ctx, t, ctr, "rm --recursive "+eaDir)
101105
}
102106

‎tests/e2e/windows/verify.go‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ func verifySearch(ctx context.Context, t *testing.T, ctr tc.Container, box slotB
6565
// endings, while vfox lists an empty install of another release first (see
6666
// common.Decoy). SDKMAN's identifier of an early-access build (e.g.
6767
// java=21.0.0.0+ea.1-tem) must then select a faked install of that build
68-
// (see common.EarlyAccess), not the release. It runs before any `vfox use`,
69-
// so java can only come from the legacy file.
68+
// (see common.EarlyAccess), not the release, and so must its installed name
69+
// (e.g. java=21-ea+1-tem). It runs before any `vfox use`, so java can only
70+
// come from the legacy file.
7071
func verifyLegacyFile(ctx context.Context, t *testing.T, ctr tc.Container, box slotBox, distribution, version, installed, arch string) {
7172
t.Helper()
7273
// vfox counts a version as installed once its directory holds
@@ -98,10 +99,13 @@ func verifyLegacyFile(ctx context.Context, t *testing.T, ctr tc.Container, box s
9899
"$bin = Join-Path %s %s; New-Item -ItemType Directory -Force -Path $bin | Out-Null; "+
99100
"Set-Content -Path (Join-Path $bin 'java.cmd') -Value %s",
100101
eaDir, pwshQuote(`java-`+ea+`\bin`), pwshQuote("@echo "+ea)), box.vars...)
101-
identifier := common.EarlyAccessIdentifier(distribution, version)
102-
out := legacyJava(ctx, t, ctr, box, identifier)
103-
require.Containsf(t, out, ea, ".sdkmanrc java=%s must select %s, not %s", identifier, ea, installed)
104-
t.Logf("PASS .sdkmanrc java=%s selects %s, not %s", identifier, ea, installed)
102+
// ParseLegacyFile could not parse the installed name, so it selected
103+
// nothing for it, while `vfox use` selects it (vfox-java#91).
104+
for _, identifier := range []string{common.EarlyAccessIdentifier(distribution, version), ea} {
105+
out := legacyJava(ctx, t, ctr, box, identifier)
106+
require.Containsf(t, out, ea, ".sdkmanrc java=%s must select %s, not %s", identifier, ea, installed)
107+
t.Logf("PASS .sdkmanrc java=%s selects %s, not %s", identifier, ea, installed)
108+
}
105109
execOK(ctx, t, ctr, fmt.Sprintf("Remove-Item -LiteralPath %s -Recurse -Force", eaDir), box.vars...)
106110
}
107111

‎tests/parse_legacy_file_test.lua‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ local cases = {
112112
-- Never a release for an early-access build, nor the other way round.
113113
{ "java=28.0.0.0+ea.19-open\n", { "28+36", "28.0.1+3" }, nil },
114114
{ "java=28.0.0+36-open\n", { "28-ea+19" }, nil },
115+
-- The installed name of an early-access build selects it, as in vfox use,
116+
-- although parse_version cannot read it (vfox-java#91). Not installed, it
117+
-- selects nothing, as vfox use reports it not installed.
118+
{ "java=28-ea+19\n", { "21.0.8+9-tem", "28-ea+19", "28-ea+18-zulu" }, "28-ea+19" },
119+
{ "java=28-ea+18-zulu\n", { "21.0.8+9-tem", "28-ea+19", "28-ea+18-zulu" }, "28-ea+18-zulu" },
120+
{ "java=28-ea+19-zulu-fx\n", { "28-ea+19-zulu", "28-ea+19-zulu-fx" }, "28-ea+19-zulu-fx" },
121+
{ "java=26-ea+13-graal\n", { "26-ea+2-graal", "26-ea+13-graal" }, "26-ea+13-graal" },
122+
{ "java=28-ea+20\n", { "28-ea+18", "28-ea+19" }, nil },
115123
-- No java line at all selects nothing.
116124
{ "maven=3.9.9\n", { "21.0.8+9-tem" }, nil },
117125
}

0 commit comments

Comments
 (0)