Skip to content

Commit

Permalink
Simplify method.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Nov 14, 2023
1 parent 713bca8 commit acb0120
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,45 @@ protected ModuleNode parseReport(final Reader reader, final FilteredLog log) {
try {
var eventReader = new SecureXmlParserFactory().createXmlEventReader(reader);

var root = new ModuleNode("-");
boolean isEmpty = true;
var root = new ModuleNode("-"); // Cobertura has no support for module names
handleEmptyResult(log, readModule(log, eventReader, root));
return root;
}
catch (XMLStreamException exception) {
throw new ParsingException(exception);
}
}

while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
private boolean readModule(final FilteredLog log, final XMLEventReader eventReader, final ModuleNode root)
throws XMLStreamException {
boolean isEmpty = true;

if (event.isStartElement()) {
var startElement = event.asStartElement();
var tagName = startElement.getName();
if (SOURCE.equals(tagName)) {
readSource(eventReader, root);
}
else if (PACKAGE.equals(tagName)) {
readPackage(eventReader, root, readName(startElement), log);
isEmpty = false;
}
}
}
if (isEmpty) {
if (ignoreErrors()) {
log.logError("No coverage information found in the specified file.");
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();

if (event.isStartElement()) {
var startElement = event.asStartElement();
var tagName = startElement.getName();
if (SOURCE.equals(tagName)) {
readSource(eventReader, root);
}
else {
throw new NoSuchElementException("No coverage information found in the specified file.");
else if (PACKAGE.equals(tagName)) {
readPackage(eventReader, root, readName(startElement), log);
isEmpty = false;
}
}
return root;
}
catch (XMLStreamException exception) {
throw new ParsingException(exception);
return isEmpty;
}

private void handleEmptyResult(final FilteredLog log, final boolean isEmpty) {
if (isEmpty) {
if (ignoreErrors()) {

Check warning on line 122 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 122 is only partially covered, one branch is missing
log.logError("No coverage information found in the specified file.");

Check warning on line 123 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 123 is not covered by tests

Check warning on line 123 in src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/edu/hm/hafner/coverage/parser/CoberturaParser.java#L123

Added line #L123 was not covered by tests
}
else {
throw new NoSuchElementException("No coverage information found in the specified file.");
}
}
}

Expand Down

0 comments on commit acb0120

Please sign in to comment.