galexandre / sonar-cobertura

Cobertura plugin for SonarQube
GNU General Public License v3.0
30 stars 26 forks source link

Cobertura ignoreTrivial for Sonar not reflecting. #14

Closed ntantri closed 6 years ago

ntantri commented 6 years ago

Hi,

We use this current plugin for integration with sonar and are quiet not getting the changes seen to eliminate getter and setter methods of the class when it comes to cobertura.

As explained here for the maven plugin: https://stackoverflow.com/questions/8225888/ignore-methods-in-class-cobertura-maven-plugin

I tried to do the same for sonar plugin using the following option:

mvn cobertura:cobertura -Dcobertura.ignoreTrivial=True sonar:sonar -Dsonar.host.url=###### \
-Dcobertura.report.format=xml -Dsonar.login=${SonarToken} -Dsonar.password=

Unfortunately this is not ignoring the getter's and setter's for us.

Could you help us to understand what more can be done?

Regards.

galexandre commented 6 years ago

Hi,

I implemented a similar system without using the -Dcobertura.ignoreTrivial=True. I created an interface like here : https://github.com/cobertura/cobertura/wiki/Coverage-Annotations

Then, I added the following piece of code in my pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.7</version>
    <configuration>
        <instrumentation>
            <ignoreMethodAnnotations>
               <ignoreMethodAnnotation>packageName.nameOfMyInterface</ignoreMethodAnnotation>
           </ignoreMethodAnnotations>
        </instrumentation>
    </configuration>
</plugin>

Then I use, the annotation @CoverageIgnore before the method I don't want to test.

However, there is an alternative solution, instead of avoiding the test of a getter/setter, make it easier in just couple of lines. For that you can have a look at this library: https://github.com/oshoukry/openpojo

Regards,

Geoffrey

ntantri commented 6 years ago

Hi Geoffrey,

Thanks for updating.

But adding @CoverageIgnore for all the getters and setters might be ideal for us.

And in case of the alternative solution, that is something not fitting us to replace our POJO's with.

Is there any way we can pass that ignoreTrivial and get rid of the test for getters and setters?

galexandre commented 6 years ago

Hi @tan31989,

Sorry for this late answer. I never used this flag personnaly, so I don't really know how to do that. I found this: https://stackoverflow.com/questions/9261731/is-there-still-no-solution-for-ignoring-setter-getter-other-trivial-methods-wi . I don't know if it helps.

ntantri commented 6 years ago

Hi @galexandre,

Thank you for the feedback, we have tried the above solution and it was not of any help.

We had no other choice but to choose Jacoco's integration.

Regards, Nagaraj