diff --git a/platform/platform-api/src/com/intellij/execution/process/ProcessTerminatedListener.java b/platform/platform-api/src/com/intellij/execution/process/ProcessTerminatedListener.java index c4111dc29423..21c8d42d36aa 100644 --- a/platform/platform-api/src/com/intellij/execution/process/ProcessTerminatedListener.java +++ b/platform/platform-api/src/com/intellij/execution/process/ProcessTerminatedListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.StatusBar; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import java.util.Locale; @@ -30,8 +29,8 @@ import java.util.Locale; * @author dyoma */ public class ProcessTerminatedListener extends ProcessAdapter { - @NonNls protected static final String EXIT_CODE_ENTRY = "$EXIT_CODE$"; - @NonNls protected static final String EXIT_CODE_REGEX = "\\$EXIT_CODE\\$"; + protected static final String EXIT_CODE_ENTRY = "$EXIT_CODE$"; + protected static final String EXIT_CODE_REGEX = "\\$EXIT_CODE\\$"; private static final Key KEY = new Key("processTerminatedListener"); @@ -64,33 +63,40 @@ public class ProcessTerminatedListener extends ProcessAdapter { attach(processHandler, null); } + @Override public void processTerminated(ProcessEvent event) { - final ProcessHandler processHandler = event.getProcessHandler(); + ProcessHandler processHandler = event.getProcessHandler(); processHandler.removeProcessListener(this); - final String message = myProcessFinishedMessage.replaceAll(EXIT_CODE_REGEX, stringifyExitCode(event.getExitCode())); + String message = myProcessFinishedMessage.replaceAll(EXIT_CODE_REGEX, stringifyExitCode(event.getExitCode())); processHandler.notifyTextAvailable(message, ProcessOutputTypes.SYSTEM); - if (myProject != null) ApplicationManager.getApplication().invokeLater(() -> { - if (myProject.isDisposed()) return; - StatusBar.Info.set(message, myProject); - }); + if (myProject != null) { + ApplicationManager.getApplication().invokeLater(() -> StatusBar.Info.set(message, myProject), myProject.getDisposed()); + } } @NotNull private static String stringifyExitCode(int exitCode) { - // Quote from http://support.microsoft.com/kb/308558: - // If the result code has the "C0000XXX" format, the task did not complete successfully (the "C" indicates an error condition). - // The most common "C" error code is "0xC000013A: The application terminated as a result of a CTRL+C". + StringBuilder result = new StringBuilder(); + result.append(exitCode); + if (SystemInfo.isWindows && exitCode >= 0xC0000000 && exitCode < 0xD0000000) { - StringBuilder result = new StringBuilder(); - result.append(exitCode); + // Quote from http://support.microsoft.com/kb/308558: + // If the result code has the "C0000XXX" format, the task did not complete successfully (the "C" indicates an error condition). + // The most common "C" error code is "0xC000013A: The application terminated as a result of a CTRL+C". result.append(" (0x").append(Integer.toHexString(exitCode).toUpperCase(Locale.ENGLISH)); if (exitCode == 0xC000013A) { - // reporting a detailed reason for a well-known exit code result.append(": interrupted by Ctrl+C"); } - result.append(")"); - return result.toString(); + result.append(')'); } - return String.valueOf(exitCode); + else if (SystemInfo.isUnix && exitCode >= 129 && exitCode <= 159) { + @SuppressWarnings("SpellCheckingInspection") String[] signals = { + "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "EMT", "FPE", "KILL", "BUS", "SEGV", "SYS", "PIPE", "ALRM", "TERM", "URG", + "STOP", "TSTP", "CONT", "CHLD", "TTIN", "TTOU", "IO", "XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "INFO", "USR1", "USR2"}; + int signal = exitCode - 128; + result.append(" (interrupted by signal ").append(signal).append(": SIG").append(signals[signal - 1]).append(')'); + } + + return result.toString(); } -} +} \ No newline at end of file