From 35adb6be7727bd04ecc3849a517a43dc62ffbef2 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 17 Feb 2015 15:28:32 +0300 Subject: [PATCH] gant wrapper for external build: show file path in compilation error message and throw BuildException only when compilation is finished --- .../jps/gant/JpsGantProjectBuilder.java | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/jps/standalone-builder/src/org/jetbrains/jps/gant/JpsGantProjectBuilder.java b/jps/standalone-builder/src/org/jetbrains/jps/gant/JpsGantProjectBuilder.java index 02774834b943..a97003c751a1 100644 --- a/jps/standalone-builder/src/org/jetbrains/jps/gant/JpsGantProjectBuilder.java +++ b/jps/standalone-builder/src/org/jetbrains/jps/gant/JpsGantProjectBuilder.java @@ -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);