From aa6ae06c13b0da5261df14818cd7317639de9443 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 5 Sep 2016 15:50:05 +0300 Subject: [PATCH] Cleanup (restarter moved to platform) --- .../src/com/intellij/util/Restarter.java | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) rename platform/{util => platform-impl}/src/com/intellij/util/Restarter.java (87%) diff --git a/platform/util/src/com/intellij/util/Restarter.java b/platform/platform-impl/src/com/intellij/util/Restarter.java similarity index 87% rename from platform/util/src/com/intellij/util/Restarter.java rename to platform/platform-impl/src/com/intellij/util/Restarter.java index 31aa77dcca41..ccb9fdc102f5 100644 --- a/platform/util/src/com/intellij/util/Restarter.java +++ b/platform/platform-impl/src/com/intellij/util/Restarter.java @@ -92,8 +92,7 @@ public class Restarter { } File restarter = new File(restartDir, "restarter.sh"); - BufferedWriter output = new BufferedWriter(new FileWriter(restarter)); - try { + try (BufferedWriter output = new BufferedWriter(new FileWriter(restarter))) { output.write("#!/bin/sh\n"); for (int i = 0; i < beforeRestart.length; i++) { output.write(beforeRestart[i]); @@ -102,16 +101,13 @@ public class Restarter { } output.write('\n'); } - finally { - 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 { + private static void restartOnWindows(@NotNull String... beforeRestart) throws IOException { Kernel32 kernel32 = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class); Shell32 shell32 = (Shell32)Native.loadLibrary("shell32", Shell32.class); @@ -121,14 +117,11 @@ public class Restarter { final String[] argv = getRestartArgv(argv_ptr.getWideStringArray(0, argc.getValue())); kernel32.LocalFree(argv_ptr); - doScheduleRestart(new File(PathManager.getBinPath(), "restarter.exe"), new Consumer>() { - @Override - public void consume(List commands) { - Collections.addAll(commands, String.valueOf(pid), String.valueOf(beforeRestart.length)); - Collections.addAll(commands, beforeRestart); - Collections.addAll(commands, String.valueOf(argv.length)); - Collections.addAll(commands, argv); - } + doScheduleRestart(new File(PathManager.getBinPath(), "restarter.exe"), commands -> { + Collections.addAll(commands, String.valueOf(pid), String.valueOf(beforeRestart.length)); + Collections.addAll(commands, beforeRestart); + Collections.addAll(commands, String.valueOf(argv.length)); + Collections.addAll(commands, argv); }); // Since the process ID is passed through the command line, we want to make sure that we don't exit before the "restarter" @@ -137,18 +130,15 @@ public class Restarter { TimeoutUtil.sleep(500); } - private static void restartOnMac(@NotNull final String... beforeRestart) throws IOException { + private static void restartOnMac(@NotNull String... beforeRestart) throws IOException { String homePath = PathManager.getHomePath(); int p = homePath.indexOf(".app"); if (p < 0) throw new IOException("Application bundle not found: " + homePath); final String bundlePath = homePath.substring(0, p + 4); - doScheduleRestart(new File(PathManager.getBinPath(), "restarter"), new Consumer>() { - @Override - public void consume(List commands) { - Collections.addAll(commands, bundlePath); - Collections.addAll(commands, beforeRestart); - } + doScheduleRestart(new File(PathManager.getBinPath(), "restarter"), commands -> { + Collections.addAll(commands, bundlePath); + Collections.addAll(commands, beforeRestart); }); } @@ -171,7 +161,7 @@ public class Restarter { } private static void doScheduleRestart(File restarterFile, Consumer> argumentsBuilder) throws IOException { - List commands = new ArrayList(); + List commands = new ArrayList<>(); commands.add(createTempExecutable(restarterFile).getPath()); argumentsBuilder.consume(commands); Runtime.getRuntime().exec(ArrayUtil.toStringArray(commands));