Issue Details (XML | Word | Printable)

Key: MCOBERTURA-61
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: James Burton
Votes: 70
Watchers: 52
Operations

If you were logged in you would be able to see more operations.
Maven 2.x Cobertura Plugin

HTML report shows all 100% but cobertura:check shows correct coverage - only in 2.1, works in 2.0

Created: 25/Jan/07 05:38 AM   Updated: 20/Nov/07 12:34 PM   Resolved: 20/Nov/07 12:34 PM
Return to search
Component/s: None
Affects Version/s: 2.1
Fix Version/s: 2.2

Time Tracking:
Not Specified

File Attachments: 1. Text File cobertura-datafile.patch (5 kB)
2. Zip Archive cobertura-test.zip (3 kB)

Environment: java 1.5.2_10, maven 2.0.4, windows XP SP2


 Description  « Hide

The cobertura HTML report shows everything 100%, yet the cobertura:check goal shows correct percentages complains about very low coverage, which is correct.

The HTML report is correct when I use your plugin version 2.0, and this error only shows up in 2.1.

Here are my dependencies, from the Maven site generator...

asm asm-all 2.2.3 - jar
aspectj aspectjrt 1.5.2a - jar
aspectj aspectjweaver 1.5.2a - jar
cglib cglib-nodep 2.1_3 - jar
commons-dbcp commons-dbcp 1.2 - jar
commons-lang commons-lang 2.2 - jar
freemarker freemarker 2.3.8 - jar
ibatis ibatis 2.3.0 - jar
net.sourceforge.jtds jtds 1.2 - jar
org.codehaus.xfire xfire-java5 1.2.4 - jar
org.codehaus.xfire xfire-jaxb2 1.2.4 - jar
org.codehaus.xfire xfire-spring 1.2.4 - jar
org.springframework spring 2.0.1 - jar
org.springframework spring-mock 2.0.1 - jar
quartz quartz 1.5.2 - jar
taglibs standard 1.1.2 - jar



James Burton added a comment - 25/Jan/07 05:48 AM

It also looks like the 2.1 HTML report also does not contain enough classes.


Jacob Robertson added a comment - 01/Feb/07 03:11 PM

I voted for this. It's kind of silly that we had to start using the previous version. Our experience is that it also always shows the branch coverage as N/A.


Mirko Nasato added a comment - 01/May/07 10:13 AM

Ok so I downloaded the plugin source code and found this interesting comment in class CoberturaInstrumentMojo

// Old, Broken way
System.setProperty( "net.sourceforge.cobertura.datafile", dataFile.getPath() );

/* New, Fixed way.

I then applied the patch from the mentioned issue to Cobertura 1.8, recompiled and copied the patched cobertura.jar into my local Maven repository. Surely enough that fixed the problem.

Basically the Maven plugin v2.1 requires a patched version of Cobertura 1.8. Maybe this patched version should be made available in the Maven repository? (Ideally that should have been done before releasing the plugin...)


Mirko Nasato added a comment - 14/May/07 06:33 AM

As a temporary, unofficial, unsupported, use-at-your-own-risk workaround I made available a patched version of Cobertura 1.8 - built as explained above - here

http://www.artofsolving.com/files/m2/cobertura-1.8.jar

You can copy it in your local repository, overriding the one retrieved from the official maven repository.


Dirk Olmes added a comment - 14/May/07 09:14 AM

For those of you out there still on JDK here's a version that was built with 1.4: http://dist.codehaus.org/mule/dependencies/maven2/cobertura/cobertura/1.8/cobertura-1.8.jar


md added a comment - 25/Jun/07 05:42 PM

I have a multi-module project. using the patched version fixed the coverage problems for one module. But I still see 0% for some modules and 100% for others.


Paul Sundling added a comment - 02/Jul/07 08:54 PM

There are other projects that have public cobertura reports that have this problem. For a live example see the PMD plugin!

http://maven.apache.org/plugins/maven-pmd-plugin/cobertura/index.html

Thanks, I'm using 2.0 now, thanks for the tip.

Paul Sundling


Daniel Takai added a comment - 03/Jul/07 07:12 AM

I'm experiencing the same problem. Unfortunately i'm also unable to switch to 2.0 because of the multi-project problems. Cannot try the cobertura patch since I won't dirty my repo. I'll vote for this issue!


Peter Feltham added a comment - 27/Jul/07 01:04 AM

I have developed a patch to the cobertura-maven-plugin that fixes the original problem, and works with the released Cobertura 1.8 (ie. it does NOT require a patched Cobertura).

The trick is that the plugin needs to configure the Maven Surefire plugin's "systemProperties" property.

As a workaround for anyone that doesn't want to patch anything, the following snippet in your POM will get Cobertura working properly with the standard released versions of everything:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>net.sourceforge.cobertura.datafile</name>
<value>${project.build.directory}/cobertura/cobertura.ser</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>

If you want to put this in the root pom of a multi-module project, the property expansion ${project.build.directory} doesn't seem to work so just replace it with "target".


Sean Woodhouse added a comment - 06/Aug/07 12:58 AM

Thanks Peter. Setting net.sourceforge.cobertura.datafile worked for me.

Cheers

Sean.


Daniel Takai added a comment - 06/Aug/07 03:58 AM

Setting net.sourceforge.cobertura.datafile worked for me too. Thanks a lot!


Damien Lecan added a comment - 23/Aug/07 04:07 AM

Setting net.sourceforge.cobertura.datafile worked for me too.
Thanks a lot too!


Chris Beams added a comment - 05/Nov/07 08:01 PM

Peter - just want to chime in with my thanks, too. Your fix worked perfectly for me.


Dennis Lundberg added a comment - 19/Nov/07 03:54 PM

Can someone please attach a test project that can be used to reproduce this problem.


Peter Feltham added a comment - 19/Nov/07 04:21 PM - edited

I've attached a simple maven project (cobertura-test.zip) that demonstrates the released cobertura plugin's incorrect behaviour. Uncomment the surefire-plugin configuration in the pom to see the workaround in action.


Dennis Lundberg added a comment - 19/Nov/07 04:51 PM

Thanks for the project Peter. Here are my findings using it together with Maven 2.0.4, Java 1.4.2_16 and Win XP SP2. I tried different versions of the cobertura-plugin to see how they compared:

maven-cobertura-plugin 2.0: 53% coverage
maven-cobertura-plugin 2.1: 100% coverage
maven-cobertura-plugin 2.2-SNAPSHOT: 53% coverage

To me it seems as if this issue has been resolved in the latest code available in trunk. I have test failures locally, but I have gone ahead and deployed a new 2.2-SNAPSHOT anyway, using "-Dmaven.test.skip=true".

Please give it a try in your respective environments. Post the results here.


Peter Feltham added a comment - 19/Nov/07 07:52 PM

Thanks Dennis. Same results for me, with Maven 2.0.4, Java 1.5.0_07 and Win XP SP2.

2.2-SNAPSHOT is working now because cobertura 1.9 has been released which reads the cobertura.properties file as required - so the next release of maven-cobertura-plugin will fix this issue.


Dennis Lundberg added a comment - 20/Nov/07 12:34 PM

Thanks for verifying that Peter.