diff options
-rw-r--r-- | src/main/java/org/sonarsource/scanner/cli/Cli.java | 8 | ||||
-rw-r--r-- | src/main/java/org/sonarsource/scanner/cli/Main.java | 4 | ||||
-rw-r--r-- | src/test/java/org/sonarsource/scanner/cli/MainTest.java | 28 |
3 files changed, 35 insertions, 5 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Cli.java b/src/main/java/org/sonarsource/scanner/cli/Cli.java index c680241..f9a45ca 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Cli.java +++ b/src/main/java/org/sonarsource/scanner/cli/Cli.java @@ -28,6 +28,7 @@ class Cli { private boolean debugEnabled = false; private boolean displayVersionOnly = false; + private boolean embedded = false; private final Properties props = new Properties(); private final Exit exit; private final Logs logger; @@ -45,6 +46,10 @@ class Cli { return displayVersionOnly; } + boolean isEmbedded() { + return embedded; + } + Properties properties() { return props; } @@ -84,6 +89,9 @@ class Cli { } else if (asList("-D", "--define").contains(arg)) { return processProp(args, pos); + } else if ("--embedded".equals(arg)) { + embedded = true; + } else if (arg.startsWith("-D")) { arg = arg.substring(2); appendPropertyTo(arg, props); diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java index 2326f24..20b97bd 100644 --- a/src/main/java/org/sonarsource/scanner/cli/Main.java +++ b/src/main/java/org/sonarsource/scanner/cli/Main.java @@ -147,7 +147,9 @@ public class Main { } private void suggestDebugMode() { - logger.error("Re-run SonarQube Scanner using the -X switch to enable full debug logging."); + if (!cli.isEmbedded()) { + logger.error("Re-run SonarQube Scanner using the -X switch to enable full debug logging."); + } } } diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java index 4c45f95..e746fe8 100644 --- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java +++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java @@ -114,17 +114,36 @@ public class MainTest { @Test public void show_error_MessageException() { Exception e = createException(true); - testException(e, false); + testException(e, false, false); verify(logs).error("Error during SonarQube Scanner execution"); verify(logs).error("Caused by: NPE"); verify(logs).error("Re-run SonarQube Scanner using the -X switch to enable full debug logging."); } + + @Test + public void show_error_MessageException_embedded() { + Exception e = createException(true); + testException(e, false, true); + + verify(logs).error("Error during SonarQube Scanner execution"); + verify(logs).error("Caused by: NPE"); + } @Test public void show_error_MessageException_debug() { Exception e = createException(true); - testException(e, true); + testException(e, true, false); + + verify(logs).error("Error during SonarQube Scanner execution"); + verify(logs).error("my message"); + verify(logs).error("Caused by: NPE"); + } + + @Test + public void show_error_MessageException_debug_embedded() { + Exception e = createException(true); + testException(e, true, true); verify(logs).error("Error during SonarQube Scanner execution"); verify(logs).error("my message"); @@ -134,14 +153,15 @@ public class MainTest { @Test public void show_error_debug() { Exception e = createException(false); - testException(e, true); + testException(e, true, false); verify(logs).error("Error during SonarQube Scanner execution", e); verify(logs, never()).error("Re-run SonarQube Scanner using the -X switch to enable full debug logging."); } - private void testException(Exception e, boolean debugEnabled) { + private void testException(Exception e, boolean debugEnabled, boolean isEmbedded) { when(cli.isDebugEnabled()).thenReturn(debugEnabled); + when(cli.isEmbedded()).thenReturn(isEmbedded); EmbeddedScanner runner = mock(EmbeddedScanner.class); doThrow(e).when(runner).execute(any(Map.class)); |