From 1d6a79e5221587c98f451b233b99eeea7d66f4d7 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 15 Sep 2016 16:24:36 +0200 Subject: SQSCANNER-23 Support the new 'MessageException' unchecked exception and log by default the error stack trace only when a non-MessageException is thrown --- .../java/org/sonarsource/scanner/cli/Main.java | 31 +++++++++------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'src/main/java/org/sonarsource/scanner/cli/Main.java') diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index 4c26e90..b8b6e68 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -74,7 +74,7 @@ public class Main { runAnalysis(stats, p); } catch (Exception e) { displayExecutionResult(stats, "FAILURE"); - showError("Error during SonarQube Scanner execution", e, cli.isDisplayStackTrace() || cli.isDebugEnabled()); + showError("Error during SonarQube Scanner execution", e, cli.isDebugEnabled()); exit.exit(Exit.ERROR); } @@ -95,10 +95,6 @@ public class Main { exit.exit(Exit.SUCCESS); } - if (cli.isDisplayStackTrace()) { - logger.info("Error stacktraces are turned on."); - } - runner = runnerFactory.create(p); } @@ -109,10 +105,6 @@ public class Main { logger.setDebugEnabled(true); logger.setDisplayStackTrace(true); } - - if (cli.isDisplayStackTrace()) { - logger.setDisplayStackTrace(true); - } } private void runAnalysis(Stats stats, Properties p) { @@ -128,13 +120,9 @@ public class Main { logger.info(SEPARATOR); } - private void showError(String message, Throwable e, boolean showStackTrace) { - if (showStackTrace) { + private void showError(String message, Throwable e, boolean debug) { + if (showStackTrace(e, debug)) { logger.error(message, e); - if (!cli.isDebugEnabled()) { - logger.error(""); - suggestDebugMode(); - } } else { logger.error(message); if (e != null) { @@ -147,13 +135,18 @@ public class Main { previousMsg = cause.getMessage(); } } + } + + if (!cli.isDebugEnabled()) { logger.error(""); - logger.error("To see the full stack trace of the errors, re-run SonarQube Scanner with the -e switch."); - if (!cli.isDebugEnabled()) { - suggestDebugMode(); - } + suggestDebugMode(); } } + + private static boolean showStackTrace(Throwable e, boolean debug) { + // class not available at compile time (loaded by isolated classloader) + return debug || "org.sonar.api.utils.MessageException".equals(e.getClass().getName()); + } private void suggestDebugMode() { logger.error("Re-run SonarQube Scanner using the -X switch to enable full debug logging."); -- cgit v1.2.3