From 434633b19d3476732f02aec4e6118fa66e45a848 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Mon, 9 Feb 2015 17:39:25 +0300 Subject: [PATCH] resistance to non-existent runnerw.exe (WEB-15051) --- .../execution/process/RunnerMediator.java | 33 +++++++++++-------- .../execution/process/RunnerWinProcess.java | 7 ++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/execution/process/RunnerMediator.java b/platform/platform-impl/src/com/intellij/execution/process/RunnerMediator.java index 8b177279e786..649835c3a544 100644 --- a/platform/platform-impl/src/com/intellij/execution/process/RunnerMediator.java +++ b/platform/platform-impl/src/com/intellij/execution/process/RunnerMediator.java @@ -31,12 +31,13 @@ import java.io.PrintWriter; * @author traff */ public class RunnerMediator { - public static final Logger LOG = Logger.getInstance("#com.intellij.execution.process.RunnerMediator"); + private static final Logger LOG = Logger.getInstance("#com.intellij.execution.process.RunnerMediator"); private static final char IAC = (char)5; private static final char BRK = (char)3; private static final char C = (char)5; private static final String STANDARD_RUNNERW = "runnerw.exe"; + private static final String IDEA_RUNNERW = "IDEA_RUNNERW"; /** * Creates default runner mediator @@ -79,28 +80,32 @@ public class RunnerMediator { @Nullable private static String getRunnerPath() { - if (SystemInfo.isWindows) { - final String path = System.getenv("IDEA_RUNNERW"); - if (path != null && new File(path).exists()) { - return path; - } - File runnerw = new File(PathManager.getBinPath(), STANDARD_RUNNERW); - if (runnerw.exists()) { - return runnerw.getPath(); - } - return null; - } - else { + if (!SystemInfo.isWindows) { throw new IllegalStateException("There is no need of runner under unix based OS"); } + final String path = System.getenv(IDEA_RUNNERW); + if (path != null) { + if (new File(path).exists()) { + return path; + } + LOG.warn("Cannot locate " + STANDARD_RUNNERW + " by " + IDEA_RUNNERW + " environment variable (" + path + ")"); + } + File runnerw = new File(PathManager.getBinPath(), STANDARD_RUNNERW); + if (runnerw.exists()) { + return runnerw.getPath(); + } + LOG.warn("Cannot locate " + STANDARD_RUNNERW + " by default path (" + runnerw.getAbsolutePath() + ")"); + return null; } - static void injectRunnerCommand(@NotNull GeneralCommandLine commandLine) { + static boolean injectRunnerCommand(@NotNull GeneralCommandLine commandLine) { final String path = getRunnerPath(); if (path != null) { commandLine.getParametersList().addAt(0, commandLine.getExePath()); commandLine.setExePath(path); + return true; } + return false; } /** diff --git a/platform/platform-impl/src/com/intellij/execution/process/RunnerWinProcess.java b/platform/platform-impl/src/com/intellij/execution/process/RunnerWinProcess.java index 8e142c45c1a4..833591c75ce0 100644 --- a/platform/platform-impl/src/com/intellij/execution/process/RunnerWinProcess.java +++ b/platform/platform-impl/src/com/intellij/execution/process/RunnerWinProcess.java @@ -35,13 +35,12 @@ public class RunnerWinProcess extends ProcessWrapper { } @NotNull - public static RunnerWinProcess create(@NotNull GeneralCommandLine commandLine) throws ExecutionException { + public static Process create(@NotNull GeneralCommandLine commandLine) throws ExecutionException { if (!SystemInfo.isWindows) { throw new RuntimeException(RunnerWinProcess.class.getSimpleName() + " works on Windows only!"); } - RunnerMediator.injectRunnerCommand(commandLine); + boolean success = RunnerMediator.injectRunnerCommand(commandLine); Process process = commandLine.createProcess(); - return new RunnerWinProcess(process); + return success ? new RunnerWinProcess(process) : process; } - }