Search in sources :

Example 1 with ProcessInfo

use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.

the class ProcessListUtil method parseListTasksOutput.

@Nullable
static List<ProcessInfo> parseListTasksOutput(@NotNull String output) {
    List<ProcessInfo> result = ContainerUtil.newArrayList();
    CSVReader reader = new CSVReader(new StringReader(output));
    try {
        String[] next;
        while ((next = reader.readNext()) != null) {
            if (next.length < 2)
                return null;
            int pid = StringUtil.parseInt(next[1], -1);
            if (pid == -1)
                continue;
            String name = next[0];
            if (name.isEmpty())
                continue;
            result.add(new ProcessInfo(pid, name, name, ""));
        }
    } catch (IOException e) {
        LOG.error("Cannot parse listtasks output", e);
        return null;
    } finally {
        try {
            reader.close();
        } catch (IOException ignore) {
        }
    }
    return result;
}
Also used : ProcessInfo(com.intellij.execution.process.ProcessInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ProcessInfo

use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.

the class ProcessListUtil method parseWinNativeHelperOutput.

private static List<ProcessInfo> parseWinNativeHelperOutput(String output) throws IllegalStateException {
    String[] strings = StringUtil.splitByLines(output, false);
    ArrayList<ProcessInfo> result = new ArrayList<>();
    int processCount = strings.length / 3;
    for (int i = 0; i < processCount; i++) {
        int offset = i * 3;
        int id = StringUtil.parseInt(strings[offset], -1);
        if (id == -1 || id == 0)
            continue;
        String name = strings[offset + 1];
        if (StringUtil.isEmpty(name))
            continue;
        String commandLine = strings[offset + 2];
        String args;
        if (commandLine.isEmpty()) {
            commandLine = name;
            args = "";
        } else {
            args = extractCommandLineArgs(commandLine, name);
        }
        result.add(new ProcessInfo(id, commandLine, name, args));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ProcessInfo(com.intellij.execution.process.ProcessInfo)

Example 3 with ProcessInfo

use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.

the class ProcessListUtil method parseMacOutput.

@Nullable
static List<ProcessInfo> parseMacOutput(String commandOnly, String full) {
    List<MacProcessInfo> commands = doParseMacOutput(commandOnly);
    List<MacProcessInfo> fulls = doParseMacOutput(full);
    if (commands == null || fulls == null)
        return null;
    TIntObjectHashMap<String> idToCommand = new TIntObjectHashMap<>();
    for (MacProcessInfo each : commands) {
        idToCommand.put(each.pid, each.commandLine);
    }
    List<ProcessInfo> result = new ArrayList<>();
    for (MacProcessInfo each : fulls) {
        if (!idToCommand.containsKey(each.pid))
            continue;
        String command = idToCommand.get(each.pid);
        if (!(each.commandLine.equals(command) || each.commandLine.startsWith(command + " ")))
            continue;
        String name = PathUtil.getFileName(command);
        String args = each.commandLine.substring(command.length()).trim();
        result.add(new ProcessInfo(each.pid, each.commandLine, name, args, command));
    }
    return result;
}
Also used : TIntObjectHashMap(gnu.trove.TIntObjectHashMap) ArrayList(java.util.ArrayList) ProcessInfo(com.intellij.execution.process.ProcessInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ProcessInfo

use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.

the class ProcessListTest method testMac_DoNotIncludeZombies.

public void testMac_DoNotIncludeZombies() throws Exception {
    List<ProcessInfo> infos = ProcessListUtil.parseMacOutput("   PID STAT USER    COMM\n\n" + "     1 S    user    /dir/file\n" + "     2 Z    user    /dir/file\n" + "     3 SZ   user    /dir/file\n", "   PID STAT USER    COMMAND\n\n" + "     1 S    user    /dir/file\n" + "     2 Z    user    /dir/file\n" + "     3 SZ   user    /dir/file\n");
    assertOrderedEquals(infos, new ProcessInfo(1, "/dir/file", "file", "", "/dir/file"));
}
Also used : ProcessInfo(com.intellij.execution.process.ProcessInfo)

Example 5 with ProcessInfo

use of com.intellij.execution.process.ProcessInfo in project intellij-community by JetBrains.

the class ProcessListTest method testMac_Basic.

public void testMac_Basic() throws Exception {
    List<ProcessInfo> infos = ProcessListUtil.parseMacOutput("   PID STAT USER    COMM\n\n" + "     1 S    user    /dir/file\n" + "     2 S    user    ./dir/dir/file\n" + "     3 S    user    ./dir/dir/file\n", "   PID STAT USER    COMMAND\n\n" + "     1 S    user    /dir/file\n" + "     2 S    user    ./dir/dir/file\n" + "     3 S    user    ./dir/dir/file param param");
    assertOrderedEquals(infos, new ProcessInfo(1, "/dir/file", "file", "", "/dir/file"), new ProcessInfo(2, "./dir/dir/file", "file", "", "./dir/dir/file"), new ProcessInfo(3, "./dir/dir/file param param", "file", "param param", "./dir/dir/file"));
}
Also used : ProcessInfo(com.intellij.execution.process.ProcessInfo)

Aggregations

ProcessInfo (com.intellij.execution.process.ProcessInfo)19 Nullable (org.jetbrains.annotations.Nullable)4 UserDataHolderBase (com.intellij.openapi.util.UserDataHolderBase)3 XLocalAttachDebugger (com.intellij.xdebugger.attach.XLocalAttachDebugger)3 ArrayList (java.util.ArrayList)3 Pair (com.intellij.openapi.util.Pair)1 MultiMap (com.intellij.util.containers.MultiMap)1 LinkedHashMap (com.intellij.util.containers.hash.LinkedHashMap)1 XLocalAttachDebuggerProvider (com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider)1 XLocalAttachGroup (com.intellij.xdebugger.attach.XLocalAttachGroup)1 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)1 NotNull (org.jetbrains.annotations.NotNull)1