Beispiel #1
0
  private static void runOutOfProcess(
      CompileContext compileContext, VirtualFile outputDir, File kotlinHome, File scriptFile) {
    final SimpleJavaParameters params = new SimpleJavaParameters();
    params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
    params.setMainClass("org.jetbrains.jet.cli.KotlinCompiler");
    params.getProgramParametersList().add("-module", scriptFile.getAbsolutePath());
    params.getProgramParametersList().add("-output", path(outputDir));
    params.getProgramParametersList().add("-tags");

    for (File jar : kompilerClasspath(kotlinHome, compileContext)) {
      params.getClassPath().add(jar);
    }

    params.getVMParametersList().addParametersString("-Djava.awt.headless=true -Xmx512m");
    //        params.getVMParametersList().addParametersString("-agentlib:yjpagent=sampling");

    Sdk sdk = params.getJdk();

    final GeneralCommandLine commandLine =
        JdkUtil.setupJVMCommandLine(
            ((JavaSdkType) sdk.getSdkType()).getVMExecutablePath(sdk), params, false);

    compileContext.addMessage(
        INFORMATION, "Invoking out-of-process compiler with arguments: " + commandLine, "", -1, -1);

    try {
      final OSProcessHandler processHandler =
          new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString()) {
            @Override
            public Charset getCharset() {
              return commandLine.getCharset();
            }
          };

      ProcessAdapter processListener = createProcessListener(compileContext);
      processHandler.addProcessListener(processListener);

      processHandler.startNotify();
      processHandler.waitFor();
    } catch (Exception e) {
      compileContext.addMessage(ERROR, "[Internal Error] " + e.getLocalizedMessage(), "", -1, -1);
      return;
    }
  }