You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JaCoCo version: the jacoco gradle plugin version 0.7.9 and whatever is used by Eclipse via EclEmma version 3.0.1
Operating system: MacOS
Tool integration: Gradle and Eclipse (via EclEmma version 3.0.1)
I have attached a super simple eclipse project which can repro the issue.
@matt-isaman@javax.annotation.Generated has @Retention(SOURCE) -
see https://docs.oracle.com/javase/7/docs/api/javax/annotation/Generated.html , so not presented in bytecode. Because of this Lombok for example has own annotation @lombok.Generated that has @Retention(CLASS), similarly Groovy recently introduced @groovy.transform.Generated. JaCoCo performs analysis of bytecode and can automatically filter methods marked by the last two. But there is nothing what we can do as long as there is no way to distinguish methods/classes based on bytecode of compiled source files generated by Immutables library. Is there a way to instruct Immutables library to generate another annotation? JaCoCo provides ability to exclude packages/classes by name pattern, maybe this is already sufficient?
Filtering by package/class name wouldn't be a general solution as the name of the generated classes can be customized via configuration and may vary depending on the purpose of the generated classes. So you would have to duplicate this configuration in the JaCoCo filtering configuration and wouldn't be a durable solution if anything in the Immutables configuration changed.
I have created an issue in their github repository to consider adding an annotation with class retention as Lombok and Groovy have.
It looks like immutables library will include such an annotation in it's 2.6 release.
I understood that recognizing this annotation will require changes to the jacoco code.
A runtime annotation is now added to the generated classes from the immutables project. Based on that annotation it should be possible to exclude that class from coverage analysis.
Any hints what I can do to do that? Or is there a plan to include that functionality in jacoco.
@Godin What do you think: Should we change our method filters to ignore a method when there is any *.Generated annotation? This would be a similar aproach as proposed in #675
While immutables/immutables#756 was marked as resolved and with latest version 2.6.1 some generated classes are annotated by org.immutables.value.Generated, seems that this is not the case for Builders - created immutables/immutables#792
What do you think: Should we change our method filters to ignore a method when there is any *.Generated annotation?
@marchof my memory tells me that we discussed this in past or at least was joking about that and for some reason decided to be concrete/precise, but I can't find any reference. Did you change your mind or this was in my dreams? 😆
Note that this case is different from previous ones - class receives annotation, not methods. Thanks to changes for #689 we now have easy access to class annotations from filters 😋
I was about to propose to implement this ticket as-is as we already do for others, and already prepared changes. And after that when this concrete feature and all test cases will be in place maybe reorganize into generic filter *.Generated. But now due to the above issue of missing annotations this concrete feature seems incomplete 😞 However we can still do this partially, leaving remaining cases in responsibility of library authors? Or directly do generic filter?
This would be a similar aproach as proposed in #675
"similar" but not exactly - #675 is less about generated code and more about manual tagging. And not sure that I like idea of manual tagging in general, especially with such a big granularity as method - today you manually tag simple method, tomorrow someone will update it up to complex one and this update will be completely missed. I prefer seeing low coverage for modified code as indication to do more careful review, than seeing 100% coverage because everything was excluded. Many times come across missing refactorings and unnecessary complexity because developers were trying to trick coverage. And even low coverage for whole application/modules rather than exclusions. Maybe we should think more/deeper about source-level annotations and enforcements around them? On the other hand already possible to abuse lombok.Generated and place it manually, however officially this is abuse rather than our statement - "yes, go ahead just exclude code instead of refactoring it into more testable and hence more maintainable". Or maybe this is out of our control and more of a philosophical/educational question.
What I for sure don't like in #675 - is usage of regex in general and the way of usage in particular. IMO this is an overkill and performance degradation should be easily observable.
@Godin Would it be possible to update the HTML report to alleviate some of the concerns over people tricking coverage or abusing these annotations? Something along the lines of adding a new HTML file, or a new section to the current file, where all the excluded classes/methods are listed along with the reason why they were excluded. This would allow developers to ignore coverage for generated classes/methods but not lose track of the fact that they are being ignored.
This would also allow for tooling around changes in the amount of code being excluded in the same way tools are used to display changes in coverage percentage between commits. If there was a suspiciously large bump in excluded code it would cause conscientious developers to double check why that happened and resolve any incorrect exclusions.
One risk, depending on how this is done, would be that certain tools which depend on and parse the output from jacoco may have issues.
@Godin#675 was created with the following scenario in mind:
A build would fail if the code coverage is not 100%
There is an ability to exclude certain parts of the code via annotations or comments
What is being excluded is clear and right there in pull requests
The team can then discuss the merit and reason why certain code is being excluded
The issue with percentage-based code coverage quality gate is that it is often not clear where the non-covered code is (unless one go through the report in details) and people can often trick coverage (e.g. write tests for the trivial parts but ignore the important bit).
As you mentioned, we can already "cheat" using the lombok.Generated annotation. It's just not nice having to use that for the above purpose.
Regarding the use of regex, if performance is a concern, I'm happy to update it in order to move the PR ahead.
@philieu First of all, I'm guilty for starting, but would prefer to stop hijacking this thread, which initially is about completely different subject - filtering of a code generated by Immutables library, and not at all about manual tagging.
Please also keep in mind that development and maintenance of JaCoCo library is not the only one of our activities, we will get back to story of manual tagging and to your PR in particular as soon as will be possible to have spare time to work on it properly.
Activity
Godin commentedon Mar 15, 2018
@matt-isaman
@javax.annotation.Generatedhas@Retention(SOURCE)-see https://docs.oracle.com/javase/7/docs/api/javax/annotation/Generated.html , so not presented in bytecode. Because of this Lombok for example has own annotation
@lombok.Generatedthat has@Retention(CLASS), similarly Groovy recently introduced@groovy.transform.Generated. JaCoCo performs analysis of bytecode and can automatically filter methods marked by the last two. But there is nothing what we can do as long as there is no way to distinguish methods/classes based on bytecode of compiled source files generated by Immutables library. Is there a way to instruct Immutables library to generate another annotation? JaCoCo provides ability to exclude packages/classes by name pattern, maybe this is already sufficient?matt-isaman commentedon Mar 15, 2018
Filtering by package/class name wouldn't be a general solution as the name of the generated classes can be customized via configuration and may vary depending on the purpose of the generated classes. So you would have to duplicate this configuration in the JaCoCo filtering configuration and wouldn't be a durable solution if anything in the Immutables configuration changed.
I have created an issue in their github repository to consider adding an annotation with class retention as Lombok and Groovy have.
cal101 commentedon May 22, 2018
It looks like immutables library will include such an annotation in it's 2.6 release.
I understood that recognizing this annotation will require changes to the jacoco code.
So why not go a small step further.
What about providing an annotation "@JacocoIgnore" that can be used as an annotation and as a meta annotation (https://www.intertech.com/Blog/spring-4-meta-annotations/) so that one can write custom annotations "@PlainGetterSetter" where the annotation itself is annoted with "@JacocoIgnore" and so serves two purposes:
Can anyone give a hint in which class/package this would be implemented?
Serranya commentedon May 28, 2018
A runtime annotation is now added to the generated classes from the immutables project. Based on that annotation it should be possible to exclude that class from coverage analysis.
Any hints what I can do to do that? Or is there a plan to include that functionality in jacoco.
marchof commentedon May 29, 2018
@Serranya Can you please provide a reference or documentation link?
Serranya commentedon May 29, 2018
@marchof
The relevant issue is this one: immutables/immutables#756
The annotation used is this: https://github.com/immutables/immutables/blob/edc79cf0e713e173dc7a74d2cd017fceea45faf0/value/src/org/immutables/value/Generated.java
I did not find the feature mentioned in the docs, but my generated class looks like this:
marchof commentedon May 29, 2018
@Godin What do you think: Should we change our method filters to ignore a method when there is any
*.Generatedannotation? This would be a similar aproach as proposed in #675gedl commentedon May 29, 2018
👍 for this feature
👍 👍 if annotations can be configurable on the pom or equivalent
cdir commentedon Jun 5, 2018
+1
Is there any possibility to configure the qualified name of the annotation that marks these generated methods?
Godin commentedon Jun 13, 2018
While immutables/immutables#756 was marked as resolved and with latest version 2.6.1 some generated classes are annotated by
org.immutables.value.Generated, seems that this is not the case for Builders - created immutables/immutables#792@marchof my memory tells me that we discussed this in past or at least was joking about that and for some reason decided to be concrete/precise, but I can't find any reference. Did you change your mind or this was in my dreams? 😆
Note that this case is different from previous ones - class receives annotation, not methods. Thanks to changes for #689 we now have easy access to class annotations from filters 😋
I was about to propose to implement this ticket as-is as we already do for others, and already prepared changes. And after that when this concrete feature and all test cases will be in place maybe reorganize into generic filter
*.Generated. But now due to the above issue of missing annotations this concrete feature seems incomplete 😞 However we can still do this partially, leaving remaining cases in responsibility of library authors? Or directly do generic filter?"similar" but not exactly - #675 is less about generated code and more about manual tagging. And not sure that I like idea of manual tagging in general, especially with such a big granularity as method - today you manually tag simple method, tomorrow someone will update it up to complex one and this update will be completely missed. I prefer seeing low coverage for modified code as indication to do more careful review, than seeing 100% coverage because everything was excluded. Many times come across missing refactorings and unnecessary complexity because developers were trying to trick coverage. And even low coverage for whole application/modules rather than exclusions. Maybe we should think more/deeper about source-level annotations and enforcements around them? On the other hand already possible to abuse
lombok.Generatedand place it manually, however officially this is abuse rather than our statement - "yes, go ahead just exclude code instead of refactoring it into more testable and hence more maintainable". Or maybe this is out of our control and more of a philosophical/educational question.What I for sure don't like in #675 - is usage of regex in general and the way of usage in particular. IMO this is an overkill and performance degradation should be easily observable.
matt-isaman commentedon Jun 13, 2018
@Godin Would it be possible to update the HTML report to alleviate some of the concerns over people tricking coverage or abusing these annotations? Something along the lines of adding a new HTML file, or a new section to the current file, where all the excluded classes/methods are listed along with the reason why they were excluded. This would allow developers to ignore coverage for generated classes/methods but not lose track of the fact that they are being ignored.
This would also allow for tooling around changes in the amount of code being excluded in the same way tools are used to display changes in coverage percentage between commits. If there was a suspiciously large bump in excluded code it would cause conscientious developers to double check why that happened and resolve any incorrect exclusions.
One risk, depending on how this is done, would be that certain tools which depend on and parse the output from jacoco may have issues.
philieu commentedon Jun 28, 2018
@Godin #675 was created with the following scenario in mind:
The issue with percentage-based code coverage quality gate is that it is often not clear where the non-covered code is (unless one go through the report in details) and people can often trick coverage (e.g. write tests for the trivial parts but ignore the important bit).
As you mentioned, we can already "cheat" using the lombok.Generated annotation. It's just not nice having to use that for the above purpose.
Regarding the use of regex, if performance is a concern, I'm happy to update it in order to move the PR ahead.
Godin commentedon Jun 28, 2018
@philieu First of all, I'm guilty for starting, but would prefer to stop hijacking this thread, which initially is about completely different subject - filtering of a code generated by
Immutableslibrary, and not at all about manual tagging.Please also keep in mind that development and maintenance of JaCoCo library is not the only one of our activities, we will get back to story of manual tagging and to your PR in particular as soon as will be possible to have spare time to work on it properly.
Thank you for your understanding.
philieu commentedon Jun 28, 2018
@Godin Sure, no worries. Was not meant to hijack the thread.
Godin commentedon Aug 16, 2018
While immutables/immutables#792 wasn't yet resolved, I'm closing this ticket, because on our side exclusion of classes and methods having
Generatedannotation with retention policyCLASSorRUNTIMEfrom any package was implemented in #731.