mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
memleak
This commit is contained in:
@@ -16,13 +16,12 @@
|
||||
package com.intellij.execution.junit;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.CommandLineBuilder;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.execution.junit2.segments.Extractor;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessTerminatedListener;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -35,17 +34,19 @@ public class JUnitProcessHandler extends OSProcessHandler {
|
||||
private final Extractor myErr;
|
||||
private final Charset myCharset;
|
||||
|
||||
public JUnitProcessHandler(final Process process, final String commandLine, final Charset charset) {
|
||||
public JUnitProcessHandler(@NotNull Process process, final String commandLine, @NotNull Charset charset) {
|
||||
super(process, commandLine);
|
||||
myOut = new Extractor(getProcess().getInputStream(), charset);
|
||||
myErr = new Extractor(getProcess().getErrorStream(), charset);
|
||||
myCharset = charset;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Reader createProcessOutReader() {
|
||||
return myOut.createReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Reader createProcessErrReader() {
|
||||
return myErr.createReader();
|
||||
}
|
||||
@@ -58,22 +59,29 @@ public class JUnitProcessHandler extends OSProcessHandler {
|
||||
return myOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Charset getCharset() {
|
||||
return myCharset;
|
||||
}
|
||||
|
||||
public static JUnitProcessHandler runJava(final JavaParameters javaParameters) throws ExecutionException {
|
||||
return runJava(javaParameters, null);
|
||||
}
|
||||
|
||||
public static JUnitProcessHandler runJava(final JavaParameters javaParameters, final Project project) throws ExecutionException {
|
||||
return runCommandLine(CommandLineBuilder.createFromJavaParameters(javaParameters, project, true));
|
||||
}
|
||||
|
||||
public static JUnitProcessHandler runCommandLine(final GeneralCommandLine commandLine) throws ExecutionException {
|
||||
final JUnitProcessHandler processHandler = new JUnitProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(),
|
||||
commandLine.getCharset());
|
||||
ProcessTerminatedListener.attach(processHandler);
|
||||
return processHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyProcessTerminated(int exitCode) {
|
||||
super.notifyProcessTerminated(exitCode);
|
||||
Disposer.dispose(myOut);
|
||||
Disposer.dispose(myErr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyProcessDetached() {
|
||||
super.notifyProcessDetached();
|
||||
Disposer.dispose(myOut);
|
||||
Disposer.dispose(myErr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,12 @@ package com.intellij.execution.junit2.segments;
|
||||
import com.intellij.execution.junit.SegmentedInputStreamReader;
|
||||
import com.intellij.execution.junit2.SegmentedInputStream;
|
||||
import com.intellij.execution.testframework.Printable;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.rt.execution.junit.segments.PacketProcessor;
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue;
|
||||
import com.intellij.util.ui.update.Update;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
@@ -30,24 +32,29 @@ import java.nio.charset.Charset;
|
||||
/**
|
||||
* @author dyoma
|
||||
*/
|
||||
public class Extractor {
|
||||
public class Extractor implements Disposable {
|
||||
private DeferredActionsQueue myFulfilledWorkGate = null;
|
||||
private final SegmentedInputStream myStream;
|
||||
private OutputPacketProcessor myEventsDispatcher;
|
||||
private static final Logger LOG = Logger.getInstance("#" + Extractor.class.getName());
|
||||
private MergingUpdateQueue myQueue = new MergingUpdateQueue("Test Extractor", 20, true, MergingUpdateQueue.ANY_COMPONENT);
|
||||
private final MergingUpdateQueue myQueue = new MergingUpdateQueue("Test Extractor", 20, true, MergingUpdateQueue.ANY_COMPONENT, this);
|
||||
|
||||
public Extractor(final InputStream stream, final Charset charset) {
|
||||
public Extractor(@NotNull InputStream stream, @NotNull Charset charset) {
|
||||
myStream = new SegmentedInputStream(stream, charset);
|
||||
myQueue.setPassThrough(false);//should be updated in awt thread
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public void setDispatchListener(final DispatchListener listener) {
|
||||
myFulfilledWorkGate.setDispactchListener(listener);
|
||||
}
|
||||
|
||||
public void setPacketDispatcher(final PacketProcessor packetProcessor, final DeferredActionsQueue queue) {
|
||||
myFulfilledWorkGate = new DeferredActionsQueue() { //todo make it all later
|
||||
@Override
|
||||
public void addLast(final Runnable runnable) {
|
||||
myQueue.queue(new Update(runnable) {
|
||||
@Override
|
||||
@@ -57,13 +64,16 @@ public class Extractor {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDispactchListener(final DispatchListener listener) {
|
||||
queue.setDispactchListener(listener);
|
||||
}
|
||||
};
|
||||
myEventsDispatcher = new OutputPacketProcessor() {
|
||||
@Override
|
||||
public void processPacket(final String packet) {
|
||||
myFulfilledWorkGate.addLast(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
packetProcessor.processPacket(packet);
|
||||
}
|
||||
@@ -74,6 +84,7 @@ public class Extractor {
|
||||
public void processOutput(final Printable printable) {
|
||||
LOG.assertTrue(packetProcessor instanceof OutputPacketProcessor);
|
||||
myFulfilledWorkGate.addLast(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((OutputPacketProcessor)packetProcessor).processOutput(printable);
|
||||
}
|
||||
|
||||
@@ -122,10 +122,12 @@ public abstract class TestObject implements JavaCommandLine {
|
||||
|
||||
public abstract String suggestActionName();
|
||||
|
||||
@Override
|
||||
public RunnerSettings getRunnerSettings() {
|
||||
return myRunnerSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigurationPerRunnerSettings getConfigurationSettings() {
|
||||
return myConfigurationSettings;
|
||||
}
|
||||
@@ -145,6 +147,7 @@ public abstract class TestObject implements JavaCommandLine {
|
||||
}
|
||||
|
||||
private static final TestObject NOT_CONFIGURED = new TestObject(null, null, null, null) {
|
||||
@Override
|
||||
public RefactoringElementListener getListener(final PsiElement element, final JUnitConfiguration configuration) {
|
||||
return null;
|
||||
}
|
||||
@@ -233,6 +236,7 @@ public abstract class TestObject implements JavaCommandLine {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JavaParameters getJavaParameters() throws ExecutionException {
|
||||
if (myJavaParameters == null) {
|
||||
myJavaParameters = new JavaParameters();
|
||||
@@ -246,6 +250,7 @@ public abstract class TestObject implements JavaCommandLine {
|
||||
return myJavaParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionResult execute(final Executor executor, @NotNull final ProgramRunner runner) throws ExecutionException {
|
||||
final JUnitProcessHandler handler = createHandler();
|
||||
final RunnerSettings runnerSettings = getRunnerSettings();
|
||||
@@ -269,6 +274,7 @@ public abstract class TestObject implements JavaCommandLine {
|
||||
if (model != null) {
|
||||
handler.getOut().setDispatchListener(model.getNotifier());
|
||||
Disposer.register(model, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
handler.getOut().setDispatchListener(DispatchListener.DEAF);
|
||||
}
|
||||
@@ -293,16 +299,19 @@ public abstract class TestObject implements JavaCommandLine {
|
||||
FileUtil.delete(myListenersFile);
|
||||
}
|
||||
IJSwingUtilities.invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
unboundOutputRoot.flush();
|
||||
packetsReceiver.checkTerminated();
|
||||
final JUnitRunningModel model = packetsReceiver.getModel();
|
||||
notifyByBalloon(model, consoleProperties);
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
Disposer.dispose(consoleView);
|
||||
try {
|
||||
unboundOutputRoot.flush();
|
||||
packetsReceiver.checkTerminated();
|
||||
final JUnitRunningModel model = packetsReceiver.getModel();
|
||||
notifyByBalloon(model, consoleProperties);
|
||||
}
|
||||
finally {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
Disposer.dispose(consoleView);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -312,6 +321,7 @@ public abstract class TestObject implements JavaCommandLine {
|
||||
final String text = event.getText();
|
||||
final ConsoleViewContentType consoleViewType = ConsoleViewContentType.getConsoleViewType(outputType);
|
||||
final Printable printable = new Printable() {
|
||||
@Override
|
||||
public void printOn(final Printer printer) {
|
||||
printer.print(text, consoleViewType);
|
||||
}
|
||||
@@ -335,6 +345,7 @@ public abstract class TestObject implements JavaCommandLine {
|
||||
final RerunFailedTestsAction rerunFailedTestsAction = new RerunFailedTestsAction(consoleView.getComponent());
|
||||
rerunFailedTestsAction.init(consoleProperties, myRunnerSettings, myConfigurationSettings);
|
||||
rerunFailedTestsAction.setModelProvider(new Getter<TestFrameworkRunningModel>() {
|
||||
@Override
|
||||
public TestFrameworkRunningModel get() {
|
||||
return packetsReceiver.getModel();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user