@SuppressWarnings("UseOfSystemOutOrSystemErr")
  private static void runGroovycInThisProcess(ClassLoader loader,
                                              boolean forStubs,
                                              CompileContext context,
                                              File tempFile,
                                              final GroovycOutputParser parser,
                                              @Nullable String byteCodeTargetLevel,
                                              @Nullable Queue<? super Object> mailbox,
                                              boolean sharedPool) throws IOException {
    PrintStream oldOut = sharedPool ? null : System.out;
    PrintStream oldErr = sharedPool? null : System.err;
    ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();

    PrintStream out = createStream(parser, ProcessOutputTypes.STDOUT, oldOut);
    PrintStream err = createStream(parser, ProcessOutputTypes.STDERR, oldErr);
    if (!sharedPool) {
      System.setOut(out);
      System.setErr(err);
    }
    Thread.currentThread().setContextClassLoader(loader);
    try {
      Class<?> runnerClass = loader.loadClass("org.jetbrains.groovy.compiler.rt.GroovycRunner");
      Method intMain = runnerClass.getDeclaredMethod("intMain2",
                                                     boolean.class, boolean.class, boolean.class,
                                                     String.class, String.class, String.class,
                                                     Queue.class, PrintStream.class, PrintStream.class);
      JpsGroovySettings groovySettings = JpsGroovycRunner.getGroovyCompilerSettings(context);
      Integer exitCode = (Integer)intMain.invoke(null,
                                                 groovySettings.invokeDynamic, false, forStubs,
                                                 tempFile.getPath(), groovySettings.configScript, byteCodeTargetLevel,
                                                 mailbox, out, err);
      parser.notifyFinished(exitCode);
    }
    catch (Exception e) {
      throw new RuntimeException(e);
    }
    finally {
      out.flush();
      err.flush();

      if (!sharedPool) {
        System.setOut(oldOut);
        System.setErr(oldErr);
      }
      Thread.currentThread().setContextClassLoader(oldLoader);
    }
  }
@SuppressWarnings("UseOfSystemOutOrSystemErr")
  private static void runGroovycInThisProcess(ClassLoader loader,
                                              boolean forStubs,
                                              CompileContext context,
                                              File tempFile,
                                              final GroovycOutputParser parser,
                                              @Nullable String byteCodeTargetLevel,
                                              @Nullable Queue<? super Object> mailbox,
                                              boolean sharedPool)