aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java1
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java10
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java1
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java41
4 files changed, 50 insertions, 3 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
index 9562f300fb1..d03537c8094 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/MeasureSensor.java
@@ -77,6 +77,7 @@ public class MeasureSensor implements Sensor {
String value = line.substring(metricKey.length() + 1);
saveMeasure(context, inputFile, metricKey, value);
} catch (Exception e) {
+ LOG.error("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
throw new IllegalStateException("Error processing line " + lineNumber + " of file " + measureFile.getAbsolutePath(), e);
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java
index 183cd378711..f401b227d0d 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/bootstrapper/LogCallbackAppender.java
@@ -20,6 +20,7 @@
package org.sonar.batch.bootstrapper;
import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.pattern.ExtendedThrowableProxyConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
@@ -36,7 +37,14 @@ public class LogCallbackAppender extends UnsynchronizedAppenderBase<ILoggingEven
@Override
protected void append(ILoggingEvent event) {
- target.log(event.getFormattedMessage(), translate(event.getLevel()));
+ if (event.getThrowableProxy() == null) {
+ target.log(event.getFormattedMessage(), translate(event.getLevel()));
+ } else {
+ ExtendedThrowableProxyConverter throwableConverter = new ExtendedThrowableProxyConverter();
+ throwableConverter.start();
+ target.log(event.getFormattedMessage() + "\n" + throwableConverter.convert(event), translate(event.getLevel()));
+ throwableConverter.stop();
+ }
}
private static LogOutput.Level translate(Level level) {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java
index 6b225306fe0..14dc014a2ae 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/bootstrapper/LogCallbackAppenderTest.java
@@ -63,6 +63,7 @@ public class LogCallbackAppenderTest {
verify(event).getFormattedMessage();
verify(event).getLevel();
+ verify(event).getThrowableProxy();
verify(listener).log(msg, translatedLevel);
verifyNoMoreInteractions(event, listener);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java
index f360dca56ac..4e4a4857ede 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java
@@ -20,7 +20,6 @@
package org.sonar.batch.mediumtest.log;
import com.google.common.collect.ImmutableMap;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -30,7 +29,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Before;
@@ -40,9 +38,12 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.batch.bootstrapper.LogOutput;
+import org.sonar.batch.bootstrapper.LogOutput.Level;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.xoo.XooPlugin;
+
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
public class LogListenerTest {
@Rule
@@ -196,6 +197,42 @@ public class LogListenerTest {
}
}
+ // SONAR-7540
+ @Test
+ public void testStackTrace() throws IOException {
+ File srcDir = new File(baseDir, "src");
+ srcDir.mkdir();
+
+ File xooFile = new File(srcDir, "sample.xoo");
+ FileUtils.write(xooFile, "Sample xoo\ncontent");
+ File xooFileMeasure = new File(srcDir, "sample.xoo.measures");
+ FileUtils.write(xooFileMeasure, "foo:bar");
+
+ try {
+ tester.newTask()
+ .properties(builder
+ .put("sonar.sources", "src")
+ .build())
+ .start();
+ fail("Expected exception");
+ } catch (Exception e) {
+ assertThat(e.getMessage()).contains("Error processing line 1");
+ }
+ tester.stop();
+
+ assertNoStdOutput();
+
+ synchronized (logOutput) {
+ for (LogEvent e : logOutput) {
+ if (e.level == Level.ERROR) {
+ assertThat(e.msg).contains("Error processing line 1 of file", "src/sample.xoo.measures", "java.lang.IllegalStateException: Unknow metric with key: foo",
+ "at org.sonar.xoo.lang.MeasureSensor.saveMeasure");
+
+ }
+ }
+ }
+ }
+
private class SimpleLogListener implements LogOutput {
@Override
public void log(String msg, Level level) {