From f4edcefe2528a4a81f8303c373747e1fffd23f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Thu, 21 Nov 2013 12:07:18 +0100 Subject: [PATCH 1/3] add FinderRecursivePanel#isEditable() --- .../src/com/intellij/ui/FinderRecursivePanel.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/ui/FinderRecursivePanel.java b/platform/platform-impl/src/com/intellij/ui/FinderRecursivePanel.java index 38d3f6c17baa..68939f076993 100644 --- a/platform/platform-impl/src/com/intellij/ui/FinderRecursivePanel.java +++ b/platform/platform-impl/src/com/intellij/ui/FinderRecursivePanel.java @@ -146,6 +146,10 @@ public abstract class FinderRecursivePanel extends JBSplitter implements Data return null; } + protected boolean isEditable() { + return getSelectedValue() != null; + } + @Nullable protected JComponent createRightComponent(T t) { return new JPanel(); @@ -245,7 +249,7 @@ public abstract class FinderRecursivePanel extends JBSplitter implements Data @Override public void update(AnActionEvent e) { - e.getPresentation().setEnabled(getSelectedValue() != null); + e.getPresentation().setEnabled(isEditable()); } @Override From 3fd7878004d14b8dcd7ce602ae34c20bedd40ab3 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 21 Nov 2013 12:23:53 +0100 Subject: [PATCH 2/3] better method naming, assertion conditions correction; reliably process events posted to debugger manager thread on its termination --- .../engine/DebuggerManagerThreadImpl.java | 9 +-- .../intellij/debugger/impl/EventQueue.java | 5 +- .../intellij/debugger/impl/InvokeThread.java | 74 ++++++++++--------- 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java index df7a6d3854ef..4f4eb3f3ffc2 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java @@ -64,9 +64,7 @@ public class DebuggerManagerThreadImpl extends InvokeAndWaitThread { return myCurrentEvent; } + @NotNull public List clearQueue() { final List allEvents = new ArrayList(); for (int i = 0; i < myEvents.length; i++) { final LinkedList eventList = getEventsList(i); - while (!eventList.isEmpty()) { - allEvents.add(eventList.poll()); + for (E event = eventList.poll(); event != null; event = eventList.poll()) { + allEvents.add(event); } } return allEvents; diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java b/java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java index 804799dd9301..8e782c5ac0a0 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java @@ -20,7 +20,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.sun.jdi.VMDisconnectedException; import org.jetbrains.annotations.NotNull; -import java.util.List; import java.util.concurrent.*; /** @@ -60,14 +59,14 @@ public abstract class InvokeThread { } } - public void interrupt() { + public void requestStop() { final Future future = myRequestFuture; assert future != null; myStopRequested = true; future.cancel(true); } - public boolean isInterrupted() { + public boolean isStopRequested() { final Future future = myRequestFuture; assert future != null; return myStopRequested || future.isCancelled() || future.isDone(); @@ -127,51 +126,58 @@ public abstract class InvokeThread { workerRequest.setRequestFuture( ApplicationManager.getApplication().executeOnPooledThread(workerRequest) ); } - private void run(@NotNull WorkerThreadRequest threadRequest) { - while(true) { - try { - if(threadRequest.isInterrupted()) { + private void run(final @NotNull WorkerThreadRequest threadRequest) { + try { + while(true) { + try { + if(threadRequest.isStopRequested()) { + break; + } + + final WorkerThreadRequest currentRequest = getCurrentRequest(); + if(currentRequest != threadRequest) { + LOG.error("Expected " + threadRequest + " instead of " + currentRequest); + if (currentRequest != null && !currentRequest.isDone()) { + continue; // ensure events are processed by one thread at a time + } + } + + processEvent(myEvents.get()); + } + catch (VMDisconnectedException e) { break; } - - final WorkerThreadRequest currentRequest = getCurrentRequest(); - if(currentRequest != threadRequest) { - LOG.error("Expected " + threadRequest + " instead of " + currentRequest); - if (currentRequest != null && !currentRequest.isDone()) { - continue; // ensure events are processed by one thread at a time + catch (EventQueueClosedException e) { + break; + } + catch (RuntimeException e) { + if(e.getCause() instanceof InterruptedException) { + break; } + LOG.error(e); + } + catch (Throwable e) { + LOG.error(e); } - - processEvent(myEvents.get()); } - catch (VMDisconnectedException e) { - break; - } - catch (EventQueueClosedException e) { - final List unprocessed = myEvents.clearQueue(); - for (E event : unprocessed) { + } + finally { + // ensure that all scheduled events are processed + if (threadRequest == getCurrentRequest()) { + for (E event : myEvents.clearQueue()) { try { processEvent(event); } catch (Throwable ignored) { } } - break; } - catch (RuntimeException e) { - if(e.getCause() instanceof InterruptedException) { - break; - } - LOG.error(e); - } - catch (Throwable e) { - LOG.error(e); + + if (LOG.isDebugEnabled()) { + LOG.debug("Request " + this.toString() + " exited"); } } - if (LOG.isDebugEnabled()) { - LOG.debug("Request " + this.toString() + " exited"); - } } protected static InvokeThread currentThread() { @@ -201,7 +207,7 @@ public abstract class InvokeThread { LOG.debug("Closing " + currentThreadRequest + " new request = " + newRequest); } - currentThreadRequest.interrupt(); + currentThreadRequest.requestStop(); } public WorkerThreadRequest getCurrentRequest() { From 2e9d7faea8090f39d8fdb2b719cf6ecb609cf988 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Thu, 21 Nov 2013 15:30:30 +0400 Subject: [PATCH 3/3] IDEA-116833 External System: clear orphan project libraries --- .../openapi/externalSystem/util/ExternalSystemApiUtil.java | 4 ++++ .../openapi/externalSystem/util/ExternalSystemUtil.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java index 5f57702dc39f..b846199e1059 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/util/ExternalSystemApiUtil.java @@ -181,6 +181,10 @@ public class ExternalSystemApiUtil { return getLibraryName(library).equals(getLibraryName(libraryData)); } + public static boolean isExternalSystemLibrary(@NotNull Library library, @NotNull ProjectSystemId externalSystemId) { + return library.getName() != null && StringUtil.startsWith(library.getName(), externalSystemId.getReadableName() + ": "); + } + @Nullable public static ArtifactInfo parseArtifactInfo(@NotNull String fileName) { Matcher matcher = ARTIFACT_PATTERN.matcher(fileName); diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/ExternalSystemUtil.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/ExternalSystemUtil.java index 3c4d5b1d5697..d998a99dcc68 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/ExternalSystemUtil.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/util/ExternalSystemUtil.java @@ -272,7 +272,7 @@ public class ExternalSystemUtil { LibraryTable projectLibraryTable = platformFacade.getProjectLibraryTable(project); for (Library library : projectLibraryTable.getLibraries()) { - if (library.getName() == null || !StringUtil.startsWith(library.getName(), externalSystemId.getReadableName() + ": ")) continue; + if (!ExternalSystemApiUtil.isExternalSystemLibrary(library, externalSystemId)) continue; if (ProjectStructureHelper.isOrphanProjectLibrary(library, platformFacade.getModules(project))) { orphanIdeLibraries.add(library); }