/** Create shell command. */ public String[] toShellCommand() { return ShellFactory.getShell().createShellCommand(this); }
static ProcessManager newInstance() { if (SystemInfo.isUnix()) { return new UnixProcessManager(); } return new DefaultProcessManager(); }
private static void readMavenVersionInformation(LineConsumer cmdOutput) throws IOException { final CommandLine commandLine = new CommandLine(getMavenExecCommand()).add("-version"); final ProcessBuilder processBuilder = new ProcessBuilder().command(commandLine.toShellCommand()).redirectErrorStream(true); final Process process = processBuilder.start(); ProcessUtil.process(process, cmdOutput, LineConsumer.DEV_NULL); } }
public static Shell getShell() { if (SystemInfo.isUnix()) { return new StandardLinuxShell(); } if (SystemInfo.isWindows()) { return new StandardWindowsShell(); } throw new IllegalStateException("Unsupported OS"); }
private void killTree(int pid) { final int[] children = getChildProcesses(pid); LOG.debug("PID: {}, child PIDs: {}", pid, children); if (children.length > 0) { for (int cpid : children) { killTree(cpid); // kill process tree recursively } } int r = C_LIBRARY.kill(pid, CLibrary.SIGKILL); // kill origin process LOG.debug("kill {}", pid); if (r != 0) { if (LOG.isDebugEnabled()) { LOG.debug("kill for {} returns {}, strerror '{}'", pid, r, C_LIBRARY.strerror(r)); } } }
private int lookupForward(int min, int max) { for (int port = min; port <= max; port++) { if (checkPort(port)) { return port; } } return -1; }
@Override public void close() throws IOException { lineConsumer.close(); }
@Override int system(String command) { return C_LIBRARY.system(command); } }
public static boolean isAlive(Process process) { return PROCESS_MANAGER.isAlive(process); }
/** * Get free port from the whole range of possible ports. * * @return free port or {@code -1} if there is no free port */ public int acquire() { return doAcquire(range.first, range.second); }
public static void kill(Process process) { PROCESS_MANAGER.kill(process); }
public static int system(String command) { return PROCESS_MANAGER.system(command); }
/** {@inheritDoc} */ @Override public void writeLine(String line) throws IOException { lineConsumer.writeLine(line + System.lineSeparator()); }
/** * Generates link header value based on given {@code page} and uri returned by {@code * uriInfo.getRequestUri()}. * * @param page page to create link header * @return link header value */ protected String createLinkHeader(Page<?> page) { return PagingUtil.createLinkHeader(page, uriInfo.getRequestUri()); }
@Override public String toString() { final String[] str = asArray(); final StringBuilder sb = new StringBuilder(); for (String s : str) { if (sb.length() > 1) { sb.append(' '); } sb.append(s); } return sb.toString(); } }
private int lookupBackward(int max, int min) { for (int port = max; port >= min; port--) { if (checkPort(port)) { return port; } } return -1; }
/** {@inheritDoc} */ @Override public void close() throws IOException { lineConsumer.close(); } }