From f7995a34fa3296d5cb08b5d31f60d0424cc68b4b Mon Sep 17 00:00:00 2001 From: "Vladimir.Orlov" Date: Tue, 1 Sep 2015 15:26:42 +0300 Subject: [PATCH] added restarter for update process on unix --- bin/scripts/unix/idea.sh | 1 + .../util/src/com/intellij/util/Restarter.java | 27 ++++++++----------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/bin/scripts/unix/idea.sh b/bin/scripts/unix/idea.sh index cfbb5880e9fd..eca569f3a23f 100755 --- a/bin/scripts/unix/idea.sh +++ b/bin/scripts/unix/idea.sh @@ -193,4 +193,5 @@ LD_LIBRARY_PATH="$IDE_BIN_HOME:$LD_LIBRARY_PATH" "$JAVA_BIN" \ "$@" EC=$? test $EC -ne 88 && exit $EC +$HOME/.@@system_selector@@/restart/restarter.sh exec "$0" "$@" diff --git a/platform/util/src/com/intellij/util/Restarter.java b/platform/util/src/com/intellij/util/Restarter.java index 8c5c30b59431..730444166664 100644 --- a/platform/util/src/com/intellij/util/Restarter.java +++ b/platform/util/src/com/intellij/util/Restarter.java @@ -28,6 +28,8 @@ import com.sun.jna.win32.StdCallLibrary; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.io.FileWriter; +import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -86,23 +88,16 @@ public class Restarter { private static void runCommand(String... beforeRestart) throws IOException { if (beforeRestart.length == 0) return; - try { - Process process = Runtime.getRuntime().exec(beforeRestart); - - Thread outThread = new Thread(new StreamRedirector(process.getInputStream(), System.out),"restarter redirector out"); - Thread errThread = new Thread(new StreamRedirector(process.getErrorStream(), System.err),"restarter redirector err"); - outThread.start(); - errThread.start(); - - try { - process.waitFor(); - } - finally { - outThread.join(); - errThread.join(); - } + File restartDir = new File(System.getProperty("user.home") + "/." + System.getProperty("idea.paths.selector") + "/restart"); + if (! FileUtilRt.createDirectory(restartDir)) throw new IOException("Cannot create dir: " + restartDir); + File restarter = new File(restartDir.getPath() + "/restarter.sh"); + BufferedWriter output = new BufferedWriter(new FileWriter(restarter)); + output.write("#!/bin/sh \n"); + for (String command : beforeRestart ){ + output.write(command + " "); } - catch (InterruptedException ignore) { } + output.close(); + if (! restarter.setExecutable(true, true)) throw new IOException("Cannot make file executable: " + restarter); } private static void restartOnWindows(@NotNull final String... beforeRestart) throws IOException {