mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
trying in tests async read of javac output
This commit is contained in:
+55
-15
@@ -27,6 +27,8 @@ import com.intellij.util.StringBuilderSpinAllocator;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
@@ -47,6 +49,8 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
|
||||
private String myPushBackLine = null;
|
||||
private volatile boolean myProcessExited = false;
|
||||
private final CompileContext myContext;
|
||||
|
||||
private final BlockingQueue<String> myLines = new LinkedBlockingQueue<String>();
|
||||
|
||||
public CompilerParsingThread(Process process, OutputParser outputParser, final boolean readErrorStream, boolean trimLines, CompileContext context) {
|
||||
myProcess = process;
|
||||
@@ -60,6 +64,24 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
|
||||
|
||||
volatile boolean processing;
|
||||
public void run() {
|
||||
if (CompileDriver.ourDebugMode) {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
final String line = readLine(myCompilerOutStreamReader);
|
||||
if (CompileDriver.ourDebugMode) {
|
||||
System.out.println("RAW_LIne read: #" + line + "#");
|
||||
}
|
||||
if (line == null) {
|
||||
myLines.offer(TERMINATION_STRING);
|
||||
break;
|
||||
}
|
||||
myLines.offer(line);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
processing = true;
|
||||
try {
|
||||
while (true) {
|
||||
@@ -105,16 +127,13 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
|
||||
}
|
||||
|
||||
public final String getNextLine() {
|
||||
if (CompileDriver.ourDebugMode) {
|
||||
System.out.println("Before reading line");
|
||||
}
|
||||
final String pushBack = myPushBackLine;
|
||||
if (pushBack != null) {
|
||||
myPushBackLine = null;
|
||||
myLastReadLine = pushBack;
|
||||
return pushBack;
|
||||
}
|
||||
final String line = readLine(myCompilerOutStreamReader);
|
||||
final String line = getNextUnprocessedLine();
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("LIne read: #" + line + "#");
|
||||
}
|
||||
@@ -130,6 +149,28 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
|
||||
return myLastReadLine;
|
||||
}
|
||||
|
||||
private String getNextUnprocessedLine() {
|
||||
if (CompileDriver.ourDebugMode) {
|
||||
try {
|
||||
if (TERMINATION_STRING.equals(myLines.peek())) {
|
||||
return TERMINATION_STRING;
|
||||
}
|
||||
final String line = myLines.take();
|
||||
if (TERMINATION_STRING.equals(line)) {
|
||||
myLines.offer(TERMINATION_STRING); // pushback
|
||||
}
|
||||
return line;
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return TERMINATION_STRING;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return readLine(myCompilerOutStreamReader);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushBack(String line) {
|
||||
myLastReadLine = null;
|
||||
@@ -227,18 +268,17 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
|
||||
|
||||
private int readNextByte(final Reader reader) {
|
||||
try {
|
||||
if (!CompileDriver.ourDebugMode) {
|
||||
while(!reader.ready()) {
|
||||
if (isProcessTerminated()) {
|
||||
//if (!reader.ready()) {
|
||||
return -1;
|
||||
//}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1L);
|
||||
}
|
||||
catch (InterruptedException ignore) {
|
||||
while(!reader.ready()) {
|
||||
if (isProcessTerminated()) {
|
||||
if (reader.ready()) {
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1L);
|
||||
}
|
||||
catch (InterruptedException ignore) {
|
||||
}
|
||||
}
|
||||
return reader.read();
|
||||
|
||||
Reference in New Issue
Block a user