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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user