-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package edu.hm.hafner.coverage.parser; | ||
|
||
import java.io.IOException; | ||
Check warning on line 3 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
import java.io.Reader; | ||
import java.io.StringWriter; | ||
Check warning on line 5 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
import java.nio.file.Paths; | ||
import java.util.NoSuchElementException; | ||
|
||
import javax.xml.namespace.QName; | ||
import javax.xml.stream.XMLEventReader; | ||
import javax.xml.stream.XMLOutputFactory; | ||
Check warning on line 11 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
import javax.xml.stream.XMLStreamException; | ||
import javax.xml.stream.events.StartElement; | ||
import javax.xml.stream.events.XMLEvent; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
Check warning on line 16 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
|
||
import edu.hm.hafner.coverage.CoverageParser; | ||
import edu.hm.hafner.coverage.ModuleNode; | ||
import edu.hm.hafner.util.FilteredLog; | ||
import edu.hm.hafner.util.PathUtil; | ||
import edu.hm.hafner.util.SecureXmlParserFactory; | ||
import edu.hm.hafner.util.SecureXmlParserFactory.ParsingException; | ||
|
||
/** | ||
* A parser which parses reports made by OpenCover into a Java Object Model. | ||
* | ||
*/ | ||
public class OpenCoverParser extends CoverageParser { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private static final PathUtil PATH_UTIL = new PathUtil(); | ||
|
||
/** XML elements. */ | ||
private static final QName MODULE = new QName("Module"); | ||
private static final QName CLASS = new QName("Class"); | ||
|
||
@Override | ||
protected ModuleNode parseReport(final Reader reader, final FilteredLog log) { | ||
try { | ||
var eventReader = new SecureXmlParserFactory().createXmlEventReader(reader); | ||
var root = new ModuleNode("-"); | ||
boolean isEmpty = true; | ||
while (eventReader.hasNext()) { | ||
XMLEvent event = eventReader.nextEvent(); | ||
if (event.isStartElement()) { | ||
var startElement = event.asStartElement(); | ||
var tagName = startElement.getName(); | ||
if (MODULE.equals(tagName)) { | ||
Check warning on line 50 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
readModule(eventReader, root, startElement, log); | ||
Check warning on line 51 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
isEmpty = false; | ||
} | ||
Check warning on line 53 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / CPDCPD
Raw output
|
||
} | ||
} | ||
if (isEmpty) { | ||
throw new NoSuchElementException("No coverage information found in the specified file."); | ||
} | ||
return root; | ||
Check warning on line 59 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
} | ||
catch (XMLStreamException exception) { | ||
throw new ParsingException(exception); | ||
} | ||
} | ||
|
||
private void readModule(final XMLEventReader reader, final ModuleNode root, | ||
Check notice Code scanning / CodeQL Useless parameter Note
The parameter 'root' is never used.
Check warning on line 66 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / PMDUnusedFormalParameter
Raw output
|
||
final StartElement currentStartElement, final FilteredLog log) throws XMLStreamException { | ||
Check notice Code scanning / CodeQL Useless parameter Note
The parameter 'currentStartElement' is never used.
Check notice Code scanning / CodeQL Useless parameter Note
The parameter 'log' is never used.
Check warning on line 67 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / PMDUnusedFormalParameter
Raw output
Check warning on line 67 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / PMDUnusedFormalParameter
Raw output
|
||
|
||
while (reader.hasNext()) { | ||
Check warning on line 69 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Code CoveragePartially covered line
Check warning on line 69 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
XMLEvent event = reader.nextEvent(); | ||
|
||
if (event.isStartElement()) { | ||
var nextElement = event.asStartElement(); | ||
if (CLASS.equals(nextElement.getName())) { | ||
Check warning on line 74 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Code CoveragePartially covered line
Check warning on line 74 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
Check warning on line 74 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / SpotBugsUCF_USELESS_CONTROL_FLOW
Raw output
Check warning on line 74 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / CheckStyleEmptyBlockCheck
Raw output
|
||
// TODO: read class | ||
} | ||
} | ||
else if (event.isEndElement()) { | ||
Check warning on line 78 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Mutation CoverageMutation survived
Raw output
|
||
return; // finish processing of package | ||
} | ||
} | ||
} | ||
|
||
private String getFileName(final String relativePath) { | ||
var path = Paths.get(PATH_UTIL.getAbsolutePath(relativePath)).getFileName(); | ||
if (path == null) { | ||
return relativePath; | ||
} | ||
return path.toString(); | ||
Check warning on line 89 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / Code CoverageNot covered lines
Check warning on line 89 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / SpotBugsUPM_UNCALLED_PRIVATE_METHOD
Raw output
|
||
} | ||
Check warning on line 90 in src/main/java/edu/hm/hafner/coverage/parser/OpenCoverParser.java ci.jenkins.io / CPDCPD
Raw output
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package edu.hm.hafner.coverage.parser; | ||
|
||
import java.util.NoSuchElementException; | ||
Check warning on line 3 in src/test/java/edu/hm/hafner/coverage/parser/OpenCoverParserTest.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junitpioneer.jupiter.DefaultLocale; | ||
|
||
import edu.hm.hafner.coverage.CoverageParser; | ||
import edu.hm.hafner.coverage.ModuleNode; | ||
import edu.hm.hafner.util.SecureXmlParserFactory.ParsingException; | ||
Check warning on line 10 in src/test/java/edu/hm/hafner/coverage/parser/OpenCoverParserTest.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
|
||
@DefaultLocale("en") | ||
class OpenCoverParserTest extends AbstractParserTest { | ||
|
||
@Override | ||
CoverageParser createParser() { | ||
return new OpenCoverParser(); | ||
} | ||
|
||
@Test | ||
void shouldReadReport() { | ||
readExampleReport(); | ||
} | ||
|
||
@Override | ||
@Test | ||
void shouldFailWhenParsingInvalidFiles() { | ||
|
||
} | ||
|
||
private ModuleNode readExampleReport() { | ||
return readReport("opencover.xml", new OpenCoverParser()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<CoverageSession> | ||
<Summary numSequencePoints="15" visitedSequencePoints="9" numBranchPoints="6" visitedBranchPoints="3" sequenceCoverage="60" branchCoverage="50" maxCyclomaticComplexity="6" minCyclomaticComplexity="6" visitedClasses="1" numClasses="1" visitedMethods="1" numMethods="1" /> | ||
<Modules> | ||
<Module hash="31750BAB-054A-4C4B-8763-D76F95F0353A"> | ||
<ModulePath>ClassLibrary.dll</ModulePath> | ||
<ModuleTime>2019-12-13T01:36:13</ModuleTime> | ||
<ModuleName>ClassLibrary</ModuleName> | ||
<Files> | ||
<File uid="1" fullPath="[PLACEHOLDER]" /> | ||
</Files> | ||
<Classes> | ||
<Class> | ||
<Summary numSequencePoints="15" visitedSequencePoints="9" numBranchPoints="6" visitedBranchPoints="3" sequenceCoverage="60" branchCoverage="50" maxCyclomaticComplexity="6" minCyclomaticComplexity="6" visitedClasses="1" numClasses="1" visitedMethods="1" numMethods="1" /> | ||
<FullName>ClassLibrary.LibraryClass</FullName> | ||
<Methods> | ||
<Method cyclomaticComplexity="6" nPathComplexity="0" sequenceCoverage="60" branchCoverage="50" isConstructor="False" isGetter="False" isSetter="False" isStatic="True"> | ||
<Summary numSequencePoints="15" visitedSequencePoints="9" numBranchPoints="6" visitedBranchPoints="3" sequenceCoverage="60" branchCoverage="50" maxCyclomaticComplexity="6" minCyclomaticComplexity="6" visitedClasses="0" numClasses="0" visitedMethods="1" numMethods="1" /> | ||
<MetadataToken /> | ||
<Name>System.Int32 ClassLibrary.LibraryClass::Sum(System.Int32,System.Int32)</Name> | ||
<FileRef uid="1" /> | ||
<SequencePoints> | ||
<SequencePoint vc="2" uspid="8" ordinal="0" sl="8" sc="1" el="8" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="2" uspid="9" ordinal="1" sl="9" sc="1" el="9" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="2" uspid="10" ordinal="2" sl="10" sc="1" el="10" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="0" uspid="13" ordinal="3" sl="13" sc="1" el="13" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="0" uspid="14" ordinal="4" sl="14" sc="1" el="14" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="0" uspid="16" ordinal="5" sl="16" sc="1" el="16" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="0" uspid="17" ordinal="6" sl="17" sc="1" el="17" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="0" uspid="19" ordinal="7" sl="19" sc="1" el="19" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="0" uspid="20" ordinal="8" sl="20" sc="1" el="20" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="1" uspid="22" ordinal="9" sl="22" sc="1" el="22" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="1" uspid="23" ordinal="10" sl="23" sc="1" el="23" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="1" uspid="25" ordinal="11" sl="25" sc="1" el="25" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="1" uspid="26" ordinal="12" sl="26" sc="1" el="26" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="2" uspid="28" ordinal="13" sl="28" sc="1" el="28" ec="2" bec="0" bev="0" fileid="1" /> | ||
<SequencePoint vc="2" uspid="29" ordinal="14" sl="29" sc="1" el="29" ec="2" bec="0" bev="0" fileid="1" /> | ||
</SequencePoints> | ||
<BranchPoints> | ||
<BranchPoint vc="0" uspid="10" ordinal="1" path="1" offset="8" offsetend="35" sl="10" fileid="1" /> | ||
<BranchPoint vc="0" uspid="10" ordinal="2" path="2" offset="8" offsetend="44" sl="10" fileid="1" /> | ||
<BranchPoint vc="0" uspid="10" ordinal="3" path="3" offset="8" offsetend="53" sl="10" fileid="1" /> | ||
<BranchPoint vc="1" uspid="10" ordinal="4" path="4" offset="8" offsetend="62" sl="10" fileid="1" /> | ||
<BranchPoint vc="1" uspid="10" ordinal="5" path="5" offset="8" offsetend="71" sl="10" fileid="1" /> | ||
<BranchPoint vc="2" uspid="10" ordinal="0" path="0" offset="8" offsetend="80" sl="10" fileid="1" /> | ||
</BranchPoints> | ||
<MethodPoint vc="9" uspid="0" p8:type="SequencePoint" ordinal="0" offset="0" sc="0" sl="8" ec="1" el="29" bec="0" bev="0" fileid="1" xmlns:p8="xsi" /> | ||
</Method> | ||
</Methods> | ||
</Class> | ||
</Classes> | ||
</Module> | ||
</Modules> | ||
</CoverageSession> |