Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dmitry Trofimov
2013-11-21 13:20:16 +01:00
6 changed files with 57 additions and 43 deletions
@@ -64,9 +64,7 @@ public class DebuggerManagerThreadImpl extends InvokeAndWaitThread<DebuggerComma
}
public void invokeAndWait(DebuggerCommandImpl managerCommand) {
LOG.assertTrue(!ApplicationManager.getApplication().isDispatchThread());
LOG.assertTrue(!(currentThread() instanceof DebuggerManagerThreadImpl),
"Should be invoked outside manager thread, use DebuggerManagerThreadImpl.getInstance(..).invoke...");
LOG.assertTrue(!isManagerThread(), "Should be invoked outside manager thread, use DebuggerManagerThreadImpl.getInstance(..).invoke...");
super.invokeAndWait(managerCommand);
}
@@ -112,7 +110,7 @@ public class DebuggerManagerThreadImpl extends InvokeAndWaitThread<DebuggerComma
try {
if (currentCommand == myEvents.getCurrentEvent()) {
// if current command is still in progress, cancel it
getCurrentRequest().interrupt();
getCurrentRequest().requestStop();
try {
getCurrentRequest().join();
}
@@ -181,6 +179,7 @@ public class DebuggerManagerThreadImpl extends InvokeAndWaitThread<DebuggerComma
public void startLongProcessAndFork(Runnable process) {
assertIsManagerThread();
startNewWorkerThread();
try {
@@ -202,7 +201,7 @@ public class DebuggerManagerThreadImpl extends InvokeAndWaitThread<DebuggerComma
if (LOG.isDebugEnabled()) {
LOG.debug("Event queue was closed, killing request");
}
request.interrupt();
request.requestStop();
}
});
}
@@ -137,12 +137,13 @@ public class EventQueue<E> {
return myCurrentEvent;
}
@NotNull
public List<E> clearQueue() {
final List<E> allEvents = new ArrayList<E>();
for (int i = 0; i < myEvents.length; i++) {
final LinkedList<E> 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;
@@ -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<E extends PrioritizedTask> {
}
}
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<E extends PrioritizedTask> {
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<E> 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<E extends PrioritizedTask> {
LOG.debug("Closing " + currentThreadRequest + " new request = " + newRequest);
}
currentThreadRequest.interrupt();
currentThreadRequest.requestStop();
}
public WorkerThreadRequest getCurrentRequest() {
@@ -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);
@@ -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);
}
@@ -146,6 +146,10 @@ public abstract class FinderRecursivePanel<T> 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<T> extends JBSplitter implements Data
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(getSelectedValue() != null);
e.getPresentation().setEnabled(isEditable());
}
@Override