From e9e9ebba9c02544c0aeb549824962eec4c6898e2 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 8 Nov 2012 21:52:36 +0400 Subject: [PATCH] Exceptions are reported through message collector This will later allow us to move this code to a separate module, where loggers are not available --- .../jet/plugin/compiler/CompilerUtils.java | 18 ++++++++---------- .../jet/plugin/compiler/JetCompiler.java | 2 +- .../compiler/MessageCollectorAdapter.java | 6 ++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java b/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java index f76c5deb80c..c31a99c6327 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/CompilerUtils.java @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableMap; import com.intellij.compiler.impl.javaCompiler.OutputItemImpl; import com.intellij.openapi.compiler.CompileContext; import com.intellij.openapi.compiler.TranslatingCompiler; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; @@ -31,6 +30,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; import org.jetbrains.jet.cli.common.messages.MessageCollector; +import org.jetbrains.jet.cli.common.messages.MessageRenderer; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -55,7 +55,6 @@ import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.*; */ public final class CompilerUtils { private static SoftReference ourClassLoaderRef = new SoftReference(null); - static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.plugin.compiler.CompilerUtils"); private CompilerUtils() { } @@ -143,11 +142,10 @@ public final class CompilerUtils { FileUtil.loadTextAndClose(wrappingReader); } catch (IOException ioException) { - LOG.error(ioException); + reportException(messageCollector, ioException); } String message = stringBuilder.toString(); - LOG.error(message); - LOG.error(e); + reportException(messageCollector, new IllegalStateException(message, e)); messageCollector.report(ERROR, message, NO_LOCATION); } finally { @@ -155,7 +153,7 @@ public final class CompilerUtils { reader.close(); } catch (IOException e) { - LOG.error(e); + reportException(messageCollector, e); } } } @@ -255,10 +253,6 @@ public final class CompilerUtils { } String text = message.toString(); - if ("exception".equals(qNameLowerCase)) { - LOG.error(text); - } - if (category == LOGGING) { collector.learn(text); } @@ -332,5 +326,9 @@ public final class CompilerUtils { parseCompilerMessagesFromReader(messageCollector, reader, outputItemsCollector); handleProcessTermination(exitCode, messageCollector); } + + static void reportException(@NotNull MessageCollector messageCollector, @NotNull Throwable e) { + messageCollector.report(EXCEPTION, MessageRenderer.PLAIN.renderException(e), NO_LOCATION); + } } diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java index 12866c6dc4c..cc410c7fdb6 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java @@ -251,7 +251,7 @@ public class JetCompiler implements TranslatingCompiler { return CompilerUtils.getReturnCodeFromObject(rc); } catch (Throwable e) { - CompilerUtils.LOG.error(e); + CompilerUtils.reportException(messageCollector, e); return -1; } } diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/MessageCollectorAdapter.java b/idea/src/org/jetbrains/jet/plugin/compiler/MessageCollectorAdapter.java index dba231f86ee..a103b11e5c0 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/MessageCollectorAdapter.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/MessageCollectorAdapter.java @@ -18,6 +18,7 @@ package org.jetbrains.jet.plugin.compiler; import com.intellij.openapi.compiler.CompileContext; import com.intellij.openapi.compiler.CompilerMessageCategory; +import com.intellij.openapi.diagnostic.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; @@ -26,6 +27,8 @@ import org.jetbrains.jet.cli.common.messages.MessageCollector; import static com.intellij.openapi.compiler.CompilerMessageCategory.*; class MessageCollectorAdapter implements MessageCollector { + private static final Logger LOG = Logger.getInstance(MessageCollectorAdapter.class); + private final CompileContext compileContext; public MessageCollectorAdapter(CompileContext compileContext) { @@ -40,6 +43,9 @@ class MessageCollectorAdapter implements MessageCollector { ) { CompilerMessageCategory category = category(severity); compileContext.addMessage(category, message, location.getPath(), location.getLine(), location.getColumn()); + if (severity == CompilerMessageSeverity.EXCEPTION) { + LOG.error(message); + } if (category == STATISTICS) { compileContext.getProgressIndicator().setText(message); }