diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2016-09-16 15:21:00 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2016-09-16 15:21:00 +0200 |
commit | 00e8ca4b08e25f0db409d90a56113a0d0907fdf0 (patch) | |
tree | 6a540a50def5646bbe6b02b4a09848b08c954af3 /src | |
parent | 85c24bd5fe1485a43342e69058263aa48a51378d (diff) | |
download | sonar-scanner-cli-00e8ca4b08e25f0db409d90a56113a0d0907fdf0.tar.gz sonar-scanner-cli-00e8ca4b08e25f0db409d90a56113a0d0907fdf0.zip |
SQSCANNER-23 Support the new 'MessageException' unchecked exception and log by default the error stack trace only when a non-MessageException is thrown
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/sonarsource/scanner/cli/Main.java | 24 | ||||
-rw-r--r-- | src/test/java/org/sonar/api/utils/MessageException.java (renamed from src/test/java/org/sonar/api/utils/MessageException/MessageException.java) | 2 | ||||
-rw-r--r-- | src/test/java/org/sonarsource/scanner/cli/MainTest.java | 6 |
3 files changed, 15 insertions, 17 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index b8b6e68..83bdf33 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -81,7 +81,7 @@ public class Main { runner.stop(); exit.exit(Exit.SUCCESS); } - + private void checkSkip(Properties properties) { if ("true".equalsIgnoreCase(properties.getProperty(ScanProperties.SKIP))) { logger.info("SonarQube Scanner analysis skipped"); @@ -125,27 +125,25 @@ public class Main { logger.error(message, e); } else { logger.error(message); - if (e != null) { - logger.error(e.getMessage()); - String previousMsg = ""; - for (Throwable cause = e.getCause(); cause != null - && cause.getMessage() != null - && !cause.getMessage().equals(previousMsg); cause = cause.getCause()) { - logger.error("Caused by: " + cause.getMessage()); - previousMsg = cause.getMessage(); - } + logger.error(e.getMessage()); + String previousMsg = ""; + for (Throwable cause = e.getCause(); cause != null + && cause.getMessage() != null + && !cause.getMessage().equals(previousMsg); cause = cause.getCause()) { + logger.error("Caused by: " + cause.getMessage()); + previousMsg = cause.getMessage(); } } - + if (!cli.isDebugEnabled()) { logger.error(""); 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()); + return debug || !"org.sonar.api.utils.MessageException".equals(e.getClass().getName()); } private void suggestDebugMode() { diff --git a/src/test/java/org/sonar/api/utils/MessageException/MessageException.java b/src/test/java/org/sonar/api/utils/MessageException.java index 163fc0f..0e72d3c 100644 --- a/src/test/java/org/sonar/api/utils/MessageException/MessageException.java +++ b/src/test/java/org/sonar/api/utils/MessageException.java @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.api.utils.MessageException; +package org.sonar.api.utils; public class MessageException extends RuntimeException { public MessageException(String msg) { diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java index abf5fc0..7efc17a 100644 --- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java +++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java @@ -28,7 +28,7 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.sonar.api.utils.MessageException.MessageException; +import org.sonar.api.utils.MessageException; import org.sonarsource.scanner.api.EmbeddedScanner; import org.sonarsource.scanner.api.ScanProperties; @@ -91,7 +91,7 @@ public class MainTest { verify(runner).stop(); verify(exit).exit(Exit.ERROR); - verify(logs).error("Caused by: NPE"); + verify(logs).error("Error during SonarQube Scanner execution", e); } @Test @@ -99,7 +99,7 @@ public class MainTest { Exception e = createException(false); testException(e, false); - verify(logs).error("Error during SonarQube Scanner execution"); + verify(logs).error("Error during SonarQube Scanner execution", e); verify(logs).error("Re-run SonarQube Scanner using the -X switch to enable full debug logging."); } |