Loading coverage suite files from a plugin

Answered

Hi,

We're building a plugin related to Java testing and we rely a lot on running/compilling tests in the background, outside of IntelliJ's task system or anything else. We're using jacoco agents to generate coverage reports for the tests, however we cannot find a good way to load the reports without running jacococli and manually parsing a csv/html/xml report. Is there a convenient way to load a `jacoco.exec` data file directly into the IDE? This is the same action as the user going to Run -> Show Coverage Data and selecting a coverage suite, but automated. Alternatively, could you direct us to any source code/documentation for parsing jacoco reports? The classes given by jacoco don't make immediate sense. https://www.jacoco.org/jacoco/trunk/doc/api/org/jacoco/core/data/ExecutionDataStore.html 

Regards,

Lyuben

4 comments
Comment actions Permalink

Hi!

You can check how IDE loads the report here: `com.intellij.coverage.JaCoCoCoverageRunner#loadExecutionData`. But the documentation on jacoco library should be rather found on their site, it's not the reference implementation for sure

Anna

1
Comment actions Permalink

Hi,

Thank you very much for pointing me to the source code I was looking for! Is there a way to use the logic in this class directly from the context to a plugin? i.e. To load a jacoco coverage report from the context of a plugin, for example on some user action.The direction of extension kind of confuses me.

Regards,

Lyuben

0
Comment actions Permalink

Hi,

you can `com.intellij.coverage.CoverageDataManager#addExternalCoverageSuite` and then set the suite to the same manager.

Anna 

1
Comment actions Permalink

Extending my thanks, this solution works. Here's what I scrapped together for future reference.

val manager = CoverageDataManager.getInstance(project)
val virtualFile = LocalFileSystem.getInstance().findFileByPath(jacocoReportPath)!!

val coverageRunner = getCoverageRunner(virtualFile)

val coverageSuite: CoverageSuite = manager
.addExternalCoverageSuite(
virtualFile.name, virtualFile.timeStamp, coverageRunner,
DefaultCoverageFileProvider(virtualFile.path)
)

manager.chooseSuitesBundle(CoverageSuitesBundle(coverageSuite))
0

Please sign in to leave a comment.