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 jacoco+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/821c9d7a-cf59-45e9-b3af-1c4ee24ef0c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to