提交 8f35aabf authored 作者: Thomas Mueller's avatar Thomas Mueller

Small compiler changes.

上级 9fe0eceb
...@@ -204,23 +204,14 @@ public class SourceCompiler { ...@@ -204,23 +204,14 @@ public class SourceCompiler {
copyInThread(p.getInputStream(), buff); copyInThread(p.getInputStream(), buff);
copyInThread(p.getErrorStream(), buff); copyInThread(p.getErrorStream(), buff);
p.waitFor(); p.waitFor();
throwSyntaxError(buff); String err = new String(buff.toByteArray(), "UTF-8");
throwSyntaxError(err);
return p.exitValue(); return p.exitValue();
} catch (Exception e) { } catch (Exception e) {
throw DbException.convert(e); throw DbException.convert(e);
} }
} }
private void throwSyntaxError(ByteArrayOutputStream out) {
String err = StringUtils.utf8Decode(out.toByteArray());
if (err.startsWith("Note:")) {
// unchecked or unsafe operations - just a warning
} else if (err.length() > 0) {
err = StringUtils.replaceAll(err, compileDir, "");
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, err);
}
}
private static void copyInThread(final InputStream in, final OutputStream out) { private static void copyInThread(final InputStream in, final OutputStream out) {
new Task() { new Task() {
public void call() throws IOException { public void call() throws IOException {
...@@ -235,14 +226,16 @@ public class SourceCompiler { ...@@ -235,14 +226,16 @@ public class SourceCompiler {
PrintStream temp = new PrintStream(buff); PrintStream temp = new PrintStream(buff);
try { try {
System.setErr(temp); System.setErr(temp);
Method compile = JAVAC_SUN.getMethod("compile", String[].class); Method compile;
compile = JAVAC_SUN.getMethod("compile", String[].class);
Object javac = JAVAC_SUN.newInstance(); Object javac = JAVAC_SUN.newInstance();
compile.invoke(javac, (Object) new String[] { compile.invoke(javac, (Object) new String[] {
"-sourcepath", compileDir, "-sourcepath", compileDir,
"-d", compileDir, "-d", compileDir,
"-encoding", "UTF-8", "-encoding", "UTF-8",
javaFile.getAbsolutePath() }); javaFile.getAbsolutePath() });
throwSyntaxError(buff); String err = new String(buff.toByteArray(), "UTF-8");
throwSyntaxError(err);
} catch (Exception e) { } catch (Exception e) {
throw DbException.convert(e); throw DbException.convert(e);
} finally { } finally {
...@@ -250,4 +243,13 @@ public class SourceCompiler { ...@@ -250,4 +243,13 @@ public class SourceCompiler {
} }
} }
private void throwSyntaxError(String err) {
if (err.startsWith("Note:")) {
// unchecked or unsafe operations - just a warning
} else if (err.length() > 0) {
err = StringUtils.replaceAll(err, compileDir, "");
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, err);
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论