From 41d0a8be242823e6db7efa0bf903fb6736a3b37e Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Thu, 10 Oct 2013 15:15:20 +0400 Subject: [PATCH] JPS: removed unnecessary code for running compiler out of process. --- .../compiler/runner/KotlinCompilerRunner.java | 107 +++--------------- .../jet/plugin/compiler/JetCompiler.java | 5 +- .../jet/jps/build/KotlinBuilder.java | 3 +- 3 files changed, 16 insertions(+), 99 deletions(-) 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 dc69dfad1cd..15978eccec1 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 @@ -16,26 +16,15 @@ package org.jetbrains.jet.compiler.runner; -import com.intellij.execution.configurations.GeneralCommandLine; -import com.intellij.execution.configurations.SimpleJavaParameters; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.projectRoots.JavaSdkType; -import com.intellij.openapi.projectRoots.JdkUtil; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.SimpleJavaSdkType; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.Function; -import com.intellij.util.SystemProperties; 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.MessageCollectorUtil; import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; import java.io.PrintStream; import java.util.*; @@ -47,17 +36,10 @@ public class KotlinCompilerRunner { MessageCollector messageCollector, CompilerEnvironment environment, File moduleFile, - OutputItemsCollector collector, - boolean runOutOfProcess + OutputItemsCollector collector ) { String[] arguments = createArgumentsForJvmCompiler(moduleFile); - - if (runOutOfProcess) { - runOutOfProcess(K2JVM_COMPILER, arguments, messageCollector, collector, environment); - } - else { - runInProcess(K2JVM_COMPILER, arguments, messageCollector, collector, environment); - } + runCompiler(K2JVM_COMPILER, arguments, messageCollector, collector, environment); } public static void runK2JsCompiler( @@ -69,24 +51,31 @@ public class KotlinCompilerRunner { File outputFile ) { String[] arguments = createArgumentsForJsCompiler(outputFile, sourceFiles, libraryFiles); - runInProcess(K2JS_COMPILER, arguments, messageCollector, collector, environment); + runCompiler(K2JS_COMPILER, arguments, messageCollector, collector, environment); } - private static void runInProcess( + private static void runCompiler( final String compilerClassName, final String[] arguments, final MessageCollector messageCollector, OutputItemsCollector collector, - final CompilerEnvironment environment) { + final CompilerEnvironment environment + ) { CompilerRunnerUtil.outputCompilerMessagesAndHandleExitCode(messageCollector, collector, new Function() { @Override public Integer fun(PrintStream stream) { - return execInProcess(compilerClassName, arguments, environment, stream, messageCollector); + return execCompiler(compilerClassName, arguments, environment, stream, messageCollector); } }); } - private static int execInProcess(String compilerClassName, String[] arguments, CompilerEnvironment environment, PrintStream out, MessageCollector messageCollector) { + private static int execCompiler( + String compilerClassName, + String[] arguments, + CompilerEnvironment environment, + PrintStream out, + MessageCollector messageCollector + ) { try { messageCollector.report(CompilerMessageSeverity.INFO, "Using kotlinHome=" + environment.getKotlinPaths().getHomePath(), @@ -142,72 +131,4 @@ public class KotlinCompilerRunner { return ArrayUtil.toStringArray(args); } - - private static void runOutOfProcess( - String compilerClassName, - String[] arguments, - final MessageCollector messageCollector, - final OutputItemsCollector itemCollector, - CompilerEnvironment environment - ) { - SimpleJavaParameters params = new SimpleJavaParameters(); - params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome())); - params.setMainClass(compilerClassName); - - for (String arg : arguments) { - params.getProgramParametersList().add(arg); - } - - for (File jar : CompilerRunnerUtil.kompilerClasspath(environment.getKotlinPaths(), messageCollector)) { - params.getClassPath().add(jar); - } - - params.getVMParametersList().addParametersString("-Djava.awt.headless=true -Xmx512m"); - // params.getVMParametersList().addParametersString("-agentlib:yjpagent=sampling"); - - Sdk sdk = params.getJdk(); - - assert sdk != null; - - GeneralCommandLine commandLine = JdkUtil.setupJVMCommandLine( - ((JavaSdkType) sdk.getSdkType()).getVMExecutablePath(sdk), params, false); - - messageCollector.report(CompilerMessageSeverity.INFO, - "Invoking out-of-process compiler with arguments: " + commandLine, - CompilerMessageLocation.NO_LOCATION); - - try { - final Process process = commandLine.createProcess(); - - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override - public void run() { - CompilerOutputParser - .parseCompilerMessagesFromReader(messageCollector, new InputStreamReader(process.getInputStream()), - itemCollector); - } - }); - - ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { - @Override - public void run() { - try { - FileUtil.loadBytes(process.getErrorStream()); - } - catch (IOException e) { - // Don't care - } - } - }); - - int exitCode = process.waitFor(); - CompilerRunnerUtil.handleProcessTermination(exitCode, messageCollector); - } - catch (Exception e) { - messageCollector.report(CompilerMessageSeverity.ERROR, - "[Internal Error] " + e.getLocalizedMessage(), - CompilerMessageLocation.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 b0319bfa224..8b6393b61d9 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/JetCompiler.java @@ -41,9 +41,6 @@ import java.io.IOException; import java.util.*; public class JetCompiler implements TranslatingCompiler { - - private static final boolean RUN_OUT_OF_PROCESS = false; - @Override public boolean isCompilableFile(VirtualFile virtualFile, CompileContext compileContext) { if (!(virtualFile.getFileType() instanceof JetFileType)) { @@ -136,7 +133,7 @@ public class JetCompiler implements TranslatingCompiler { File scriptFile, OutputItemsCollector outputItemsCollector ) { - KotlinCompilerRunner.runK2JvmCompiler(messageCollector, environment, scriptFile, outputItemsCollector, RUN_OUT_OF_PROCESS); + KotlinCompilerRunner.runK2JvmCompiler(messageCollector, environment, scriptFile, outputItemsCollector); } public static File tryToWriteScriptFile( diff --git a/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java b/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java index f3feaf01107..24f12b14800 100644 --- a/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java +++ b/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java @@ -152,8 +152,7 @@ public class KotlinBuilder extends ModuleLevelBuilder { messageCollector, environment, moduleFile, - outputItemCollector, - /*runOutOfProcess = */false); + outputItemCollector); } for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {