Loading coverage suite files from a plugin

已回答

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

0

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

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

Hi,

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

Anna 

1

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

Hi, Lyuben Todorov!
I also encountered the same problem as you. I need to map the jacoco exec file I ran to the IDE.
I don't know if you have implemented this function? If it is implemented, can you give me a reference?
Thanks!

0

请先登录再写评论。