}
boolean success = false;
try {
FregeParseController parseController = new FregeParseController();
MarkerCreatorWithBatching markerCreator = new MarkerCreatorWithBatching(file, parseController, this);
parseController.getAnnotationTypeInfo().addProblemMarkerType(
getErrorMarkerID());
ISourceProject sourceProject = ModelFactory.open(file.getProject());
parseController.initialize(file.getProjectRelativePath(),
sourceProject, markerCreator);
String contents = BuilderUtils.getFileContents(file);
final TGlobal result = parseController.parse(contents, new CompProgress());
if (FregeParseController.errors(result) == 0) {
// run the eclipse java compiler
final String target = Main.targetPath(result, ".java");
getPlugin().writeInfoMsg("built: " + target);
// get the frege path and build path
final String bp = TOptions.dir( TGlobal.options(result) );
final TList ourPath = frege.compiler.Utilities.ourPath(TGlobal.options(result));
final String fp = Delayed.<String>forced(
PreludeText.joined(
System.getProperty("path.separator"),
ourPath
));
final TList srcPath = TOptions.sourcePath(TGlobal.options(result));
final String sp = Delayed.<String>forced(
PreludeText.joined(
System.getProperty("path.separator"),
srcPath
));
// construct the commandline
final String cmdline = "-cp " + "\"" + fp + "\""
+ " -d " + "\"" + bp + "\""
+ " -sourcepath " + "\"" + sp + "\""
+ " -Xemacs -1.7 -encoding UTF-8 "
+ "\"" + target + "\"";
getPlugin().writeInfoMsg("batch-compile " + cmdline);
final StringWriter errs = new StringWriter();
success = org.eclipse.jdt.core.compiler.batch.BatchCompiler.compile(
cmdline,
new PrintWriter(System.out),
new PrintWriter(errs),
new CompProgress());
/* write java error messages to some file.
if (errs.toString().length() > 0) try {
FileWriter f = new FileWriter(target + ".errors");
f.append(errs.toString());
f.close();
}
catch (IOException e) {
getPlugin().writeErrorMsg("could not write java compiler errors " + e.getMessage());
}
*/
if (!success) {
TPosition pos = Global.packageStart(result).<TPosition>forced();
TToken module = TPosition.first(pos);
int line = TToken.line(module);
int chStart = TToken.offset(module);
int chEnd = chStart + TToken.length(module);
String msg = errs.toString();
String[] msgs = msg.split(System.getProperty("line.terminator", "\n"));
Pattern p = Pattern.compile(":\\d+:\\s+error:(.*)");
for (String s : msgs) {
if (s == null) continue;
// getPlugin().writeInfoMsg(s);
Matcher m = p.matcher(s);
if (m.find()) {
String se = m.group(1);
markerCreator.addMarker(
IMarker.SEVERITY_ERROR,
se, line, chStart, chEnd);
}
}
getPlugin().writeErrorMsg("java compiler failed on " + target);
markerCreator.addMarker(IMarker.SEVERITY_INFO,
"Java compiler errors are almost always caused by bad native declarations. "
+ "When you're sure this is out of the question you've found a compiler bug, "
+ "please report under https://github.com/frege/frege/issues and attach a copy of "
+ target,
line, chStart, chEnd);
}
else {
// notify that we have a new module
parseController.justCompiled();
}
}
if (markerCreator instanceof MarkerCreatorWithBatching) {
((MarkerCreatorWithBatching) markerCreator).flush(monitor);