OpenJDK / jdk / jdk
changeset 60314:47ebccd0ac02
8248248: [macos] EmptyFolderPackageTest.java fails EmptyFolderPackageTest-dmg-setup.scpt exited with 134 code
Reviewed-by: herrick, asemenyuk
author | almatvee |
---|---|
date | Fri, 24 Jul 2020 16:46:18 -0700 |
parents | b3af0bdfb85a |
children | d7c82394c54c |
files | src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Executor.java src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java test/jdk/ProblemList.txt |
diffstat | 4 files changed, 44 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java Fri Jul 24 13:49:38 2020 -0700 +++ b/src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java Fri Jul 24 16:46:18 2020 -0700 @@ -359,7 +359,7 @@ protoDMG.toAbsolutePath().toString(), hdiUtilVerbosityFlag, "-mountroot", imagesRoot.toAbsolutePath().toString()); - IOUtils.exec(pb, false, null, true); + IOUtils.exec(pb, false, null, true, Executor.INFINITE_TIMEOUT); Path mountedRoot = imagesRoot.resolve(APP_NAME.fetchFrom(params)); @@ -392,7 +392,7 @@ try { pb = new ProcessBuilder("osascript", getConfig_VolumeScript(params).toAbsolutePath().toString()); - IOUtils.exec(pb); + IOUtils.exec(pb, 180); // Wait 3 minutes. See JDK-8248248. } catch (IOException ex) { Log.verbose(ex); }
--- a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Executor.java Fri Jul 24 13:49:38 2020 -0700 +++ b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/Executor.java Fri Jul 24 16:46:18 2020 -0700 @@ -30,6 +30,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -55,6 +56,16 @@ return this; } + Executor setTimeout(long v) { + timeout = v; + if (timeout != INFINITE_TIMEOUT) { + // Redirect output to file if timeout is requested, otherwise we will + // reading until process ends and timeout will never be reached. + setWriteOutputToFile(true); + } + return this; + } + Executor setProcessBuilder(ProcessBuilder v) { pb = v; return this; @@ -103,7 +114,7 @@ int code = 0; if (writeOutputToFile) { try { - code = p.waitFor(); + code = waitForProcess(p); } catch (InterruptedException ex) { Log.verbose(ex); throw new RuntimeException(ex); @@ -184,6 +195,21 @@ } } + private int waitForProcess(Process p) throws InterruptedException { + if (timeout == INFINITE_TIMEOUT) { + return p.waitFor(); + } else { + if (p.waitFor(timeout, TimeUnit.SECONDS)) { + return p.exitValue(); + } else { + Log.verbose(String.format("Command %s timeout after %d seconds", + createLogMessage(pb), timeout)); + p.destroy(); + return -1; + } + } + } + static Executor of(String... cmdline) { return new Executor().setCommandLine(cmdline); } @@ -201,9 +227,12 @@ return sb.toString(); } + public final static int INFINITE_TIMEOUT = -1; + private ProcessBuilder pb; private boolean saveOutput; private boolean writeOutputToFile; + private long timeout = INFINITE_TIMEOUT; private List<String> output; private Consumer<Stream<String>> outputConsumer; }
--- a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java Fri Jul 24 13:49:38 2020 -0700 +++ b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/IOUtils.java Fri Jul 24 16:46:18 2020 -0700 @@ -148,7 +148,13 @@ public static void exec(ProcessBuilder pb) throws IOException { - exec(pb, false, null, false); + exec(pb, false, null, false, Executor.INFINITE_TIMEOUT); + } + + // timeout in seconds. -1 will be return if process timeouts. + public static void exec(ProcessBuilder pb, long timeout) + throws IOException { + exec(pb, false, null, false, timeout); } // See JDK-8236282 @@ -158,19 +164,20 @@ // read this file back. public static void exec(ProcessBuilder pb, boolean writeOutputToFile) throws IOException { - exec(pb, false, null, writeOutputToFile); + exec(pb, false, null, writeOutputToFile, Executor.INFINITE_TIMEOUT); } static void exec(ProcessBuilder pb, boolean testForPresenceOnly, PrintStream consumer) throws IOException { - exec(pb, testForPresenceOnly, consumer, false); + exec(pb, testForPresenceOnly, consumer, false, Executor.INFINITE_TIMEOUT); } static void exec(ProcessBuilder pb, boolean testForPresenceOnly, - PrintStream consumer, boolean writeOutputToFile) throws IOException { + PrintStream consumer, boolean writeOutputToFile, long timeout) + throws IOException { List<String> output = new ArrayList<>(); Executor exec = Executor.of(pb).setWriteOutputToFile(writeOutputToFile) - .setOutputConsumer(lines -> { + .setTimeout(timeout).setOutputConsumer(lines -> { lines.forEach(output::add); if (consumer != null) { output.forEach(consumer::println);
--- a/test/jdk/ProblemList.txt Fri Jul 24 13:49:38 2020 -0700 +++ b/test/jdk/ProblemList.txt Fri Jul 24 16:46:18 2020 -0700 @@ -928,6 +928,5 @@ # jdk_jpackage tools/jpackage/share/jdk/jpackage/tests/ModulePathTest3.java#id0 8248418 generic-all -tools/jpackage/share/EmptyFolderPackageTest.java 8249201 macosx-all ############################################################################