junit: dispatch messages

This commit is contained in:
anna
2009-12-21 17:42:45 +03:00
parent 63bda52025
commit 85272394c3
76 changed files with 741 additions and 1296 deletions
@@ -19,18 +19,11 @@ 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.SegmentedInputStream;
import com.intellij.execution.junit2.segments.DeferedActionsQueue;
import com.intellij.execution.junit2.segments.DispatchListener;
import com.intellij.execution.junit2.segments.PacketExtractorBase;
import com.intellij.execution.junit2.segments.Extractor;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessTerminatedListener;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.project.Project;
import com.intellij.rt.execution.junit.segments.PacketProcessor;
import java.io.InputStream;
import java.io.Reader;
import java.nio.charset.Charset;
@@ -50,18 +43,18 @@ public class JUnitProcessHandler extends OSProcessHandler {
}
protected Reader createProcessOutReader() {
return myOut.getReader();
return myOut.createReader();
}
protected Reader createProcessErrReader() {
return myErr.getReader();
return myErr.createReader();
}
public PacketExtractorBase getErr() {
public Extractor getErr() {
return myErr;
}
public PacketExtractorBase getOut() {
public Extractor getOut() {
return myOut;
}
@@ -83,46 +76,4 @@ public class JUnitProcessHandler extends OSProcessHandler {
ProcessTerminatedListener.attach(processHandler);
return processHandler;
}
private class Extractor extends PacketExtractorBase {
private final SegmentedInputStream myStream;
public Extractor(final InputStream stream, final Charset charset) {
myStream = new SegmentedInputStream(stream, charset);
}
public void setPacketProcessor(final PacketProcessor packetProcessor) {
myStream.setEventsDispatcher(new PacketProcessor() {
public void processPacket(final String packet) {
perform(new Runnable() {
public void run() {
packetProcessor.processPacket(packet);
}
});
}
});
}
public void setFulfilledWorkGate(final DeferedActionsQueue fulfilledWorkGate) {
super.setFulfilledWorkGate(new DeferedActionsQueue() {
public void addLast(final Runnable runnable) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
fulfilledWorkGate.addLast(runnable);
}
}, ModalityState.NON_MODAL);
}
public void setDispactchListener(final DispatchListener listener) {
fulfilledWorkGate.setDispactchListener(listener);
}
});
}
public Reader getReader() {
return new SegmentedInputStreamReader(myStream);
//return new InputStreamReader(myStream, myCharset);
}
}
}
@@ -62,21 +62,22 @@ public class SegmentedInputStream extends InputStream {
while (true) {
nextByte = readNext();
if (nextByte != SegmentedStream.SPECIAL_SYMBOL) break;
final boolean packetRead = readControlSequence();
if (!packetRead) break;
final Integer packetRead = readControlSequence();
if (packetRead != null) break;
}
return nextByte;
}
private boolean readControlSequence() throws IOException {
private Integer readControlSequence() throws IOException {
for (int idx = 1; idx < SegmentedStream.MARKER_PREFIX.length(); idx++) {
if (readNext() != SegmentedStream.MARKER_PREFIX.charAt(idx)) {
return false;
final int readAhead = readNext();
if (readAhead != SegmentedStream.MARKER_PREFIX.charAt(idx)) {
return readAhead;
}
}
final char[] marker = readMarker();
if(myEventsDispatcher != null) myEventsDispatcher.processPacket(decode(marker));
return true;
return null;
}
public void setEventsDispatcher(final PacketProcessor eventsDispatcher) {
@@ -127,11 +128,11 @@ public class SegmentedInputStream extends InputStream {
mySourceStream.pushBack(b);
return 1;
}
final boolean packetRead = readControlSequence();
if (!packetRead) {
final Integer packetRead = readControlSequence();
if (packetRead != null) {
// push back quoted slash
mySourceStream.pushBack(b);
mySourceStream.pushBack(b);
mySourceStream.pushBack(packetRead);
return 1;
}
}
@@ -15,7 +15,7 @@
*/
package com.intellij.execution.junit2.segments;
public interface DeferedActionsQueue {
public interface DeferredActionsQueue {
void addLast(Runnable runnable);
void setDispactchListener(DispatchListener listener);
@@ -19,7 +19,7 @@ import com.intellij.openapi.diagnostic.Logger;
import java.awt.*;
public class DeferedActionsQueueImpl implements DeferedActionsQueue {
public class DeferredActionsQueueImpl implements DeferredActionsQueue {
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.segments.DeferedActionsQueueImpl");
private DispatchListener myListener = DispatchListener.DEAF;
private int myCounter = 0;
@@ -0,0 +1,72 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
import com.intellij.execution.junit.SegmentedInputStreamReader;
import com.intellij.execution.junit2.SegmentedInputStream;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.rt.execution.junit.segments.PacketProcessor;
import java.io.InputStream;
import java.io.Reader;
import java.nio.charset.Charset;
/**
* @author dyoma
*/
public class Extractor {
private DeferredActionsQueue myFulfilledWorkGate = null;
private final SegmentedInputStream myStream;
public Extractor(final InputStream stream, final Charset charset) {
myStream = new SegmentedInputStream(stream, charset);
}
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
public void addLast(final Runnable runnable) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
queue.addLast(runnable);
}
}, ModalityState.NON_MODAL);
}
public void setDispactchListener(final DispatchListener listener) {
queue.setDispactchListener(listener);
}
};
myStream.setEventsDispatcher(new PacketProcessor() {
public void processPacket(final String packet) {
myFulfilledWorkGate.addLast(new Runnable() {
public void run() {
packetProcessor.processPacket(packet);
}
});
}
});
}
public Reader createReader() {
return new SegmentedInputStreamReader(myStream);
}
}
@@ -18,10 +18,8 @@ package com.intellij.execution.junit2.segments;
import com.intellij.execution.ui.ConsoleViewContentType;
public interface InputConsumer {
class DeafInputConsumer implements InputConsumer {
public void onOutput(final String text, final ConsoleViewContentType contentType) {
}
}
DeafInputConsumer DEAF = new DeafInputConsumer();
InputConsumer DEAF = new InputConsumer() {
public void onOutput(String text, ConsoleViewContentType contentType) {}
};
void onOutput(String text, ConsoleViewContentType contentType);
}
@@ -1,39 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.execution.junit2.segments;
import com.intellij.rt.execution.junit.segments.PacketProcessor;
/**
* @author dyoma
*/
public abstract class PacketExtractorBase {
private DeferedActionsQueue myFulfilledWorkGate = null;
public void setFulfilledWorkGate(final DeferedActionsQueue fulfilledWorkGate) {
myFulfilledWorkGate = fulfilledWorkGate;
}
public abstract void setPacketProcessor(PacketProcessor packetProcessor);
public void setDispatchListener(final DispatchListener listener) {
myFulfilledWorkGate.setDispactchListener(listener);
}
protected void perform(final Runnable runnable) {
myFulfilledWorkGate.addLast(runnable);
}
}