Skip to content

Commit 48e3b65

Browse files
kurashige23Alexey Semenyuk
authored andcommitted
8344275: tools/jpackage/windows/Win8301247Test.java fails on localized Windows platform
Reviewed-by: asemenyuk, almatvee
1 parent 1623257 commit 48e3b65

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static Executor of(String... cmdline) {
5454
public Executor() {
5555
saveOutputType = new HashSet<>(Set.of(SaveOutputType.NONE));
5656
removePathEnvVar = false;
57+
winEnglishOutput = false;
5758
}
5859

5960
public Executor setExecutable(String v) {
@@ -90,6 +91,15 @@ public Executor setRemovePathEnvVar(boolean value) {
9091
return this;
9192
}
9293

94+
public Executor setWinRunWithEnglishOutput(boolean value) {
95+
if (!TKit.isWindows()) {
96+
throw new UnsupportedOperationException(
97+
"setWinRunWithEnglishOutput is only valid on Windows platform");
98+
}
99+
winEnglishOutput = value;
100+
return this;
101+
}
102+
93103
public Executor setWindowsTmpDir(String tmp) {
94104
if (!TKit.isWindows()) {
95105
throw new UnsupportedOperationException(
@@ -207,6 +217,11 @@ public Result executeWithoutExitCodeCheck() {
207217
"Can't change directory when using tool provider");
208218
}
209219

220+
if (toolProvider != null && winEnglishOutput) {
221+
throw new IllegalArgumentException(
222+
"Can't change locale when using tool provider");
223+
}
224+
210225
return ThrowingSupplier.toSupplier(() -> {
211226
if (toolProvider != null) {
212227
return runToolProvider();
@@ -324,8 +339,17 @@ private Path executablePath() {
324339
return executable.toAbsolutePath();
325340
}
326341

342+
private List<String> prefixCommandLineArgs() {
343+
if (winEnglishOutput) {
344+
return List.of("cmd.exe", "/c", "chcp", "437", ">nul", "2>&1", "&&");
345+
} else {
346+
return List.of();
347+
}
348+
}
349+
327350
private Result runExecutable() throws IOException, InterruptedException {
328351
List<String> command = new ArrayList<>();
352+
command.addAll(prefixCommandLineArgs());
329353
command.add(executablePath().toString());
330354
command.addAll(args);
331355
ProcessBuilder builder = new ProcessBuilder(command);
@@ -457,15 +481,17 @@ public String getPrintableCommandLine() {
457481
exec = executablePath().toString();
458482
}
459483

460-
return String.format(format, printCommandLine(exec, args),
461-
args.size() + 1);
484+
var cmdline = Stream.of(prefixCommandLineArgs(), List.of(exec), args).flatMap(
485+
List::stream).toList();
486+
487+
return String.format(format, printCommandLine(cmdline), cmdline.size());
462488
}
463489

464-
private static String printCommandLine(String executable, List<String> args) {
490+
private static String printCommandLine(List<String> cmdline) {
465491
// Want command line printed in a way it can be easily copy/pasted
466-
// to be executed manally
492+
// to be executed manually
467493
Pattern regex = Pattern.compile("\\s");
468-
return Stream.concat(Stream.of(executable), args.stream()).map(
494+
return cmdline.stream().map(
469495
v -> (v.isEmpty() || regex.matcher(v).find()) ? "\"" + v + "\"" : v).collect(
470496
Collectors.joining(" "));
471497
}
@@ -479,6 +505,7 @@ private static void trace(String msg) {
479505
private Set<SaveOutputType> saveOutputType;
480506
private Path directory;
481507
private boolean removePathEnvVar;
508+
private boolean winEnglishOutput;
482509
private String winTmpDir = null;
483510

484511
private static enum SaveOutputType {

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,13 @@ public static void killAppLauncherProcess(JPackageCommand cmd,
284284
}
285285

286286
private static long[] findAppLauncherPIDs(JPackageCommand cmd, String launcherName) {
287-
// Get the list of PIDs and PPIDs of app launcher processes.
287+
// Get the list of PIDs and PPIDs of app launcher processes. Run setWinRunWithEnglishOutput(true) for JDK-8344275.
288288
// wmic process where (name = "foo.exe") get ProcessID,ParentProcessID
289289
List<String> output = Executor.of("wmic", "process", "where", "(name",
290290
"=",
291291
"\"" + cmd.appLauncherPath(launcherName).getFileName().toString() + "\"",
292-
")", "get", "ProcessID,ParentProcessID").dumpOutput(true).
293-
saveOutput().executeAndGetOutput();
294-
292+
")", "get", "ProcessID,ParentProcessID").dumpOutput(true).saveOutput().
293+
setWinRunWithEnglishOutput(true).executeAndGetOutput();
295294
if ("No Instance(s) Available.".equals(output.getFirst().trim())) {
296295
return new long[0];
297296
}

0 commit comments

Comments
 (0)