From 3adced9962940e6947450446f6d892dec46c87a6 Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Sun, 4 Mar 2018 09:57:39 +0100 Subject: [PATCH] Remove workaround for JDK-8023130 in RunProcess With JDK 8 being the baseline and JDK 7 not being supported anymore we can get rid of the workaround for a JDK 7 bug in ProcessBuilder.inheritIO on Windows machines. Closes gh-12337 --- .../boot/loader/tools/RunProcess.java | 69 +------------------ 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java index 0b1b41eaf4..03b2a90cf4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/RunProcess.java @@ -16,16 +16,10 @@ package org.springframework.boot.loader.tools; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; -import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collection; -import java.util.Locale; - -import org.springframework.util.ReflectionUtils; /** * Utility used to run a process. @@ -38,9 +32,6 @@ import org.springframework.util.ReflectionUtils; */ public class RunProcess { - private static final Method INHERIT_IO_METHOD = ReflectionUtils - .findMethod(ProcessBuilder.class, "inheritIO"); - private static final long JUST_ENDED_LIMIT = 500; private File workingDirectory; @@ -81,13 +72,10 @@ public class RunProcess { builder.directory(this.workingDirectory); builder.command().addAll(args); builder.redirectErrorStream(true); - boolean inheritedIO = inheritIO(builder); + builder.inheritIO(); try { Process process = builder.start(); this.process = process; - if (!inheritedIO) { - redirectOutput(process); - } SignalUtils.attachSignalHandler(this::handleSigInt); if (waitForProcess) { try { @@ -108,61 +96,6 @@ public class RunProcess { } } - private boolean inheritIO(ProcessBuilder builder) { - if (isInheritIOBroken()) { - return false; - } - try { - INHERIT_IO_METHOD.invoke(builder); - return true; - } - catch (Exception ex) { - return false; - } - } - - // There's a bug in the Windows VM (https://bugs.openjdk.java.net/browse/JDK-8023130) - // that means we need to avoid inheritIO - private static boolean isInheritIOBroken() { - if (!System.getProperty("os.name", "none").toLowerCase(Locale.ENGLISH) - .contains("windows")) { - return false; - } - String runtime = System.getProperty("java.runtime.version"); - if (!runtime.startsWith("1.7")) { - return false; - } - String[] tokens = runtime.split("_"); - if (tokens.length < 2) { - return true; // No idea actually, shouldn't happen - } - try { - Integer build = Integer.valueOf(tokens[1].split("[^0-9]")[0]); - if (build < 60) { - return true; - } - } - catch (Exception ex) { - return true; - } - return false; - } - - private void redirectOutput(Process process) { - new Thread(() -> { - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(process.getInputStream()))) { - reader.lines().forEach((line) -> { - System.out.println(line); - System.out.flush(); - }); - } - catch (Exception ex) { - // Ignore - } - }).start(); - } - /** * Return the running process. * @return the process or {@code null}