Re: [java code coverage] Jacoco API to filter report

2018-11-26 Thread ramaro
Hey Marc, yeah i'm aware of this. 

Actually the major point what i intended to was to filter some Kotlin 
generated code. I later discovered that version 0.8.2 does this by default, 
but i was struggling to configure it on my Android build.

After some Googling i've found out that i need to set this on Gradle

android.jacoco.version = '0.8.2'

instead (or along, don't know if its also needed)

jacoco.toolVersion = '0.8.2'

With this, all the cases i wanted to filter were covered. Still, i think 
that there's room to improve filtering with some minor tweaks on current 
gradle plugin or with a new plugin

Rodrigo


On Monday, November 26, 2018 at 2:15:49 PM UTC-2, Marc R. Hoffmann wrote:
>
> Hi Rodrigo,
>
> you do know that the gradle plugin already supports filtering on class 
> level? With the includes and excludes property you can specify patters for 
> the classfiles to include or exclude.
>
> Regards,
>
> -marc
>
>
> On 2018-11-26 13:18, ram...@uolinc.com  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) { 
>> > 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 = 

Re: [java code coverage] Jacoco API to filter report

2018-11-26 Thread Marc Hoffmann
Hi Rodrigo, 

you do know that the gradle plugin already supports filtering on class
level? With the includes and excludes property you can specify patters
for the classfiles to include or exclude. 

Regards, 

-marc 

On 2018-11-26 13:18, ram...@uolinc.com 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) { 
>>> 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 [1]) } 
>>> .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) { 
>>> 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/42f214f9-9d5b-4d4d-8f20-238fcd4e2c0f%40googlegroups.com
>  [2].
> For more options, visit https://groups.google.com/d/optout.

 

Links:
--
[1] http://it.name
[2]

Re: [java code coverage] Jacoco API to filter report

2018-11-26 Thread John A
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  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) {
>> > 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) {
>> > 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 

Re: [java code coverage] Jacoco API to filter report

2018-11-26 Thread ramaro
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) { 
> > 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) { 
> > 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/42f214f9-9d5b-4d4d-8f20-238fcd4e2c0f%40googlegroups.com.

Re: [java code coverage] Jacoco API to filter report

2018-11-26 Thread Marc Hoffmann

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) {
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) {
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/9964d0181581981bbf1be25111247f63%40mountainminds.com.
For more options, visit https://groups.google.com/d/optout.