Search in sources :

Example 16 with ProcessInfo

use of com.intellij.execution.process.ProcessInfo 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 17 with ProcessInfo

use of com.intellij.execution.process.ProcessInfo 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)

Example 18 with ProcessInfo

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

the class AttachToLocalProcessActionTest method testHistory_UpdatingPreviousItems.

public void testHistory_UpdatingPreviousItems() throws Exception {
    TestAttachGroup group1 = new TestAttachGroup("group1", 1);
    TestAttachGroup group2 = new TestAttachGroup("group2", 2);
    ProcessInfo info1 = new ProcessInfo(1, "same command line", "exec1", "args1");
    ProcessInfo info2 = new ProcessInfo(2, "same command line", "exec2", "args2");
    UserDataHolderBase dataHolder = new UserDataHolderBase();
    AttachItem item1 = new AttachItem(group1, true, info1, createDebuggers("gdb1"), dataHolder);
    AttachItem item2 = new AttachItem(group2, true, info2, createDebuggers("gdb2"), dataHolder);
    HistoryItem historyItem1 = new HistoryItem(info1, group1, "gdb1");
    HistoryItem historyItem2 = new HistoryItem(info2, group2, "gdb2");
    addToHistory(getProject(), item1);
    assertOrderedEquals(getHistory(getProject()), historyItem1);
    addToHistory(getProject(), item2);
    assertOrderedEquals(getHistory(getProject()), historyItem2);
}
Also used : UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) ProcessInfo(com.intellij.execution.process.ProcessInfo)

Example 19 with ProcessInfo

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

the class AttachToLocalProcessActionTest method assertItems.

private void assertItems(String expected, @NotNull XLocalAttachDebuggerProvider... providers) {
    ProcessInfo[] infos = { new ProcessInfo(1, "command line 1", "exec1", "args1"), new ProcessInfo(2, "command line 2", "exec2", "args2") };
    assertItems(expected, infos, providers);
}
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