From 6e33df0cc2e8e243fef6eb4486a03e84620d51d3 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Tue, 7 May 2024 16:17:25 +0200 Subject: [PATCH] Fix stacktrace in the Json output --- .../sonar/scanner/bootstrap/ScannerLogbackEncoder.java | 6 ++++++ .../scanner/bootstrap/ScannerLogbackEncoderTest.java | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoder.java index bbad390077a..f67b41bf40c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoder.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoder.java @@ -24,6 +24,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.IThrowableProxy; import ch.qos.logback.core.CoreConstants; import ch.qos.logback.core.encoder.EncoderBase; +import java.util.List; import org.apache.commons.text.StringEscapeUtils; import static ch.qos.logback.core.CoreConstants.COMMA_CHAR; @@ -41,6 +42,11 @@ public class ScannerLogbackEncoder extends EncoderBase { private final ThrowableProxyConverter tpc = new ThrowableProxyConverter(); + public ScannerLogbackEncoder() { + tpc.setOptionList(List.of("full")); + tpc.start(); + } + @Override public byte[] headerBytes() { return EMPTY_BYTES; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java index e63985da428..d752b67b4c5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java @@ -30,9 +30,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; class ScannerLogbackEncoderTest { - + ScannerLogbackEncoder underTest = new ScannerLogbackEncoder(); - + @Test void no_headers_and_footers() { assertThat(underTest.headerBytes()).isEmpty(); @@ -70,7 +70,9 @@ class ScannerLogbackEncoderTest { var bytes = underTest.encode(logEvent); - assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo("{\"level\":\"DEBUG\",\"message\":\"message\",\"stacktrace\":\"java.lang.IllegalArgumentException: foo\\n\"}\n"); + assertThat(new String(bytes, StandardCharsets.UTF_8)) + .startsWith( + "{\"level\":\"DEBUG\",\"message\":\"message\",\"stacktrace\":\"java.lang.IllegalArgumentException: foo\\n\\tat org.sonar.scanner.bootstrap.ScannerLogbackEncoderTest.should_encode_with_stacktrace"); } -} \ No newline at end of file +} -- 2.39.5