diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java index faac526d8c9..fab64235c79 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerRunnerUtil.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.compiler.runner; -import com.intellij.util.Function; import kotlin.Function1; import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; @@ -27,7 +26,9 @@ import org.jetbrains.jet.preloading.ClassPreloadingUtils; import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.UtilsPackage; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; import java.lang.ref.SoftReference; import java.lang.reflect.Method; import java.net.MalformedURLException; @@ -114,12 +115,6 @@ public class CompilerRunnerUtil { ); } - private static void handleProcessTermination(int exitCode, @NotNull MessageCollector messageCollector) { - if (exitCode != 0 && exitCode != 1) { - messageCollector.report(ERROR, "Compiler terminated with exit code: " + exitCode, NO_LOCATION); - } - } - public static int getReturnCodeFromObject(@Nullable Object rc) throws Exception { if (rc == null) { return /* ExitCode.INTERNAL_ERROR */ 2; @@ -155,19 +150,4 @@ public class CompilerRunnerUtil { return exec.invoke(kompiler.newInstance(), out, environment.getServices(), arguments); } - - public static void outputCompilerMessagesAndHandleExitCode( - @NotNull MessageCollector messageCollector, - @NotNull OutputItemsCollector outputItemsCollector, - @NotNull Function compilerRun - ) { - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(outputStream); - - int exitCode = compilerRun.fun(out); - - BufferedReader reader = new BufferedReader(new StringReader(outputStream.toString())); - CompilerOutputParser.parseCompilerMessagesFromReader(messageCollector, reader, outputItemsCollector); - handleProcessTermination(exitCode, messageCollector); - } } diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java index df9e9f78bf5..9fe5923f9d8 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/KotlinCompilerRunner.java @@ -31,11 +31,13 @@ import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollectorUtil; import org.jetbrains.jet.compiler.CompilerSettings; -import java.io.File; -import java.io.PrintStream; +import java.io.*; import java.util.Collection; import java.util.List; +import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_LOCATION; +import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.ERROR; + public class KotlinCompilerRunner { private static final String K2JVM_COMPILER = "org.jetbrains.jet.cli.jvm.K2JVMCompiler"; private static final String K2JS_COMPILER = "org.jetbrains.jet.cli.js.K2JSCompiler"; @@ -77,23 +79,28 @@ public class KotlinCompilerRunner { } private static void runCompiler( - final String compilerClassName, + String compilerClassName, CommonCompilerArguments arguments, String additionalArguments, CommonCompilerArguments defaultArguments, - final MessageCollector messageCollector, + MessageCollector messageCollector, OutputItemsCollector collector, - final CompilerEnvironment environment + CompilerEnvironment environment ) { - final List argumentsList = ArgumentUtils.convertArgumentsToStringList(arguments, defaultArguments); + List argumentsList = ArgumentUtils.convertArgumentsToStringList(arguments, defaultArguments); argumentsList.addAll(StringUtil.split(additionalArguments, " ")); - CompilerRunnerUtil.outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function() { - @Override - public Integer fun(PrintStream stream) { - return execCompiler(compilerClassName, ArrayUtil.toStringArray(argumentsList), environment, stream, messageCollector); - } - }); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + PrintStream out = new PrintStream(stream); + + int exitCode = execCompiler(compilerClassName, ArrayUtil.toStringArray(argumentsList), environment, out, messageCollector); + + BufferedReader reader = new BufferedReader(new StringReader(stream.toString())); + CompilerOutputParser.parseCompilerMessagesFromReader(messageCollector, reader, collector); + + if (exitCode != 0 && exitCode != 1) { + messageCollector.report(ERROR, "Compiler terminated with internal error", NO_LOCATION); + } } private static int execCompiler(