Hi Rodrigo,
the scope of the coverage report is defined by the classes you provide
to the analyzer, not by the content of the exec file. If you filter
classes from the exec file these classes simply show as not covered.
Instead of calling analyzer.analzeAll() on the root folder of your
classes iterate through the classses and only supply classes which are
you want to show in the report.
Regards,
-marc
On 2018-11-23 18:22, Rodrigo Amaro wrote:
Hi everyone.
I know that Jacoco offers some options in order to filter which
classes should be considered in the coverage report, but i sometimes
fell that they are not enough (as many people that i've talked to)
So i was wondering if it's possible to use Jacoco API to open the
.ec/.exec files and filter some files in order to get a more accurate
value given my filtering needs.
I've been playing with the API and i was able to load the .ec file
filter some stuff and generate a new HTML report. The problem is that
i expected that the coverage would increase since i'm no longer
considering some classes on the coverage report.
My code (Kotlin) is based on the examples provided on the
documentation:
class ExecDump(private val out: PrintStream) {
private var execFileLoader: ExecFileLoader? = null
/**
* Run this example with the given parameters.
*
* @param args
* command line parameters
* @throws IOException
* in case of error reading a input file
*/
@Throws(IOException::class)
fun execute(args: Array<String>) {
for (file in args) {
dump(file)
}
}
private fun dump(file: String) {
execFileLoader = ExecFileLoader()
execFileLoader!!.load(File(file))
execFileLoader!!.executionDataStore.contents
.filter { it.name.contains("$") }
.onEach {
execFileLoader!!.executionDataStore.contents.remove(it) }
val bundleCoverage = analyzeStructure()
bundleCoverage.packages.map { it.classes }
.onEach { pack ->
pack.filter { it.name.contains("$") }
.onEach { out.println(it.name) }
.onEach { pack.remove(it) }
}
val htmlFormatter = HTMLFormatter()
val visitor = htmlFormatter
.createVisitor(FileMultiReportOutput(File(".")))
// Initialize the report with all of the execution and session
visitor.visitInfo(execFileLoader?.sessionInfoStore?.infos,
execFileLoader?.executionDataStore?.contents)
visitor.visitBundle(bundleCoverage, DirectorySourceFileLocator(
File("path_to_source"), "utf-8", 4))
visitor.visitEnd()
}
@Throws(IOException::class)
private fun analyzeStructure(): IBundleCoverage {
val coverageBuilder = CoverageBuilder()
val analyzer = Analyzer(execFileLoader?.executionDataStore,
coverageBuilder)
analyzer.analyzeAll(File("path_to_classes"))
return coverageBuilder.getBundle("Report JaCoCos")
}
companion object {
@Throws(IOException::class)
@JvmStatic
fun main(args: Array<String>) {
ExecDump(System.out).execute(arrayOf("path_to_ec_file"))
}
}
}
Resuming:
- Is it possible to use a .ec file and rebuild it excluding some
classes?
- If yes, what should i change in the code above need to achieve it?
My goal, assuming this is possible, is to build a complementary gradle
plugin to help filtering these classes
--
You received this message because you are subscribed to the Google Groups "JaCoCo
and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jacoco/9964d0181581981bbf1be25111247f63%40mountainminds.com.
For more options, visit https://groups.google.com/d/optout.