public ClojureReplProcessHandler()

in src/java/org/jetbrains/plugins/clojure/repl/ClojureReplProcessHandler.java [98:159]


  public ClojureReplProcessHandler(String path, Module module)
      throws IOException, ConfigurationException, CantRunException {

    myExecPath = path;
    myModule = module;

    if (notConfigured()) {
      throw new ConfigurationException("Can't create Clojure REPL process");
    } else {
      // Only a single command line per-project is supported. We may need more flexibility
      //  in the future (e.g., different Clojure paths with different args)

      final JavaParameters params = new JavaParameters();
      params.configureByModule(myModule, JavaParameters.JDK_AND_CLASSES_AND_TESTS);
      // To avoid NCDFE while starting REPL

      final boolean sdkConfigured = ClojureConfigUtil.isClojureConfigured(myModule);
      if (!sdkConfigured) {
        final String jarPath = ClojureConfigUtil.CLOJURE_SDK;
        assert jarPath != null;
        params.getClassPath().add(jarPath);
      }

      Set<VirtualFile> cpVFiles = new HashSet<VirtualFile>();
      ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(myModule);
      OrderEntry[] entries = moduleRootManager.getOrderEntries();
      for (OrderEntry orderEntry : entries) {
        // Add module sources to classpath
        if (orderEntry instanceof ModuleSourceOrderEntry) {
          cpVFiles.addAll(Arrays.asList(orderEntry.getFiles(OrderRootType.SOURCES)));
        }
      }

      for (VirtualFile file : cpVFiles) {
        params.getClassPath().add(file.getPath());
      }


      params.setMainClass(ClojureUtils.CLOJURE_MAIN);
      params.setWorkingDirectory(path);

      final GeneralCommandLine line = CommandLineBuilder.createFromJavaParameters(params, PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext()), true);

      final Sdk sdk = params.getJdk();
      assert sdk != null;
      final SdkType type = (SdkType) sdk.getSdkType();
      final String executablePath = ((JavaSdkType) type).getVMExecutablePath(sdk);

      final ArrayList<String> env = new ArrayList<String>();
      final ArrayList<String> cmd = new ArrayList<String>();
      cmd.add(executablePath);
      cmd.addAll(line.getParametersList().getList());

      if (!sdkConfigured) {
        ClojureConfigUtil.warningDefaultClojureJar(myModule);
      }

      myProcess = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]),
          env.toArray(new String[env.size()]), new File(myExecPath));
      myWaitFor = new ProcessWaitFor(myProcess);
    }
  }