From 900b0083b6fe8f2df2b6679eefbdb01b41ecd35f Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 13 Jan 2017 10:18:35 +0100 Subject: [PATCH] SQSCANNER-36 Properly exit process even in case of failure during stop --- .../java/org/sonarsource/scanner/cli/Main.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index f825034..8d030e4 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -64,6 +64,7 @@ public class Main { void execute() { Stats stats = new Stats(logger).start(); + int status = Exit.ERROR; try { Properties p = conf.properties(); checkSkip(p); @@ -72,14 +73,22 @@ public class Main { runner.start(); logger.info("SonarQube server " + runner.serverVersion()); runAnalysis(stats, p); + status = Exit.SUCCESS; } catch (Exception e) { + status = Exit.ERROR; displayExecutionResult(stats, "FAILURE"); showError("Error during SonarQube Scanner execution", e, cli.isDebugEnabled()); - exit.exit(Exit.ERROR); + } finally { + try { + runner.stop(); + } catch (Throwable e) { + status = Exit.ERROR; + logger.error("Unable to properly stop the scanner", e); + } finally { + exit.exit(status); + } } - runner.stop(); - exit.exit(Exit.SUCCESS); } private void checkSkip(Properties properties) { -- 2.39.5