|
This plugin allows you to capture code coverage report from Cobertura. Hudson will generate the trend report of coverage. Configuring the Cobertura Plugin
Configuring build toolsHere are the configuration details for common build tools. Please feel free to update this with corrections or additions. Maven 2Single ProjectIf you are using a single module configuration, add the following into your pom.xml
<project ...>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version> <!-- This version is needed to allow generating the xml reports AFAIK -->
<configuration>
<formats>
<format>xml</format>
<!-- if you still want the HTML reports just add another format entry with html as the value -->
</formats>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
</project>
Project hierarchieIf you are using a common parent for all Maven2 modules you can move the plugin configuration to the pluginManagement section of the common parent... <project ...>
...
<build>
...
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version> <!-- This version is needed to allow generating the xml reports AFAIK -->
<configuration>
<formats>
<format>xml</format>
<!-- if you still want the HTML reports just add another format entry with html as the value -->
</formats>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
...
</build>
...
</project>
And add the plugin group and artifact to the children <project ...>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
...
</plugins>
...
</build>
...
</project>
AntNote these instructions are untested as I use Maven2. If somebody can check and either fix them or remove this bolded text! <property name="cobertura.dir" value="C:/javastuff/cobertura" /> <path id="cobertura.classpath"> <fileset dir="${cobertura.dir}"> <include name="cobertura.jar" /> <include name="lib/**/*.jar" /> </fileset> </path> <taskdef classpathref="cobertura.classpath" resource="tasks.properties" /> You'll need to instrument the classes, e.g. <cobertura-instrument todir="${instrumented.dir}"> <ignore regex="org.apache.log4j.*" /> <fileset dir="${classes.dir}"> <include name="**/*.class" /> <exclude name="**/*Test.class" /> </fileset> <fileset dir="${guiclasses.dir}"> <include name="**/*.class" /> <exclude name="**/*Test.class" /> </fileset> <fileset dir="${jars.dir}"> <include name="my-simple-plugin.jar" /> </fileset> </cobertura-instrument> Here's an example call to the JUnit ant task that has been modified to work with Cobertura.
<junit fork="yes" dir="${basedir}" failureProperty="test.failed"> <!-- Specify the name of the coverage data file to use. The value specified below is the default. --> <sysproperty key="net.sourceforge.cobertura.datafile" file="${basedir}/cobertura.ser" /> <!-- Note the classpath order: instrumented classes are before the original (uninstrumented) classes. This is important. --> <classpath location="${instrumented.dir}" /> <classpath location="${classes.dir}" /> <!-- The instrumented classes reference classes used by the Cobertura runtime, so Cobertura and its dependencies must be on your classpath. --> <classpath refid="cobertura.classpath" /> <formatter type="xml" /> <test name="${testcase}" todir="${reports.xml.dir}" if="testcase" /> <batchtest todir="${reports.xml.dir}" unless="testcase"> <fileset dir="${src.dir}"> <include name="**/*Test.java" /> </fileset> </batchtest> </junit> Finally, you need a task to generate the xml report: <cobertura-report format="xml" destdir="${coveragereport.dir}" srcdir="${src.dir}" />
Version HistoryUpcoming Version
Version 0.8.4 (21/10/2007)
Version 0.8.3 (12/10/2007)
Version 0.8.2 (4/10/2007)
Version 0.8.1 (28/09/2007)
Version 0.8 (20/09/2007)
Version 0.7 (20/09/2007)
Version 0.6 (20/09/2007)
Version 0.5 (20/09/2007)
Note that the conditional coverage is the highest coverage from all the cobertura reports aggregated in each build. Thus if you have two reports and one covers only 50% of a conditional and the other covers a different 25%, conditional coverage will be reported as 50% and not the 75% that you could argue it should be!
Version 0.4 (29/08/2007)
Version 0.3 (28/08/2007)
Version 0.2 (28/08/2007)
Version 0.1 (27/08/2007)
|

Comments (29)
Sep 02, 2007
Anonymous says:
After some hours, I got it to work with the Netbeans makefile. :) The handling o...After some hours, I got it to work with the Netbeans makefile.
The handling of build.properties and project.properties was a bit tricky for me as a novice Ant user, because I don't wanted to "pollute" the other workstations in our working group with dependencies to cobertura. Besides, there seems to be a bug with the datafile attribute, which should define the position of cobertura.ser, but in fact this attribute doesn't work correctly.
I was a bit dissapointed about the graphical representation of the Cobertura report in the Hudson plugin, knowing the HTML report of Cobertura. Isn't there a possibility to let Cobertura produce the HTML report and put a link to it in Hudson?
But alltogether I became an entusiastic user of Hudson in the last four days! It's really an excellent tool.
Sep 20, 2007
Stephen Connolly says:
Could you please add a section into this page detailing how to get this plugin w...Could you please add a section into this page detailing how to get this plugin working with the Netbeans makefile?
Sep 23, 2007
Jessica-Aileen says:
There is no magic with it. I've simply used the advices from this blog:There is no magic with it. I've simply used the advices from this blog: http://weblogs.java.net/blog/fabriziogiudici/archive/2006/11/setting_up_netb.html
If I have more time I'll post my configuration for findbugs, violations (pmd, findbugs, cpd, checkstyle) and cobertura. But it shouldn't be a problem with Fabrizios blog entry to make a suitable buildfile.
Sep 02, 2007
Anonymous says:
I agree with the previous poster \\ the HTML reports generated by Cobertura are ...I agree with the previous poster -- the HTML reports generated by Cobertura are great. My ANT file already generates those -- so what I want (in addition to the timeline graph) is to put a link to the coverage reports in my build status page. That has to be easy, right?
Sep 14, 2007
Anonymous says:
\1 for integrating the plain Cobertura reports in some way or another. The plugi...+1 for integrating the plain Cobertura reports in some way or another.
The plugin is great by the way
Sep 19, 2007
Stephen Connolly says:
The issue with integrating the plain Cobertura reports is that this plugin is ag...The issue with integrating the plain Cobertura reports is that this plugin is aggregating multiple cobertura reports, so I have to generate the HTML report by hand. The code for this is getting close to ready, but I was on holidays and have a backlog in work before I can get to it.
Sep 20, 2007
Stephen Connolly says:
See Version 0.5 which was released todaySee Version 0.5 which was released today
Sep 21, 2007
Anonymous says:
The HTML coverage report is produced now :) \ but there is a problem: The plugin...The HTML coverage report is produced now
- but there is a problem: The plugin doesn't include it! It seems to be that the plugin ist awaiting the HTML report in a "hard wired" directory named "cobertura" in the jobname-directory under jobs.
There should be a possibility to tell the plugin where the destination directory is - in the same way that you define the "Cobertura xml report pattern" in the project configuration.
At the moment I can't find out how to tell cobertura to use the hard-wired directory - but it is nearly midnight now.
Sep 21, 2007
Anonymous says:
It makes no difference if the report is in the cobertura directory or elsewhere:...It makes no difference if the report is in the cobertura directory or elsewhere: The plugin claims "Source code is unavailable". Two minutes past midnight now ...
Sep 22, 2007
Stephen Connolly says:
The source code will only be available for the most recent build. Disk spa...The source code will only be available for the most recent build. Disk space is cheap, but not cheap enough to save it for every build. Also, there is not much use in knowing the past source code coverage (and there is the method level coverage for such anyway)
If you are not seeing the source code for the most recent build, please file an issue and I'll have a look.
Sep 22, 2007
Anonymous says:
Perhaps I misunderstood what you meant the report is produced and I can access i...Perhaps I misunderstood what you meant - the report is produced and I can access it via the workspace hierarchy in hudson. But there is no link in the report itself. Where I assume it should be, in the detailed report generated by the plugin, there is only the text "Source code is unavailable".
Where can I file the issue - in the hudson issue tracker?
Sep 23, 2007
Stephen Connolly says:
Yes the issue tracker is the best place for it. The basic idea is that the plugi...Yes the issue tracker is the best place for it.
The basic idea is that the plugin goes looking for the source code in all the places that cobertura says it could have been. If it did not find the source code then you won't see it.
what version of cobertura are you using (most of my testing is with 1.9)
Sep 23, 2007
Jessica-Aileen says:
I've filed it as https://hudson.dev.java.net/issues/showbug.cgi?id=846I've filed it as https://hudson.dev.java.net/issues/show_bug.cgi?id=846
Oct 11, 2007
Anonymous says:
The plugin does not work. I have Cobertura successfully generating both HTML and...The plugin does not work. I have Cobertura successfully generating both HTML and XML reports as part of the build. I have the XML pattern set in the plugin configuration and it's able to find it successfully. But that's where the magic stops.
Here is the output from the log:Recording test results
Publishing Cobertura coverage report...
Publishing Cobertura coverage results...
FATAL: /local/bamboo/.hudson/jobs/MYJOB/cobertura/com/foo/dec/framework/dataAccessServices (Is a directory)
java.io.FileNotFoundException: /local/bamboo/.hudson/jobs/MYJOB/cobertura/com/foo/dec/framework/dataAccessServices (Is a directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at hudson.FilePath.write(FilePath.java:600)
at hudson.plugins.cobertura.renderers.SourceCodePainter.paintSourceCode(SourceCodePainter.java:48)
at hudson.plugins.cobertura.renderers.SourceCodePainter.invoke(SourceCodePainter.java:127)
at hudson.plugins.cobertura.renderers.SourceCodePainter.invoke(SourceCodePainter.java:28)
at hudson.FilePath.act(FilePath.java:280)
at hudson.plugins.cobertura.CoberturaPublisher.perform(CoberturaPublisher.java:250)
at hudson.model.Build$RunnerImpl.post2(Build.java:138)
at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:244)
at hudson.model.Run.run(Run.java:597)
at hudson.model.Build.run(Build.java:103)
at hudson.model.ResourceController.execute(ResourceController.java:66)
at hudson.model.Executor.run(Executor.java:62)
Oct 21, 2007
Anonymous says:
Have you filed an issue with respect to this? The best way to get attention is t...Have you filed an issue with respect to this?
The best way to get attention is to file an issue or post on the mailing list.
Oct 24, 2007
Anonymous says:
Recenty, I am getting the following error when displayng the graph@:\\ Status C...Recenty, I am getting the following error when displayng the graph@:
Status Code: 500
Exception:
Stacktrace: java.lang.LinkageError: hudson/util/ChartUtil
at hudson.plugins.cobertura.targets.CoverageResult.doGraph(CoverageResult.java:298)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:103)
at org.kohsuke.stapler.Function.bindAndinvoke(Function.java:59)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:63)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:30)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:294)
at org.kohsuke.stapler.MetaClass$15.dispatch(MetaClass.java:361)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:294)
at org.kohsuke.stapler.MetaClass$7.doDispatch(MetaClass.java:208)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:30)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:294)
at org.kohsuke.stapler.MetaClass$9.doDispatch(MetaClass.java:240)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:30)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:294)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:231)
at org.kohsuke.stapler.Stapler.service(Stapler.java:79)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:45)
at winstone.ServletConfiguration.execute(ServletConfiguration.java:249)
at winstone.RequestDispatcher.forward(RequestDispatcher.java:335)
at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:378)
at hudson.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:79)
at winstone.FilterConfiguration.execute(FilterConfiguration.java:195)
at winstone.RequestDispatcher.doFilter(RequestDispatcher.java:368)
at winstone.RequestDispatcher.forward(RequestDispatcher.java:333)
at winstone.RequestHandlerThread.processRequest(RequestHandlerThread.java:244)
at winstone.RequestHandlerThread.run(RequestHandlerThread.java:150)
at java.lang.Thread.run(Unknown Source)
Any ideas what maybe wrong?
Oct 24, 2007
Anonymous says:
{}PRETTY PLEASE WITH CATNIP ON TOP\! File an issue https://hudson.dev.java.net/s...PRETTY PLEASE WITH CATNIP ON TOP!
File an issue
Or at least post your question on the mailing list
Nobody is watching this comments section
Oct 31, 2007
Anonymous says:
The instructions above say that examples for maven and ant are below. I don't se...The instructions above say that examples for maven and ant are below. I don't see any such examples. Maybe they could be more attention-getting. thanks.
Nov 02, 2007
Anonymous says:
i second that.i second that.
Nov 16, 2007
Stephen Connolly says:
{}MORE PRETTY PLEASE WITH EXTRA CATNIP ON TOP\! This is a Wiki. If you spo...MORE PRETTY PLEASE WITH EXTRA CATNIP ON TOP!
This is a Wiki. If you spot something that is incorrect, please correct it. If you spot something that is missing, please add it. If you spot something that should be there but is not, please add a placeholder.
Mar 27
Mike Haller says:
Stephen, i tried to query the issue tracker but no luck. The dev.java.net issue ...Stephen, i tried to query the issue tracker but no luck. The dev.java.net issue tracker is very unusable. Userfriendlyness equals zero.
According to the current version of SourceCodePainter in source control, there have already been changes. Do you know the cause of the FileNotFound Exception or how to circumvent this issue?
Dec 12, 2007
Mike Caron says:
Just started using this. Really cool work, but it seems like the HTML reports ge...Just started using this. Really cool work, but it seems like the HTML reports gen'd by the plugin always report 100%, even though the weather is accurate and the file view reports correct red and green lines. I became an observer so that I could grab the code and work on it. I also like the idea of linking the "Coverage Report" to the original HTML reports, so I was going to do that too. Of course, I'd provide patches. But I first need code access...
Jun 02
fabrice says:
I use Hudson ver. 1.219 and I verified my cobertura config matches this on ...I use Hudson ver. 1.219 and I verified my cobertura config matches this on this webpage, HTML and XML files are generated in target/site/cobertura but there is no image generated on the job page, no link which allow me to see cobertura reports and trends.
I think it is a bug.
Jun 03
Jose Muanis says:
Just updated hudson to 1.220, cobertura plugin version 0.8.4 Build ok, coverage....Just updated hudson to 1.220, cobertura plugin version 0.8.4
Build ok, coverage.xml being generated just as expected in this tutorial. but I get no image nor link on the status page.
No kind of errors in the log file.
Any ideas where I can find information to help finding this bug?
Jun 04
fabrice says:
ouf I am not alone on this new problem :) help us :)ouf I am not alone on this new problem
help us
Jun 04
Jose Muanis says:
Fabrice, I've checked out version 0.8.5SNAPSHOT and its working. But...Fabrice,
I've checked out version 0.8.5-SNAPSHOT and its working.
But anyway, the coverage reports only apper at module page
Jun 05
fabrice says:
Ok nice It would be nice too if we have a new stable release. When ?Ok nice
It would be nice too if we have a new stable release. When ?
Jun 18
truong van nga says:
Hi, have you some news about a stable release of this plugin? I can only downloa...Hi, have you some news about a stable release of this plugin?
I can only download the 0.8.4 which is not working
the report don't appear on the web site (but my coverage.xml are generated)
Is the 0.8.5-SNAPSHOT always available? and where?
Jun 26
Nicolas Ruffel says:
Hi, I have the same issue plus another one. I have a main project with lots of s...Hi, I have the same issue plus another one.
I have a main project with lots of sub-projects. I configured only one job for the main project (using maven2) and it calls allthe sub modules. Great. But I want the cobertura reports generated without running the tests twice.
If I call the goal "install", cobertura is not run. If I run "cobertura:cobertura", some modules are tested with some old dependencies since some new packages haven't been "installed" in the repository. "install cobertura:cobertura" works, but it runs tests twice.
What am I doing wrong?
Thanks for your hints