@@ -59,11 +59,12 @@ func verifySearch(ctx context.Context, t *testing.T, ctr tc.Container, box slotB
5959// java=21.0.8.0+9-tem, see common.PaddedIdentifier) or the installed version
6060// itself (e.g. java=21.0.8+9-tem), written by Set-Content with Windows line
6161// endings, while vfox lists an empty install of another release first (see
62- // common.Decoy). It runs before any `vfox use`, so java can only come from
63- // the legacy file.
62+ // common.Decoy). SDKMAN's identifier of an early-access build (e.g.
63+ // java=21.0.0.0+ea.1-tem) must then select a faked install of that build
64+ // (see common.EarlyAccess), not the release. It runs before any `vfox use`,
65+ // so java can only come from the legacy file.
6466func verifyLegacyFile (ctx context.Context , t * testing.T , ctr tc.Container , box slotBox , distribution , version , installed , arch string ) {
6567 t .Helper ()
66- const dir = `C:\e2e-legacy-sdkmanrc`
6768 // vfox counts a version as installed once its directory holds
6869 // java-<version>; the decoy holds nothing more, so selecting it leaves
6970 // no java on PATH.
@@ -79,25 +80,46 @@ func verifyLegacyFile(ctx context.Context, t *testing.T, ctr tc.Container, box s
7980 common .PaddedIdentifier (distribution , version , installed ),
8081 installed ,
8182 } {
82- execOK (ctx , t , ctr , fmt .Sprintf (
83- "New-Item -ItemType Directory -Force -Path %s | Out-Null; Set-Content -Path %s -Value %s" ,
84- pwshQuote (dir ), pwshQuote (dir + `\.sdkmanrc` ), pwshQuote ("java=" + identifier )), box .vars ... )
85- // The probe activates its own PowerShell process. Activation pins
86- // __VFOX_PID, which scopes the `vfox env` state cache, but Windows may
87- // reuse a just-exited PID and legacy files are not among the cache's
88- // tracked inputs, so the cache file is removed before the export.
89- script := fmt .Sprintf (
90- "Invoke-Expression -Command (vfox activate pwsh | Out-String); " +
91- "Set-Location -LiteralPath %s; " +
92- "if ($env:__VFOX_CURTMPPATH) { Remove-Item -LiteralPath (Join-Path $env:__VFOX_CURTMPPATH 'env-state.json') -Force -ErrorAction SilentlyContinue }; " +
93- "$__vfoxExport = vfox env -s pwsh | Out-String; " +
94- "if ($__vfoxExport.Trim()) { Invoke-Expression -Command $__vfoxExport }; " +
95- "java %s" , pwshQuote (dir ), showSettings )
96- out := execRetry (ctx , t , ctr , ".sdkmanrc java=" + identifier , script , box .vars ... )
83+ out := legacyJava (ctx , t , ctr , box , identifier )
9784 common .CheckJava (t , out , distribution , version , arch , ".sdkmanrc java=" + identifier )
9885 t .Logf ("PASS .sdkmanrc java=%s selects java %s, not %s" , identifier , version , decoy )
9986 }
10087 execOK (ctx , t , ctr , fmt .Sprintf ("Remove-Item -LiteralPath %s -Recurse -Force" , decoyDir ), box .vars ... )
88+
89+ // The early-access build's java (a java.cmd) only prints its name, which
90+ // the release's java, selected instead, would not.
91+ ea := common .EarlyAccess (distribution , version )
92+ eaDir := fmt .Sprintf ("(Join-Path $env:VFOX_HOME %s)" , pwshQuote (`cache\java\v-` + ea ))
93+ execOK (ctx , t , ctr , fmt .Sprintf (
94+ "$bin = Join-Path %s %s; New-Item -ItemType Directory -Force -Path $bin | Out-Null; " +
95+ "Set-Content -Path (Join-Path $bin 'java.cmd') -Value %s" ,
96+ eaDir , pwshQuote (`java-` + ea + `\bin` ), pwshQuote ("@echo " + ea )), box .vars ... )
97+ identifier := common .EarlyAccessIdentifier (distribution , version )
98+ out := legacyJava (ctx , t , ctr , box , identifier )
99+ require .Containsf (t , out , ea , ".sdkmanrc java=%s must select %s, not %s" , identifier , ea , installed )
100+ t .Logf ("PASS .sdkmanrc java=%s selects %s, not %s" , identifier , ea , installed )
101+ execOK (ctx , t , ctr , fmt .Sprintf ("Remove-Item -LiteralPath %s -Recurse -Force" , eaDir ), box .vars ... )
102+ }
103+
104+ // legacyJava writes java=<identifier> to a .sdkmanrc and returns what java
105+ // prints next to it. The probe activates its own PowerShell process.
106+ // Activation pins __VFOX_PID, which scopes the `vfox env` state cache, but
107+ // Windows may reuse a just-exited PID and legacy files are not among the
108+ // cache's tracked inputs, so the cache file is removed before the export.
109+ func legacyJava (ctx context.Context , t * testing.T , ctr tc.Container , box slotBox , identifier string ) string {
110+ t .Helper ()
111+ const dir = `C:\e2e-legacy-sdkmanrc`
112+ execOK (ctx , t , ctr , fmt .Sprintf (
113+ "New-Item -ItemType Directory -Force -Path %s | Out-Null; Set-Content -Path %s -Value %s" ,
114+ pwshQuote (dir ), pwshQuote (dir + `\.sdkmanrc` ), pwshQuote ("java=" + identifier )), box .vars ... )
115+ script := fmt .Sprintf (
116+ "Invoke-Expression -Command (vfox activate pwsh | Out-String); " +
117+ "Set-Location -LiteralPath %s; " +
118+ "if ($env:__VFOX_CURTMPPATH) { Remove-Item -LiteralPath (Join-Path $env:__VFOX_CURTMPPATH 'env-state.json') -Force -ErrorAction SilentlyContinue }; " +
119+ "$__vfoxExport = vfox env -s pwsh | Out-String; " +
120+ "if ($__vfoxExport.Trim()) { Invoke-Expression -Command $__vfoxExport }; " +
121+ "java %s" , pwshQuote (dir ), showSettings )
122+ return execRetry (ctx , t , ctr , ".sdkmanrc java=" + identifier , script , box .vars ... )
101123}
102124
103125// verifyToolchain runs java and javac through the activate + env hooks and
0 commit comments