diff --git a/test/jdk/sun/security/mscapi/CngCipher.java b/test/jdk/sun/security/mscapi/CngCipher.java index b867641e8a5..348fdeef865 100644 --- a/test/jdk/sun/security/mscapi/CngCipher.java +++ b/test/jdk/sun/security/mscapi/CngCipher.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,6 +22,7 @@ */ import jdk.test.lib.Asserts; +import jdk.test.lib.util.FileUtils; import jdk.test.lib.SecurityTools; import java.util.Arrays; @@ -57,7 +58,7 @@ public class CngCipher { SecurityTools.keytool("-storetype Windows-MY -genkeypair -alias " + PREFIX + "m -keyalg RSA -dname CN=" + PREFIX + "m"); // This will generate a CNG key - ProcessBuilder pb = new ProcessBuilder("powershell", "-Command", + ProcessBuilder pb = new ProcessBuilder(FileUtils.powerShellPath(), "-Command", "New-SelfSignedCertificate", "-DnsName", PREFIX + "c", // -KeyAlgorithm not supported on Windows Server 2012 //"-KeyAlgorithm", "RSA", diff --git a/test/jdk/sun/security/mscapi/DupAlias.java b/test/jdk/sun/security/mscapi/DupAlias.java index 84c70cbbee2..bcadb2debe4 100644 --- a/test/jdk/sun/security/mscapi/DupAlias.java +++ b/test/jdk/sun/security/mscapi/DupAlias.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,6 +21,7 @@ * questions. */ import jdk.test.lib.Asserts; +import jdk.test.lib.util.FileUtils; import sun.security.tools.keytool.CertAndKeyGen; import sun.security.x509.X500Name; @@ -83,7 +84,7 @@ public class DupAlias { } static void ps(String f) throws Exception { - ProcessBuilder pb = new ProcessBuilder("powershell", "-Command", f); + ProcessBuilder pb = new ProcessBuilder(FileUtils.powerShellPath(), "-Command", f); pb.inheritIO(); if (pb.start().waitFor() != 0) { throw new RuntimeException("Failed"); diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WinExecutableIconVerifier.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WinExecutableIconVerifier.java index f4468fa9ab0..3967c0131db 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WinExecutableIconVerifier.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WinExecutableIconVerifier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -208,7 +208,7 @@ public final class WinExecutableIconVerifier { Path extractedIcon = outputDir.resolve(extractedIconFilename + ".bmp"); - Executor.of("powershell", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Unrestricted", + Executor.of(WindowsHelper.PowerShellPath(), "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Unrestricted", "-File", EXTRACT_ICON_PS1.toString(), "-InputExecutable", executable.toAbsolutePath().normalize().toString(), "-OutputIcon", extractedIcon.toAbsolutePath().normalize().toString() diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java index 22031d1a7fd..639bd295e57 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java @@ -306,7 +306,7 @@ public class WindowsHelper { } public static String getExecutableDescription(Path pathToExeFile) { - Executor exec = Executor.of("powershell", + Executor exec = Executor.of(PowerShellPath(), "-NoLogo", "-NoProfile", "-Command", @@ -455,7 +455,7 @@ public class WindowsHelper { ; Path getPath() { - final var str = Executor.of("powershell", "-NoLogo", "-NoProfile", + final var str = Executor.of(PowerShellPath(), "-NoLogo", "-NoProfile", "-NonInteractive", "-Command", String.format("[Environment]::GetFolderPath('%s')", name()) ).saveFirstLineOfOutput().execute().getFirstLineOfOutput(); @@ -661,4 +661,11 @@ public class WindowsHelper { private static final String USER_SHELL_FOLDERS_REGKEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; private static final int WIN_MAX_PATH = 260; + + public static String PowerShellPath() { + String systemRoot = System.getenv("SystemRoot"); + String suffix = "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"; + String fullPath = systemRoot == null ? null : systemRoot + suffix; + return (fullPath != null && Files.exists(Path.of(fullPath))) ? fullPath : "powershell"; + } } diff --git a/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/util/CommandOutputControlTest.java b/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/util/CommandOutputControlTest.java index 2ddfbcb5d78..43280de79ad 100644 --- a/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/util/CommandOutputControlTest.java +++ b/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/util/CommandOutputControlTest.java @@ -22,6 +22,8 @@ */ package jdk.jpackage.internal.util; +import jdk.jpackage.test.WindowsHelper; + import static java.util.stream.Collectors.joining; import static jdk.jpackage.internal.util.CommandOutputControlTestUtils.isInterleave; import static jdk.jpackage.internal.util.function.ThrowingConsumer.toConsumer; @@ -1004,7 +1006,7 @@ public class CommandOutputControlTest { commandSeparator = " && "; } case POWERSHELL -> { - commandline.addAll(List.of("powershell", "-NoProfile", "-Command")); + commandline.addAll(List.of(WindowsHelper.PowerShellPath(), "-NoProfile", "-Command")); commandSeparator = "; "; } default -> { @@ -1176,7 +1178,7 @@ public class CommandOutputControlTest { // It sends packets every second. // To wait N seconds, it should send N+1 packets. // The "timeout" command works only in a console. - return String.format("(ping -n %d localhost > nul)", sleep.seconds() + 1); + return String.format("(%%SystemRoot%%\\System32\\ping.exe -n %d localhost > nul)", sleep.seconds() + 1); } case POWERSHELL -> { return "Start-Sleep -Seconds " + sleep.seconds(); diff --git a/test/jdk/tools/jpackage/resources/Win8365790Test.ps1 b/test/jdk/tools/jpackage/resources/Win8365790Test.ps1 index 3a7d8c9a90b..ee77fea2a67 100644 --- a/test/jdk/tools/jpackage/resources/Win8365790Test.ps1 +++ b/test/jdk/tools/jpackage/resources/Win8365790Test.ps1 @@ -1,5 +1,5 @@ # -# Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -64,6 +64,9 @@ Add-Type @type Set-PSDebug -Trace 2 +# Ensure system directories are on the PATH for the child process. +$env:Path = "$env:SystemRoot\System32;$env:SystemRoot;$env:Path" + # Launch the target executable. # `-NoNewWindow` parameter will attach the started process to the existing console. $childProc = Start-Process -PassThru -NoNewWindow $Executable diff --git a/test/jdk/tools/jpackage/windows/Win8365790Test.java b/test/jdk/tools/jpackage/windows/Win8365790Test.java index 5a690ea0146..62a648dce8e 100644 --- a/test/jdk/tools/jpackage/windows/Win8365790Test.java +++ b/test/jdk/tools/jpackage/windows/Win8365790Test.java @@ -23,6 +23,8 @@ import static jdk.jpackage.test.HelloApp.configureAndExecute; +import jdk.jpackage.test.WindowsHelper; + import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -108,7 +110,7 @@ public class Win8365790Test { var future = CompletableFuture.runAsync(() -> { TKit.withState(() -> { - configureAndExecute(0, Executor.of("powershell", "-NonInteractive", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Unrestricted") + configureAndExecute(0, Executor.of(WindowsHelper.PowerShellPath(), "-NonInteractive", "-NoLogo", "-NoProfile", "-ExecutionPolicy", "Unrestricted") .addArgument("-File").addArgument(TEST_PS1) .addArguments("-TimeoutSeconds", Long.toString(Duration.ofSeconds(5).getSeconds())) .addArgument("-Executable").addArgument(cmd.appLauncherPath(launcherName)) diff --git a/test/lib/jdk/test/lib/util/FileUtils.java b/test/lib/jdk/test/lib/util/FileUtils.java index 3e537835c0b..8c149f3de81 100644 --- a/test/lib/jdk/test/lib/util/FileUtils.java +++ b/test/lib/jdk/test/lib/util/FileUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -475,4 +475,11 @@ public final class FileUtils { {"/sbin/lsof", "-p"}, {"/usr/local/bin/lsof", "-p"}, }; + + public static String powerShellPath() { + String systemRoot = System.getenv("SystemRoot"); + String suffix = "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"; + String fullPath = systemRoot == null ? null : systemRoot + suffix; + return (fullPath != null && Files.exists(Path.of(fullPath))) ? fullPath : "powershell"; + } }