From 4c09eddfee3663cb40aea16ee54bace67f68b780 Mon Sep 17 00:00:00 2001 From: Oleg Sukhodolsky Date: Thu, 20 Sep 2012 17:21:22 +0400 Subject: [PATCH] RUBY-11574: if rake execution has output in stderr but exit status is 0 we show it as list of warnings. #RUBY-11574 fixed --- .../intellij/execution/ExecutionHelper.java | 62 ++++++++++++++----- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java b/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java index 8b8eb3362a29..d21dd307ac7a 100644 --- a/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java +++ b/platform/lang-impl/src/com/intellij/execution/ExecutionHelper.java @@ -46,6 +46,7 @@ import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; import com.intellij.ui.content.MessageView; +import com.intellij.util.ArrayUtil; import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.NotNullFunction; @@ -74,17 +75,29 @@ public class ExecutionHelper { private ExecutionHelper() { } - public static void showErrors(@NotNull final Project myProject, - @NotNull final List exceptionList, - @NotNull final String tabDisplayName, - @Nullable final VirtualFile file) { - if (ApplicationManager.getApplication().isUnitTestMode() && !exceptionList.isEmpty()) { - throw new RuntimeException(exceptionList.get(0)); + public static void showErrors( + @NotNull final Project myProject, + @NotNull final List errors, + @NotNull final String tabDisplayName, + @Nullable final VirtualFile file) + { + showExceptions(myProject, errors, Collections.emptyList(), tabDisplayName, file); + } + + public static void showExceptions( + @NotNull final Project myProject, + @NotNull final List errors, + @NotNull final List warnings, + @NotNull final String tabDisplayName, + @Nullable final VirtualFile file) + { + if (ApplicationManager.getApplication().isUnitTestMode() && !errors.isEmpty()) { + throw new RuntimeException(errors.get(0)); } ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { if (myProject.isDisposed()) return; - if (exceptionList.isEmpty()) { + if (errors.isEmpty() && warnings.isEmpty()) { removeContents(null, myProject, tabDisplayName); return; } @@ -95,25 +108,44 @@ public class ExecutionHelper { } catch (NullPointerException e) { final StringBuilder builder = new StringBuilder(); - builder.append("Exceptions occured:"); - for (final Exception exception : exceptionList) { + builder.append("Exceptions occurred:"); + for (final Exception exception : errors) { + builder.append("\n"); + builder.append(exception.getMessage()); + } + builder.append("Warnings occurred:"); + for (final Exception exception : warnings) { builder.append("\n"); builder.append(exception.getMessage()); } Messages.showErrorDialog(builder.toString(), "Execution Error"); return; } - for (final Exception exception : exceptionList) { - String[] messages = StringUtil.splitByLines(exception.getMessage()); - if (messages.length == 0) messages = new String[]{"Unknown Error"}; - errorTreeView.addMessage(MessageCategory.ERROR, messages, file, -1, -1, null); - } + + addMessages(MessageCategory.ERROR, errors, errorTreeView, file, "Unknown Error"); + addMessages(MessageCategory.WARNING, warnings, errorTreeView, file, "Unknown Warning"); ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.MESSAGES_WINDOW).activate(null); } }); } + private static void addMessages( + final int messageCategory, + @NotNull final List exceptions, + @NotNull ErrorViewPanel errorTreeView, + @NotNull final VirtualFile file, + @NotNull final String defaultMessage) + { + for (final Exception exception : exceptions) { + String[] messages = StringUtil.splitByLines(exception.getMessage()); + if (messages.length == 0) { + messages = new String[] { defaultMessage }; + } + errorTreeView.addMessage(messageCategory, messages, file, -1, -1, null); + } + } + public static void showOutput(@NotNull final Project myProject, @NotNull final Output output, @NotNull final String tabDisplayName, @@ -171,7 +203,7 @@ public class ExecutionHelper { } else { errorTreeView.addMessage(MessageCategory.SIMPLE, new String[]{stderrTitle}, file, -1, -1, null); - errorTreeView.addMessage(MessageCategory.SIMPLE, new String[0], file, -1, -1, null); + errorTreeView.addMessage(MessageCategory.SIMPLE, ArrayUtil.EMPTY_STRING_ARRAY, file, -1, -1, null); errorTreeView.addMessage(MessageCategory.SIMPLE, stderrLines, file, -1, -1, null); } }