gant wrapper for external build: show file path in compilation error message and throw BuildException only when compilation is finished

This commit is contained in:
nik
2015-02-17 17:13:01 +03:00
parent 859428a7ee
commit 35adb6be77
@@ -267,17 +267,20 @@ public class JpsGantProjectBuilder {
info("Starting build; incremental: " + myBuildIncrementally + ", cache directory: " + myDataStorageRoot.getAbsolutePath());
info("Build scope: " + (allModules ? "all" : modulesSet.size()) + " modules, " + (includeTests ? "including tests" : "production only"));
long compilationStart = System.currentTimeMillis();
try {
long compilationStart = System.currentTimeMillis();
Standalone.runBuild(myModelLoader, myDataStorageRoot, messageHandler, scopes, false);
if (!myStatisticsReported) {
myBuildInfoPrinter.printStatisticsMessage(this, "Compilation time, ms", String.valueOf(System.currentTimeMillis() - compilationStart));
myStatisticsReported = true;
}
}
catch (Throwable e) {
error(e);
}
if (messageHandler.myFailed) {
error("Compilation failed");
}
else if (!myStatisticsReported) {
myBuildInfoPrinter.printStatisticsMessage(this, "Compilation time, ms", String.valueOf(System.currentTimeMillis() - compilationStart));
myStatisticsReported = true;
}
}
else {
info("Building skipped as we're running dry");
@@ -316,15 +319,33 @@ public class JpsGantProjectBuilder {
}
private class AntMessageHandler implements MessageHandler {
private boolean myFailed;
@Override
public void processMessage(BuildMessage msg) {
BuildMessage.Kind kind = msg.getKind();
String text = msg.getMessageText();
switch (kind) {
case ERROR:
String compilerName = msg instanceof CompilerMessage ? ((CompilerMessage)msg).getCompilerName() : "";
myBuildInfoPrinter.printCompilationErrors(JpsGantProjectBuilder.this, compilerName, text);
error("Compilation failed");
String compilerName;
String messageText;
if (msg instanceof CompilerMessage) {
CompilerMessage compilerMessage = (CompilerMessage)msg;
compilerName = compilerMessage.getCompilerName();
String sourcePath = compilerMessage.getSourcePath();
if (sourcePath != null) {
messageText = sourcePath + (compilerMessage.getLine() != -1 ? ":" + compilerMessage.getLine() : "") + ":\n" + text;
}
else {
messageText = text;
}
}
else {
compilerName = "";
messageText = text;
}
myFailed = true;
myBuildInfoPrinter.printCompilationErrors(JpsGantProjectBuilder.this, compilerName, messageText);
break;
case WARNING:
warning(text);