diff options
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org')
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); |