cobertura-maven-plugin 2.7

812 views
Skip to first unread message

pablo....@gmail.com

unread,
Sep 23, 2015, 5:33:51 AM9/23/15
to SonarQube
Hi,

To get cobertura coverage for integration tests, I need to upgrade cobertura-maven-plugin from version 2.6 to version 2.7. However, with this latest version, I get an 0.0% coverage in sonarqube, maybe due to some format change in cobertura's output file.

Is there some ongoing development to address this issue? Or do you know some workaround for this?

Regards,

    Pablo.

pablo....@gmail.com

unread,
Sep 23, 2015, 7:26:31 AM9/23/15
to SonarQube, pablo....@gmail.com
Hi,

I have compared the obtained coverage.xml with versions 2.6 and 2.7, and I don't see any important difference between the two files, apart from a new attribute "complexity" in the tag method. So I think the problem is not in the coverage.xml format.

Regards,

     Pablo.

Michel Pawlak

unread,
Sep 23, 2015, 1:55:57 PM9/23/15
to SonarQube, pablo....@gmail.com
Hi,

I'm not able to help you with your specific question about the cobertura-maven-plugin. However if you don't find an answer and/or if you need to separate UT from IT coverage + want to execute tests only once instead of twice (as cobertura-maven-plugin does), have a look at this alternative  :


This maven plugin outputs coverage data in a format that can be used as an input for SonarQube's generic test coverage plugin (and not Cobertura plugin for SonarQube).

Note : I just released the version 1.0.3 a few minutes ago, so if you decide to try it, having your feedback would be greatly appreciated.

Best regards,

Michel

pablo....@gmail.com

unread,
Sep 24, 2015, 4:39:43 AM9/24/15
to SonarQube, pablo....@gmail.com
Hi,

I have tested your plugin, and it looks promising to me. However, I get a lot of warnings saying that classes in the dependent jars are not found:

[WARNING] Unable to instrument file /home/jenkins/.jenkins/jobs/desktop/workspace/target/classes/es/horus/milenio/template/component/Text.class
java.lang.RuntimeException: java.lang.ClassNotFoundException: com/vaadin/ui/HorizontalLayout
	at net.sourceforge.cobertura.instrument.CoberturaClassWriter.getCommonSuperClass(CoberturaClassWriter.java:35)
	at org.objectweb.asm.ClassWriter.a(Unknown Source)
	at org.objectweb.asm.Frame.a(Unknown Source)
	at org.objectweb.asm.Frame.a(Unknown Source)
	at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
	at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
	at org.objectweb.asm.util.CheckMethodAdapter.visitMaxs(Unknown Source)
	at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
	at org.objectweb.asm.commons.LocalVariablesSorter.visitMaxs(Unknown Source)
	at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
	at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
	at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
	at org.objectweb.asm.util.CheckMethodAdapter.visitEnd(Unknown Source)
	at org.objectweb.asm.ClassReader.b(Unknown Source)
	at org.objectweb.asm.ClassReader.accept(Unknown Source)
	at org.objectweb.asm.ClassReader.accept(Unknown Source)
	at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:214)
	at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:129)
	at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:243)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.addInstrumentationToSingleClass(CodeInstrumentationTask.java:299)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.addInstrumentation(CodeInstrumentationTask.java:308)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.addInstrumentation(CodeInstrumentationTask.java:317)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.addInstrumentation(CodeInstrumentationTask.java:317)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.addInstrumentation(CodeInstrumentationTask.java:317)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.addInstrumentation(CodeInstrumentationTask.java:317)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.addInstrumentation(CodeInstrumentationTask.java:317)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.addInstrumentation(CodeInstrumentationTask.java:317)
	at net.sourceforge.cobertura.instrument.CodeInstrumentationTask.instrument(CodeInstrumentationTask.java:90)
	at net.sourceforge.cobertura.dsl.Cobertura.instrumentCode(Cobertura.java:74)
	at com.qualinsight.mojo.cobertura.core.AbstractInstrumentationMojo.processInstrumentation(AbstractInstrumentationMojo.java:138)
	at com.qualinsight.mojo.cobertura.core.AbstractInstrumentationMojo.execute(AbstractInstrumentationMojo.java:83)
	at com.qualinsight.mojo.cobertura.core.ITInstrumentationMojo.execute(ITInstrumentationMojo.java:22)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
	at org.jvnet.hudson.maven3.launcher.Maven31Launcher.main(Maven31Launcher.java:132)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:331)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)
	at jenkins.maven3.agent.Maven31Main.launch(Maven31Main.java:181)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at hudson.maven.Maven3Builder.call(Maven3Builder.java:136)
	at hudson.maven.Maven3Builder.call(Maven3Builder.java:71)
	at hudson.remoting.UserRequest.perform(UserRequest.java:121)
	at hudson.remoting.UserRequest.perform(UserRequest.java:49)
	at hudson.remoting.Request$2.run(Request.java:325)
	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com/vaadin/ui/HorizontalLayout
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:278)
	at net.sourceforge.cobertura.instrument.CoberturaClassWriter.getCommonSuperClass(CoberturaClassWriter.java:32)
	... 63 more

pablo....@gmail.com

unread,
Sep 24, 2015, 5:00:07 AM9/24/15
to SonarQube, pablo....@gmail.com
Hi,

I have noticed this warning is also issued with referenced superclasses:

[WARNING] Unable to instrument file /home/jenkins/.jenkins/jobs/desktop/workspace/target/classes/es/horus/milenio/modules/Historia/elementos/extracciones/ExtraccionBloqueCtl.class
java.lang.RuntimeException: java.lang.ClassNotFoundException: es/horus/milenio/modules/Historia/elementos/extracciones/ExtraccionBloqueTableItem

Also, How should I configure sonarqube? Is the cobertura plugin still required?


   Regards,

        Pablo.

Michel Pawlak

unread,
Sep 24, 2015, 6:04:19 AM9/24/15
to SonarQube, pablo....@gmail.com
Hi Pablo,

First of all thanks for your valuable feedback. I'll try to see what can be done concerning these warnings (external classes should not be required to compute coverage, but in this case warnings should not appear either. However I have to do some tests.) One question : is the superclass you're referring to in the same project or in another one ? It would be great if you could create a github issue on this matter.

Concerning your question about SQ configuration :
  • no you don't need the cobertura plugin anymore
  • you need to install SonarQube Generic Test Coverage plugin (available in update center)
  • once installed, in general settings you have a "generic coverage section" that needs to be configured as follows (if you haven't changed the default paths of the qualinsight-mojo-cobertura-core plugin) :
    • Coverage report paths : target/cobertura/ut/converted-coverage.xml
    • Integration tests coverage report paths : target/cobertura/it/converted-coverage.xml
  • the last path (Unit tests report paths) only needs to be modified if your surefire reports are generated in a non default place
  • that's it, you then have to run a mvn sonar:sonar after having built your project
Tell me if you need more information (I'll update the documentation as it may be useful to other people). I'll get back to you concerning the "Cobertura warnings" issue quickly.

Best regards,

Michel

Michel Pawlak

unread,
Sep 24, 2015, 10:47:46 AM9/24/15
to SonarQube, pablo....@gmail.com
Hi again,

I could not reproduce these warning messages locally. Do you have a specific logging configuration ?

Michel

pablo....@gmail.com

unread,
Sep 26, 2015, 1:30:53 PM9/26/15
to SonarQube, pablo....@gmail.com
Hi,

I have been doing some researching, but I can't find a common denominator for the warning messages. There are 84 warnings complaining for a missing class out of 1444 files in the project, some are simple beans, some are more complex classes, some are in the same project and some are from dependencies, so I can't figure what is causing this.

But if I understand well, this should not prevent the rest of classes from being instrumented. However, I'm getting a 0% coverage in sonar. I've inspected the converted-coverage.xml, and there's no covered="true" attributes, so I suspect that the IT are running from uninstrumented classes.

Does the jetty maven plugin I'm using need any special configuration? Where are the instrumented classes saved?

Regards,

      Pablo.

Michel Pawlak

unread,
Sep 26, 2015, 2:47:26 PM9/26/15
to SonarQube, pablo....@gmail.com
Hi again Pablo,

Well for classes in the same project, I don't understand what can be wrong (I ran the plugin on many projects and did not face this issue so far). Does the problem occur with UTs and ITs or just ITs ?

Back to your first stack trace, if I'm not wrong, Vaadin is based on GWT and other coverage tools (for instance clover) need to be tweaked in order to be able to compute coverage only on server side code. There is a "hidden" (or rather undocumented) parameter in the qualinsight-mojo-cobertura-core plugin that allows to pass inclusions/exclusions to Cobertura. However it is hidden... because I don't understand the format to be used (and thus I wasn't able to document it, nor to exclude a single class... and Cobertura's documentation is just misleading and unaligned with the code) I'll try to give you more information as soon as possible on this topic.

Iif you're using any framework that instruments code, you need to add a dependency to the framework in the plugin's configuration (this works for instance if you need to use openJPA offline instrumentation) otherwise you'll get similar warnings to the ones you're getting. You can try to add such dependencies for instance for Vaadin to check if that makes any difference.

In any case, It would be great if you could provide me the smallest possible code example that raises such warnings and a 0% code coverage as a github project (by smallest, I mean without any code specific to your project). In any case if only a few classes raise issues, it's odd that you get a 0% coverage.  It would allow me to try to help you more efficiently if I had a working example.

You should have my email if you receive email updates. Do not hesitate to send me directly an email (I don't want to spam the mailing list with issues not directly related to it)

Best regards,

Michel

Michel Pawlak

unread,
Sep 26, 2015, 3:47:57 PM9/26/15
to SonarQube, pablo....@gmail.com
One last point, can you please send me your pom.xml file(s) ?

Regards,

Michel

bubunia...@gmail.com

unread,
Mar 6, 2017, 10:03:35 AM3/6/17
to SonarQube, pablo....@gmail.com
Hi ,

We have multiple modules. m1, m2, and each have pom.xml and sonar-properties files. There is a pom.xml at the /root/bubunia folder as well which is parent pom.xml.
/root/bubunia/pom.xml
/root/bubunia/m1/pom.xml + /root/bubunia/m1/sonar.properties + src
/root/bubunia/m2/pom.xml + /root/bubunia/m2/sonar.properties + src

The problem is after running "mvn clean install pmd:pmd -DfailIfNoTests=false cobertura:cobertura -Pjenkins" the m1 or m2/report/coverage.xml is not getting generated in all modules folder(m1/m2) not the cobertura.ser(in /root/bubunia/m1/target/cobertura/cobertura.ser). Can you please help ? 
pom.xml snippet at /root/bubunia/pom.xml

<profiles>
                 <!-- Jenkins by default defines a property BUILD_NUMBER which is used to enable the profile. -->
                <profile>
                    <id>jenkins</id>
                    <activation>
                        <property>
                            <name>env.BUILD_NUMBER</name>
                        </property>
                    </activation>
                    <build>
                        <pluginManagement>
                            <plugins>
                                <plugin>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>cobertura-maven-plugin</artifactId>
                                    <version>2.6</version>
                                    <configuration>
                                        <outputDirectory>{project.modules}/report/cobertura/</outputDirectory>
                                        <formats>
                                            <format>html</format>
                                            <format>xml</format>
                                        </formats>
                                        <aggregate>true</aggregate>
                                        <instrumentation>
                                                <!--<ignores>
                                                  <ignore>com.example.boringcode.*</ignore>
                                                </ignores>-->
                                                <excludes>
                                                  <exclude>**/generated/*</exclude>
                                                  <exclude>**/entities/*</exclude>
                                                  <exclude>**/fmt/*</exclude>
                                                  <exclude>**/exceptions/*</exclude>
                                                  <exclude>**/constants/*</exclude>
                                                </excludes>
                                      </instrumentation>
                                    </configuration>
                                  </plugin>
                            </plugins>
                        </pluginManagement>
                    </build>
                </profile>
</profiles>
Reply all
Reply to author
Forward
0 new messages