}
LOG.debug("Dry Run database size: {}", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(toFile)));
} catch (SonarException e) {
- Throwable rootCause = Throwables.getRootCause(e);
- if (rootCause instanceof SocketTimeoutException) {
- // Pico will unwrap the first runtime exception
- throw new SonarException(new SonarException(String.format("DryRun database read timed out after %s ms. You can try to increase read timeout with property -D"
- + CoreProperties.DRY_RUN_READ_TIMEOUT,
- readTimeout), e));
- }
- if (projectKey != null && (rootCause instanceof HttpException) && (((HttpException) rootCause).getResponseCode() == 401)) {
- // Pico will unwrap the first runtime exception
- throw new SonarException(new SonarException(String.format("You don't have access rights to project [%s]", projectKey), e));
- }
+ handleException(readTimeout, projectKey, e);
throw e;
}
}
+ private void handleException(int readTimeout, String projectKey, SonarException e) {
+ Throwable rootCause = Throwables.getRootCause(e);
+ if (rootCause instanceof SocketTimeoutException) {
+ // Pico will unwrap the first runtime exception
+ throw new SonarException(new SonarException(String.format("DryRun database read timed out after %s ms. You can try to increase read timeout with property -D"
+ + CoreProperties.DRY_RUN_READ_TIMEOUT,
+ readTimeout), e));
+ }
+ if (projectKey != null && (rootCause instanceof HttpException) && (((HttpException) rootCause).getResponseCode() == 401)) {
+ // Pico will unwrap the first runtime exception
+ throw new SonarException(new SonarException(String.format("You don't have access rights to project [%s]", projectKey), e));
+ }
+ }
+
private void replaceSettings(String databasePath) {
settings
.removeProperty("sonar.jdbc.schema")
private CoberturaReportParserUtils() {
}
- public static interface FileResolver {
+ public interface FileResolver {
/**
* Return a SonarQube file resource from a filename present in Cobertura report
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
- try {
- rootCursor.advance();
- collectPackageMeasures(rootCursor.descendantElementCursor("package"), context, fileResolver);
- } catch (ParseException e) {
- throw new XMLStreamException(e);
- }
+ rootCursor.advance();
+ collectPackageMeasures(rootCursor.descendantElementCursor("package"), context, fileResolver);
}
});
parser.parse(xmlFile);
}
}
- private static void collectPackageMeasures(SMInputCursor pack, SensorContext context, final FileResolver fileResolver) throws ParseException, XMLStreamException {
+ private static void collectPackageMeasures(SMInputCursor pack, SensorContext context, final FileResolver fileResolver) throws XMLStreamException {
while (pack.getNext() != null) {
Map<String, CoverageMeasuresBuilder> builderByFilename = Maps.newHashMap();
collectFileMeasures(pack.descendantElementCursor("class"), builderByFilename);
return context.getResource(file) != null;
}
- private static void collectFileMeasures(SMInputCursor clazz, Map<String, CoverageMeasuresBuilder> builderByFilename) throws ParseException, XMLStreamException {
+ private static void collectFileMeasures(SMInputCursor clazz, Map<String, CoverageMeasuresBuilder> builderByFilename) throws XMLStreamException {
while (clazz.getNext() != null) {
String fileName = clazz.getAttrValue("filename");
CoverageMeasuresBuilder builder = builderByFilename.get(fileName);
}
}
- private static void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws ParseException, XMLStreamException {
+ private static void collectFileData(SMInputCursor clazz, CoverageMeasuresBuilder builder) throws XMLStreamException {
SMInputCursor line = clazz.childElementCursor("lines").advance().childElementCursor("line");
while (line.getNext() != null) {
int lineId = Integer.parseInt(line.getAttrValue("number"));
- builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH));
+ try {
+ builder.setHits(lineId, (int) parseNumber(line.getAttrValue("hits"), ENGLISH));
+ } catch (ParseException e) {
+ throw new XmlParserException(e);
+ }
String isBranch = line.getAttrValue("branch");
String text = line.getAttrValue("condition-coverage");