aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-09-08 12:27:26 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-09-15 08:51:08 +0200
commit3078c44cf8dd58238ac05ee39b77dff660a20560 (patch)
tree4ce070d73a7ff3502ac37b8c612da47c0fbd5e2c /sonar-scanner-engine/src/main/java/org
parenta19af040824349b4be8be4c6f179c2887bf97076 (diff)
downloadsonarqube-3078c44cf8dd58238ac05ee39b77dff660a20560.tar.gz
sonarqube-3078c44cf8dd58238ac05ee39b77dff660a20560.zip
SONAR-8855 Make it obvious that generic coverage report expect an XML file
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java11
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java9
2 files changed, 13 insertions, 7 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java
index 0be3ce89536..0890c8544b3 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericCoverageReportParser.java
@@ -20,6 +20,7 @@
package org.sonar.scanner.genericcoverage;
import com.google.common.base.Preconditions;
+import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
@@ -32,6 +33,7 @@ import org.codehaus.staxmate.in.SMInputCursor;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
+import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.StaxParser;
public class GenericCoverageReportParser {
@@ -47,15 +49,16 @@ public class GenericCoverageReportParser {
private final List<String> firstUnknownFiles = new ArrayList<>();
private final Set<String> matchedFileKeys = new HashSet<>();
- public void parse(java.io.File reportFile, SensorContext context) {
+ public void parse(File reportFile, SensorContext context) {
try (InputStream inputStream = new FileInputStream(reportFile)) {
parse(inputStream, context);
} catch (Exception e) {
- throw new IllegalStateException("Error during parsing of coverage report " + reportFile, e);
+ throw MessageException.of("Error during parsing of the generic coverage report '" + reportFile + "'. Look at SonarQube documentation to know the expected XML format.",
+ e);
}
}
- void parse(InputStream inputStream, SensorContext context) throws XMLStreamException {
+ private void parse(InputStream inputStream, SensorContext context) throws XMLStreamException {
new StaxParser(rootCursor -> {
rootCursor.advance();
parseRootNode(rootCursor, context);
@@ -88,7 +91,7 @@ public class GenericCoverageReportParser {
"Line %s of report refers to a file with an unknown language: %s",
fileCursor.getCursorLocation().getLineNumber(),
filePath);
- matchedFileKeys.add(inputFile.absolutePath());
+ matchedFileKeys.add(inputFile.key());
NewCoverage newCoverage = context.newCoverage().onFile(inputFile);
SMInputCursor lineToCoverCursor = fileCursor.childElementCursor();
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java
index 40b908d061a..68b883627b5 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/genericcoverage/GenericTestExecutionReportParser.java
@@ -20,6 +20,7 @@
package org.sonar.scanner.genericcoverage;
import com.google.common.base.Preconditions;
+import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
@@ -34,6 +35,7 @@ import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.test.MutableTestCase;
import org.sonar.api.test.MutableTestPlan;
import org.sonar.api.test.TestCase;
+import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.StaxParser;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -71,15 +73,16 @@ public class GenericTestExecutionReportParser {
this.testPlanBuilder = testPlanBuilder;
}
- public void parse(java.io.File reportFile, SensorContext context) {
+ public void parse(File reportFile, SensorContext context) {
try (InputStream inputStream = new FileInputStream(reportFile)) {
parse(inputStream, context);
} catch (Exception e) {
- throw new IllegalStateException("Error during parsing of test execution report " + reportFile, e);
+ throw MessageException.of(
+ "Error during parsing of generic test execution report '" + reportFile + "'. Look at the SonarQube documentation to know the expected XML format.", e);
}
}
- public void parse(InputStream inputStream, SensorContext context) throws XMLStreamException {
+ private void parse(InputStream inputStream, SensorContext context) throws XMLStreamException {
new StaxParser(rootCursor -> {
rootCursor.advance();
parseRootNode(rootCursor, context);