8344275: tools/jpackage/windows/Win8301247Test.java fails on localized Windows platform
Reviewed-by: asemenyuk, almatvee
This commit is contained in:
parent
16232578d9
commit
48e3b6511a
@ -54,6 +54,7 @@ public final class Executor extends CommandArguments<Executor> {
|
||||
public Executor() {
|
||||
saveOutputType = new HashSet<>(Set.of(SaveOutputType.NONE));
|
||||
removePathEnvVar = false;
|
||||
winEnglishOutput = false;
|
||||
}
|
||||
|
||||
public Executor setExecutable(String v) {
|
||||
@ -90,6 +91,15 @@ public final class Executor extends CommandArguments<Executor> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Executor setWinRunWithEnglishOutput(boolean value) {
|
||||
if (!TKit.isWindows()) {
|
||||
throw new UnsupportedOperationException(
|
||||
"setWinRunWithEnglishOutput is only valid on Windows platform");
|
||||
}
|
||||
winEnglishOutput = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Executor setWindowsTmpDir(String tmp) {
|
||||
if (!TKit.isWindows()) {
|
||||
throw new UnsupportedOperationException(
|
||||
@ -207,6 +217,11 @@ public final class Executor extends CommandArguments<Executor> {
|
||||
"Can't change directory when using tool provider");
|
||||
}
|
||||
|
||||
if (toolProvider != null && winEnglishOutput) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can't change locale when using tool provider");
|
||||
}
|
||||
|
||||
return ThrowingSupplier.toSupplier(() -> {
|
||||
if (toolProvider != null) {
|
||||
return runToolProvider();
|
||||
@ -324,8 +339,17 @@ public final class Executor extends CommandArguments<Executor> {
|
||||
return executable.toAbsolutePath();
|
||||
}
|
||||
|
||||
private List<String> prefixCommandLineArgs() {
|
||||
if (winEnglishOutput) {
|
||||
return List.of("cmd.exe", "/c", "chcp", "437", ">nul", "2>&1", "&&");
|
||||
} else {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
private Result runExecutable() throws IOException, InterruptedException {
|
||||
List<String> command = new ArrayList<>();
|
||||
command.addAll(prefixCommandLineArgs());
|
||||
command.add(executablePath().toString());
|
||||
command.addAll(args);
|
||||
ProcessBuilder builder = new ProcessBuilder(command);
|
||||
@ -457,15 +481,17 @@ public final class Executor extends CommandArguments<Executor> {
|
||||
exec = executablePath().toString();
|
||||
}
|
||||
|
||||
return String.format(format, printCommandLine(exec, args),
|
||||
args.size() + 1);
|
||||
var cmdline = Stream.of(prefixCommandLineArgs(), List.of(exec), args).flatMap(
|
||||
List::stream).toList();
|
||||
|
||||
return String.format(format, printCommandLine(cmdline), cmdline.size());
|
||||
}
|
||||
|
||||
private static String printCommandLine(String executable, List<String> args) {
|
||||
private static String printCommandLine(List<String> cmdline) {
|
||||
// Want command line printed in a way it can be easily copy/pasted
|
||||
// to be executed manally
|
||||
// to be executed manually
|
||||
Pattern regex = Pattern.compile("\\s");
|
||||
return Stream.concat(Stream.of(executable), args.stream()).map(
|
||||
return cmdline.stream().map(
|
||||
v -> (v.isEmpty() || regex.matcher(v).find()) ? "\"" + v + "\"" : v).collect(
|
||||
Collectors.joining(" "));
|
||||
}
|
||||
@ -479,6 +505,7 @@ public final class Executor extends CommandArguments<Executor> {
|
||||
private Set<SaveOutputType> saveOutputType;
|
||||
private Path directory;
|
||||
private boolean removePathEnvVar;
|
||||
private boolean winEnglishOutput;
|
||||
private String winTmpDir = null;
|
||||
|
||||
private static enum SaveOutputType {
|
||||
|
@ -284,14 +284,13 @@ public class WindowsHelper {
|
||||
}
|
||||
|
||||
private static long[] findAppLauncherPIDs(JPackageCommand cmd, String launcherName) {
|
||||
// Get the list of PIDs and PPIDs of app launcher processes.
|
||||
// Get the list of PIDs and PPIDs of app launcher processes. Run setWinRunWithEnglishOutput(true) for JDK-8344275.
|
||||
// wmic process where (name = "foo.exe") get ProcessID,ParentProcessID
|
||||
List<String> output = Executor.of("wmic", "process", "where", "(name",
|
||||
"=",
|
||||
"\"" + cmd.appLauncherPath(launcherName).getFileName().toString() + "\"",
|
||||
")", "get", "ProcessID,ParentProcessID").dumpOutput(true).
|
||||
saveOutput().executeAndGetOutput();
|
||||
|
||||
")", "get", "ProcessID,ParentProcessID").dumpOutput(true).saveOutput().
|
||||
setWinRunWithEnglishOutput(true).executeAndGetOutput();
|
||||
if ("No Instance(s) Available.".equals(output.getFirst().trim())) {
|
||||
return new long[0];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user