mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
make tests stoppable via IDEA 'Stop' button on unix (don't wait forever in a shutdown hook)
This commit is contained in:
+10
-19
@@ -71,7 +71,6 @@ import org.picocontainer.MutablePicoContainer;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
@@ -245,25 +244,17 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
|
||||
if (isDisposed() || isDisposeInProgress()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManagerEx.setApplication(ApplicationImpl.this);
|
||||
try {
|
||||
saveAll();
|
||||
}
|
||||
finally {
|
||||
disposeSelf();
|
||||
}
|
||||
ShutDownTracker.invokeAndWait(isUnitTestMode(), new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManagerEx.setApplication(ApplicationImpl.this);
|
||||
try {
|
||||
saveAll();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
finally {
|
||||
disposeSelf();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -683,7 +683,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
ShutDownTracker.getInstance().registerShutdownTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
ShutDownTracker.invokeAndWait(true, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
closeAndDeleteProject();
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
package com.intellij.openapi.util;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -127,4 +129,27 @@ public class ShutDownTracker implements Runnable {
|
||||
private synchronized <T> T removeLast(LinkedList<T> list) {
|
||||
return list.isEmpty()? null : list.removeLast();
|
||||
}
|
||||
|
||||
public static void invokeAndWait(boolean timed, Runnable runnable) {
|
||||
if (timed) {
|
||||
final Semaphore semaphore = new Semaphore();
|
||||
semaphore.down();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
semaphore.up();
|
||||
}
|
||||
});
|
||||
if (!semaphore.waitFor(1000)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(runnable);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user