Search in sources :

Example 6 with UserDataHolderBase

use of com.intellij.openapi.util.UserDataHolderBase in project intellij-community by JetBrains.

the class ExternalDiffTool method collectRequests.

@NotNull
private static List<DiffRequest> collectRequests(@Nullable Project project, @NotNull final DiffRequestChain chain, @NotNull ProgressIndicator indicator) {
    List<DiffRequest> requests = new ArrayList<>();
    UserDataHolderBase context = new UserDataHolderBase();
    List<String> errorRequests = new ArrayList<>();
    // TODO: show all changes on explicit selection
    List<? extends DiffRequestProducer> producers = Collections.singletonList(chain.getRequests().get(chain.getIndex()));
    for (DiffRequestProducer producer : producers) {
        try {
            requests.add(producer.process(context, indicator));
        } catch (DiffRequestProducerException e) {
            LOG.warn(e);
            errorRequests.add(producer.getName());
        }
    }
    if (!errorRequests.isEmpty()) {
        new Notification("diff", "Can't load some changes", StringUtil.join(errorRequests, "<br>"), NotificationType.ERROR).notify(project);
    }
    return requests;
}
Also used : DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) ArrayList(java.util.ArrayList) ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) DiffRequestProducer(com.intellij.diff.chains.DiffRequestProducer) Notification(com.intellij.notification.Notification) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with UserDataHolderBase

use of com.intellij.openapi.util.UserDataHolderBase 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 8 with UserDataHolderBase

use of com.intellij.openapi.util.UserDataHolderBase 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 9 with UserDataHolderBase

use of com.intellij.openapi.util.UserDataHolderBase 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)

Aggregations

UserDataHolderBase (com.intellij.openapi.util.UserDataHolderBase)9 ProcessInfo (com.intellij.execution.process.ProcessInfo)3 XLocalAttachDebugger (com.intellij.xdebugger.attach.XLocalAttachDebugger)2 NotNull (org.jetbrains.annotations.NotNull)2 DiffRequestProducer (com.intellij.diff.chains.DiffRequestProducer)1 DiffRequestProducerException (com.intellij.diff.chains.DiffRequestProducerException)1 ContentDiffRequest (com.intellij.diff.requests.ContentDiffRequest)1 DiffRequest (com.intellij.diff.requests.DiffRequest)1 CantRunException (com.intellij.execution.CantRunException)1 ParametersList (com.intellij.execution.configurations.ParametersList)1 SimpleJavaParameters (com.intellij.execution.configurations.SimpleJavaParameters)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 Notification (com.intellij.notification.Notification)1 PluginId (com.intellij.openapi.extensions.PluginId)1 Module (com.intellij.openapi.module.Module)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 Pair (com.intellij.openapi.util.Pair)1 UserDataHolder (com.intellij.openapi.util.UserDataHolder)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 MultiMap (com.intellij.util.containers.MultiMap)1