/** * start gvim with args using a ProcessBuilder and setup {@link #vc VimConnection} . * * @param args */ private void start(String workingDir, boolean embedded, boolean tabbed, String... args) { if (!tabbed && vc != null && vc.isServerRunning()) { return; } VimPlugin plugin = VimPlugin.getDefault(); if (vc == null || !vc.isServerRunning()) { vc = new VimConnection(ID); t = new Thread(vc); t.setUncaughtExceptionHandler(new VimExceptionHandler()); t.setDaemon(true); t.start(); } try { logger.debug("Trying to start vim"); logger.debug(Arrays.toString(args)); ProcessBuilder builder = new ProcessBuilder(args); /*java.util.Map<String, String> env = builder.environment(); env.put("SPRO_GVIM_DEBUG", "/tmp/netbeans.log"); env.put("SPRO_GVIM_DLEVEL", "0xffffffff");*/ if (workingDir != null) { builder.directory(new File(workingDir)); } p = builder.start(); logger.debug("Started vim"); } catch (IOException e) { logger.error("error:", e); } // Waits until server starts.. vim should return startupDone long maxTime = System.currentTimeMillis() + 10000L; // 10 seconds while (!vc.isServerRunning()) { if (System.currentTimeMillis() >= maxTime) { try { vc.close(); } catch (Exception e) { logger.error("error:", e); } String message = plugin.getMessage("gvim.startup.failed", plugin.getMessage("gvim.startupDone.event")); throw new RuntimeException(message); } // sleep so that we don't have a messy cpu-hogging infinite loop // here long stoptime = 2000L; // 2 Seconds logger.debug("Waiting to connect to vim server"); try { Thread.sleep(stoptime); } catch (InterruptedException e) { e.printStackTrace(); } } this.embedded = embedded; }