Ignore preceding newline from scala RepleReporter.error

This commit is contained in:
Lee moon soo 2017-02-07 10:31:21 +09:00
parent 5bb38c89ae
commit 6908bdf14d
2 changed files with 22 additions and 10 deletions

View file

@ -993,6 +993,7 @@ public class SparkInterpreter extends Interpreter {
}
private Results.Result interpret(String line) {
out.ignoreLeadingNewLinesFromScalaReporter();
return (Results.Result) Utils.invokeMethod(
intp,
"interpret",
@ -1261,7 +1262,6 @@ public class SparkInterpreter extends Interpreter {
if (varName == null || varName.isEmpty()) {
return;
}
Object lastObj = null;
try {
if (Utils.isScala2_10()) {

View file

@ -30,6 +30,7 @@ import java.io.IOException;
public class InterpreterOutputStream extends LogOutputStream {
public static Logger logger;
InterpreterOutput interpreterOutput;
boolean ignoreLeadingNewLinesFromScalaReporter = false;
public InterpreterOutputStream(Logger logger) {
this.logger = logger;
@ -45,6 +46,18 @@ public class InterpreterOutputStream extends LogOutputStream {
@Override
public void write(int b) throws IOException {
if (ignoreLeadingNewLinesFromScalaReporter && b == '\n') {
StackTraceElement[] stacks = Thread.currentThread().getStackTrace();
for (StackTraceElement stack : stacks) {
if (stack.getClassName().equals("scala.tools.nsc.interpreter.ReplReporter") &&
stack.getMethodName().equals("error")) {
// ignore
return;
}
}
} else {
ignoreLeadingNewLinesFromScalaReporter = false;
}
super.write(b);
if (interpreterOutput != null) {
interpreterOutput.write(b);
@ -53,17 +66,13 @@ public class InterpreterOutputStream extends LogOutputStream {
@Override
public void write(byte [] b) throws IOException {
super.write(b);
if (interpreterOutput != null) {
interpreterOutput.write(b);
}
write(b, 0, b.length);
}
@Override
public void write(byte [] b, int offset, int len) throws IOException {
super.write(b, offset, len);
if (interpreterOutput != null) {
interpreterOutput.write(b, offset, len);
public void write(byte [] b, int off, int len) throws IOException {
for (int i = off; i < len; i++) {
write(b[i]);
}
}
@ -80,7 +89,6 @@ public class InterpreterOutputStream extends LogOutputStream {
}
}
@Override
public void flush() throws IOException {
super.flush();
@ -88,4 +96,8 @@ public class InterpreterOutputStream extends LogOutputStream {
interpreterOutput.flush();
}
}
public void ignoreLeadingNewLinesFromScalaReporter() {
ignoreLeadingNewLinesFromScalaReporter = true;
}
}