Hi John

Take a look a these classes on my project. It's not finished as i had to 
move to some other tasks but it's enough for filtering

https://raw.githubusercontent.com/RodrigoAmaroEng/jacoco-filter-plugin/master/library/src/main/kotlin/br/eng/rodrigoamaro/jacoco/Converter.kt
https://raw.githubusercontent.com/RodrigoAmaroEng/jacoco-filter-plugin/master/library/src/main/kotlin/br/eng/rodrigoamaro/jacoco/FilteredCoverageBuilder.kt

Rodrigo

On Monday, November 26, 2018 at 1:16:23 PM UTC-2, John A wrote:
>
> Rodrigo,
>
> Would you be willing to share your code? I'm looking for something similar 
> and your code would be an easy and quick starting point.
>
> John
>
> On Mon, Nov 26, 2018, 04:18 <ram...@uolinc.com <javascript:> wrote:
>
>> Hey Marc, thanks for your reply.
>>
>> I was able to achieve what i intended to by build a 
>> custom CoverageBuilder class and overriding the visitCoverage method.
>>
>> Building a report with the same code i've submitted (but using this 
>> custom class) generates a Report without the classes filtered by the custom 
>> class and considering only the classes i want on the coverage.
>>
>> Right now i'm trying to organize this code to provide a gradle plugin 
>> that would help configuring these filters
>>
>> Regards,
>> Rodrigo
>>
>> On Monday, November 26, 2018 at 7:30:40 AM UTC-2, Marc R. Hoffmann wrote:
>>>
>>> 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 jacoco+un...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jacoco/42f214f9-9d5b-4d4d-8f20-238fcd4e2c0f%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/jacoco/42f214f9-9d5b-4d4d-8f20-238fcd4e2c0f%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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/4c307c13-d3b6-4d20-902b-f3a438adcc21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to