Search in sources :

Example 1 with XLocalAttachDebugger

use of com.intellij.xdebugger.attach.XLocalAttachDebugger in project intellij-community by JetBrains.

the class AttachToLocalProcessActionTest method testHistoryGroup.

public void testHistoryGroup() throws Exception {
    TestAttachGroup group1 = new TestAttachGroup("group1", 1);
    TestAttachGroup group2 = new TestAttachGroup("group2", 2);
    List<XLocalAttachDebugger> debuggers1 = createDebuggers("gdb1", "lldb1");
    List<XLocalAttachDebugger> debuggers2 = createDebuggers("gdb2", "lldb2");
    List<AttachItem> originalItems = collectAttachItems(getProject(), new ProcessInfo[] { new ProcessInfo(1, "command line 1", "exec1", "args1"), new ProcessInfo(2, "command line 2", "exec2", "args2") }, DumbProgressIndicator.INSTANCE, new TestDebuggerProvider(1, group1, debuggers1), new TestDebuggerProvider(2, group2, debuggers2));
    // one item in history
    addToHistory(getProject(), originalItems.get(0));
    assertItems("----Recent----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group2, debuggers2));
    // several items in history
    addToHistory(getProject(), originalItems.get(1));
    assertItems("----Recent----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group2, debuggers2));
    // put most recent item on top
    addToHistory(getProject(), originalItems.get(0));
    assertItems("----Recent----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group2, debuggers2));
    // put debugger used in history item on top
    addToHistory(getProject(), originalItems.get(0).getSubItems().get(1));
    addToHistory(getProject(), originalItems.get(1).getSubItems().get(1));
    assertItems("----Recent----\n" + "20 exec20: lldb2\n" + "    gdb2\n" + "    lldb2\n" + "10 exec10: lldb1\n" + "    gdb1\n" + "    lldb1\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group2, debuggers2));
    // filter unavailable history items
    assertItems("----Recent----\n" + "20 exec20: lldb2\n" + "    gdb2\n" + "    lldb2\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 10", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group2, debuggers2));
    assertItems("----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 10", "exec10", "args10"), new ProcessInfo(20, "command line 20", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group2, debuggers2));
    // history items available again:
    assertItems("----Recent----\n" + "20 exec20: lldb2\n" + "    gdb2\n" + "    lldb2\n" + "10 exec10: lldb1\n" + "    gdb1\n" + "    lldb1\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group2, debuggers2));
    // filter items from history by suitable group
    assertItems("----Recent----\n" + "10 exec10: lldb1\n" + "    gdb1\n" + "    lldb1\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group1, debuggers2));
    assertItems("----Recent----\n" + "20 exec20: lldb2\n" + "    gdb2\n" + "    lldb2\n" + "----group2----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group2, debuggers1), new TestDebuggerProvider(20, group2, debuggers2));
    // filter by group equality, not by name
    assertItems("----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, new TestAttachGroup(group1.getGroupName(), group1.getOrder()), debuggers1), new TestDebuggerProvider(20, new TestAttachGroup(group2.getGroupName(), group2.getOrder()), debuggers2));
    // filter items from history by available debugger
    assertItems("----Recent----\n" + "10 exec10: lldb1\n" + "    gdb1\n" + "    lldb1\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb1\n" + "    gdb1\n" + "    lldb1\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, debuggers1), new TestDebuggerProvider(20, group2, debuggers1));
    // filter debuggers by name, not by equality
    assertItems("----Recent----\n" + "20 exec20: lldb2\n" + "    gdb2\n" + "    lldb2\n" + "10 exec10: lldb1\n" + "    gdb1\n" + "    lldb1\n" + "----group1----\n" + "10 exec10: gdb1\n" + "    gdb1\n" + "    lldb1\n" + "----group2----\n" + "20 exec20: gdb2\n" + "    gdb2\n" + "    lldb2\n", new ProcessInfo[] { new ProcessInfo(10, "command line 1", "exec10", "args10"), new ProcessInfo(20, "command line 2", "exec20", "args20") }, new TestDebuggerProvider(10, group1, createDebuggers("gdb1", "lldb1")), new TestDebuggerProvider(20, group2, createDebuggers("gdb2", "lldb2")));
}
Also used : XLocalAttachDebugger(com.intellij.xdebugger.attach.XLocalAttachDebugger) ProcessInfo(com.intellij.execution.process.ProcessInfo)

Example 2 with XLocalAttachDebugger

use of com.intellij.xdebugger.attach.XLocalAttachDebugger in project intellij-community by JetBrains.

the class AttachToLocalProcessAction method collectAttachItems.

@NotNull
public static List<AttachItem> collectAttachItems(@NotNull final Project project, @NotNull ProcessInfo[] processList, @NotNull ProgressIndicator indicator, @NotNull XLocalAttachDebuggerProvider... providers) {
    MultiMap<XLocalAttachGroup, Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>>> groupWithItems = new MultiMap<>();
    UserDataHolderBase dataHolder = new UserDataHolderBase();
    for (ProcessInfo eachInfo : processList) {
        MultiMap<XLocalAttachGroup, XLocalAttachDebugger> groupsWithDebuggers = new MultiMap<>();
        for (XLocalAttachDebuggerProvider eachProvider : providers) {
            indicator.checkCanceled();
            groupsWithDebuggers.putValues(eachProvider.getAttachGroup(), eachProvider.getAvailableDebuggers(project, eachInfo, dataHolder));
        }
        for (XLocalAttachGroup eachGroup : groupsWithDebuggers.keySet()) {
            Collection<XLocalAttachDebugger> debuggers = groupsWithDebuggers.get(eachGroup);
            if (!debuggers.isEmpty()) {
                groupWithItems.putValue(eachGroup, Pair.create(eachInfo, new ArrayList<>(debuggers)));
            }
        }
    }
    ArrayList<XLocalAttachGroup> sortedGroups = new ArrayList<>(groupWithItems.keySet());
    sortedGroups.sort(Comparator.comparingInt(XLocalAttachGroup::getOrder));
    List<AttachItem> currentItems = new ArrayList<>();
    for (final XLocalAttachGroup eachGroup : sortedGroups) {
        List<Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>>> sortedItems = new ArrayList<>(groupWithItems.get(eachGroup));
        sortedItems.sort((a, b) -> eachGroup.compare(project, a.first, b.first, dataHolder));
        boolean first = true;
        for (Pair<ProcessInfo, ArrayList<XLocalAttachDebugger>> eachItem : sortedItems) {
            currentItems.add(new AttachItem(eachGroup, first, eachItem.first, eachItem.second, dataHolder));
            first = false;
        }
    }
    List<AttachItem> currentHistoryItems = new ArrayList<>();
    List<HistoryItem> history = getHistory(project);
    for (int i = history.size() - 1; i >= 0; i--) {
        HistoryItem eachHistoryItem = history.get(i);
        for (AttachItem eachCurrentItem : currentItems) {
            boolean isSuitableItem = eachHistoryItem.getGroup().equals(eachCurrentItem.getGroup()) && eachHistoryItem.getProcessInfo().getCommandLine().equals(eachCurrentItem.getProcessInfo().getCommandLine());
            if (!isSuitableItem)
                continue;
            List<XLocalAttachDebugger> debuggers = eachCurrentItem.getDebuggers();
            int selectedDebugger = -1;
            for (int j = 0; j < debuggers.size(); j++) {
                XLocalAttachDebugger eachDebugger = debuggers.get(j);
                if (eachDebugger.getDebuggerDisplayName().equals(eachHistoryItem.getDebuggerName())) {
                    selectedDebugger = j;
                    break;
                }
            }
            if (selectedDebugger == -1)
                continue;
            currentHistoryItems.add(new AttachItem(eachCurrentItem.getGroup(), currentHistoryItems.isEmpty(), XDebuggerBundle.message("xdebugger.attach.toLocal.popup.recent"), eachCurrentItem.getProcessInfo(), debuggers, selectedDebugger, dataHolder));
        }
    }
    currentHistoryItems.addAll(currentItems);
    return currentHistoryItems;
}
Also used : UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) ProcessInfo(com.intellij.execution.process.ProcessInfo) XLocalAttachDebugger(com.intellij.xdebugger.attach.XLocalAttachDebugger) MultiMap(com.intellij.util.containers.MultiMap) XLocalAttachGroup(com.intellij.xdebugger.attach.XLocalAttachGroup) XLocalAttachDebuggerProvider(com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with XLocalAttachDebugger

use of com.intellij.xdebugger.attach.XLocalAttachDebugger in project intellij-community by JetBrains.

the class AttachToLocalProcessActionTest method testHistory.

public void testHistory() throws Exception {
    ProcessInfo info1 = new ProcessInfo(1, "command line 1", "exec1", "args1");
    ProcessInfo info2 = new ProcessInfo(1, "command line 2", "exec1", "args1");
    ProcessInfo info3 = new ProcessInfo(1, "command line 3", "exec1", "args1");
    ProcessInfo info4 = new ProcessInfo(1, "command line 4", "exec1", "args1");
    ProcessInfo info5 = new ProcessInfo(1, "command line 5", "exec1", "args1");
    List<XLocalAttachDebugger> debuggers = createDebuggers("gdb");
    UserDataHolderBase dataHolder = new UserDataHolderBase();
    AttachItem item1 = new AttachItem(XLocalAttachGroup.DEFAULT, true, info1, debuggers, dataHolder);
    AttachItem item2 = new AttachItem(XLocalAttachGroup.DEFAULT, true, info2, debuggers, dataHolder);
    AttachItem item3 = new AttachItem(XLocalAttachGroup.DEFAULT, true, info3, debuggers, dataHolder);
    AttachItem item4 = new AttachItem(XLocalAttachGroup.DEFAULT, true, info4, debuggers, dataHolder);
    AttachItem item5 = new AttachItem(XLocalAttachGroup.DEFAULT, true, info5, debuggers, dataHolder);
    HistoryItem historyItem1 = new HistoryItem(info1, XLocalAttachGroup.DEFAULT, "gdb");
    HistoryItem historyItem2 = new HistoryItem(info2, XLocalAttachGroup.DEFAULT, "gdb");
    HistoryItem historyItem3 = new HistoryItem(info3, XLocalAttachGroup.DEFAULT, "gdb");
    HistoryItem historyItem4 = new HistoryItem(info4, XLocalAttachGroup.DEFAULT, "gdb");
    HistoryItem historyItem5 = new HistoryItem(info5, XLocalAttachGroup.DEFAULT, "gdb");
    // empty
    assertEmpty(getHistory(getProject()));
    // adding some items
    addToHistory(getProject(), item1);
    addToHistory(getProject(), item2);
    assertOrderedEquals(getHistory(getProject()), historyItem1, historyItem2);
    addToHistory(getProject(), item3);
    addToHistory(getProject(), item4);
    assertOrderedEquals(getHistory(getProject()), historyItem1, historyItem2, historyItem3, historyItem4);
    // limiting size to 4 items
    addToHistory(getProject(), item5);
    assertOrderedEquals(getHistory(getProject()), historyItem2, historyItem3, historyItem4, historyItem5);
    // popping up recent items
    addToHistory(getProject(), item3);
    addToHistory(getProject(), item2);
    assertOrderedEquals(getHistory(getProject()), historyItem4, historyItem5, historyItem3, historyItem2);
}
Also used : XLocalAttachDebugger(com.intellij.xdebugger.attach.XLocalAttachDebugger) UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) ProcessInfo(com.intellij.execution.process.ProcessInfo)

Aggregations

ProcessInfo (com.intellij.execution.process.ProcessInfo)3 XLocalAttachDebugger (com.intellij.xdebugger.attach.XLocalAttachDebugger)3 UserDataHolderBase (com.intellij.openapi.util.UserDataHolderBase)2 Pair (com.intellij.openapi.util.Pair)1 MultiMap (com.intellij.util.containers.MultiMap)1 XLocalAttachDebuggerProvider (com.intellij.xdebugger.attach.XLocalAttachDebuggerProvider)1 XLocalAttachGroup (com.intellij.xdebugger.attach.XLocalAttachGroup)1 NotNull (org.jetbrains.annotations.NotNull)1