Execute cobertura only from hudson using profiles

You can reduce the load of your developer machine by using maven profiles to execute the plugin only if you are running within hudson. Theconfiguration below shows how to enable the plugin based on the information if maven was started by hudson.

Execute cobertura only from hudson using profiles

It is highly recommend to reduce the workload of the developers machines by disabling the cobertura plugin and only using it from within hudson. The following excerpt from the parent shows how to do so:

Finally, you need a task to generate the xml report, where 'destdir' is where you want the report (coverage.xml) generated.

Your cobertura.ser is generated to your module root.

srcdir is where your *.java files are located. If you use multiple modules in one build process you need to include the module name, if you use the simple srcdir parameter. It is not required to include module name if you use fileset.

Version History

Compatibility InfoThe plug-in is being maintained by its owner/maintainers from a [new home:[https://wiki.jenkins-ci.org/display/JENKINS/Cobertura+Plugin]]. Check the Tier info for details of compatibility

Version 0.8.2 (4-Oct-2007)

Version 0.8.1 (28-Sep-2007)

Version 0.8 (20-Sep-2007)

Works with JDK 5 as well as JDK 6 (removing JDK dependency introduced during regression fixing)

Version 0.7 (20-Sep-2007)

Better fix of regressions introduced in 0.5

Version 0.6 (20-Sep-2007)

Fix of regressions introduced in 0.5

Version 0.5 (20-Sep-2007)

Now with built in source code painting! (Source code is available at the file level for the latest stable build only).

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!

The trend graph now works when there are broken builds in the build history.

Version 0.4 (29-Aug-2007)

Initial support for multi-report aggregation (may get totals incorrect if reports overlap for individual classes - I'll need to get source file painting support implemented to remove that issue. However, this is just how the files are parsed. This version will archive the files correctly so when it is fixed your history should report correctly)

Anonymous says:

After some hours, I got it to work with the Netbeans makefile.
The handling of...

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.

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.

Anonymous says:

I agree with the previous poster -- the HTML reports generated by Cobert...

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?

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.

Anonymous says:

The HTML coverage report is produced now - but there is a problem: The plug...

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.

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.

Anonymous says:

Perhaps I misunderstood what you meant - the report is produced and I can access...

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".

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)

Anonymous says:

Recenty, I am getting the following error when displayng the graph@:
Status Cod...

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?

Anonymous says:

MORE PRETTY PLEASE WITH EXTRA CATNIP ON TOP!
This is a Wiki. If you s...

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.

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...

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.

Hi, I have the same issue plus another one.
I have a main project with lots of ...

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.

Is there any plans to make this work with the built-in maven 2 project type? doh...

Is there any plans to make this work with the built-in maven 2 project type? doh, its already there! its just that i'm running a custom cobertura mojo called report-only and that was being detected by the hudson cobertura plugin. reports don't seem aggregated though...

Hello.
I've discovered that plugin doesn't work correctly if your build is unst...

Hello.

I've discovered that plugin doesn't work correctly if your build is unstable. For example if some of your unit tests failed then you got "Source code is unavailable" message although all reports are gathered and you can see coverage rate. Global link to cobertura report also would be broken or invalid because you may not have any live stable build or you last stable build is not actual

So I looked into code and noticed that method isSourceFileAvailable in CoverageResult.class looks like "... owner == owner.getProject().getLastStableBuild() && blah-blah-blah ...".

I think this is not really good, because in TDD you always have some errors in tests, so you would never see source code.

Maybe it is better to change code of isSourceFileAvailable to something like "...getProject().getLastSuccessfulBuild()..." and also fix urls that is generated by CoberturaProjectAction.class ?

There is a way to avoid doubled testing. We have added new "generate-report" goa...

There is a way to avoid doubled testing. We have added new "generate-report" goal to cobertura-maven-plugin, so you can instrument code before tests and generate xml report when tests (or integration-tests) phase is finished. See top.touk.pl

Hi,
I am using Maven2/SVN and the latest Hudson Cobertura plugin 0.8.5. I have t...

Hi,
I am using Maven2/SVN and the latest Hudson Cobertura plugin 0.8.5. I have the coverage report generated and all the settings set correctly, but I do not see the coverage report in Hudson either in the job or module pages. No errors in the log either. Any ideas of how else I can debug? Pretty much stuck.

I'm using Hudson 1.304 and Cobertura plugin 0.8.6. In my build.xml file I have the following that works fine when I build from the command line but it keeps on complaining about the task definition when is build by hudson. Any idea? Thank you.

I'm using Hudson 1.34 and Cobertura plugin 0.8.9 with Maven 2. When hudson builds the coverage.xml files they are corrupted. If I build my project in my IDE they are fine. Here is an example of they look like when hudson builds them.

It produces a coverage.xml file and several coverage#.xml files where the # is a number 1-10. Some of the numbered files appear to be more or less mangled copies of some of my .java files. It puts them in the .hudson/jobs/<MyProject>/builds/<Current build date and time> directory and then fails the build saying it can't parse them, which is no surprise. I have tried putting my cobertura plugin config stuff in my build tags or in my reporting tags or in both places in my pom, I have even just cut and pasted the config at the top of this page for the Single Project type and it all comes out the same. It does however work correctly with the maven "site" goal both with html and xml. Anyone know what I'm doing wrong that makes it not work with hudson?

I have the same issues. The cobertura plugin seems to copy everything from the s...

I have the same issues. The cobertura plugin seems to copy everything from the source directory ... even the stuff from my ".git"-SCM directory (I found a hook as coverage8.xml). I think 0.8.9 is bugged.

Edit:

Maybe hudson is bugged? I downgraded to 0.8.7 and the problem still persists. I'm running Hudson 1.315.

We have two build machines running Hudson, one Linux (openSUSE) and the other Wi...

We have two build machines running Hudson, one Linux (openSUSE) and the other Windows 2003. The plug-in works great on Linux, but it does not work on Windows. In fact, it causes the builds to fail. Both build machines are configured with the same version of the various components used.

We're using version 1.326 of Hudson, Maven version 2.2.1, JDK 1.6 update 16, and version 0.8.9 of this plug-in.

We have a parent POM that references child POM's via the <modules/> tag.

I've noticed that this plug-in shows method coverage stats -- but cobertura html reports don't show method coverage. I also don't see any explicit method coverage stats in the cobertura xml file. How are you getting method coverage? Are you getting it by looking at each method element in the report and generating those stats yourself?

Hi,
I've been running the cobertura plugin in Hudson for a couple of weeks now ...

Hi,

I've been running the cobertura plugin in Hudson for a couple of weeks now with no issues. All of a sudden, this morning, builds that were building correctly started failing. Looking in the console output it turns out that Hudson could not find the cobertura plugin. Nothing has changed as far as setup and configuration. I've tried disabling and enabling (with Hudson restarts) but cobertura is still not recognized by Hudson.

There seem to be 2 styles of graph available from the Cobetura plugin, for proje...

There seem to be 2 styles of graph available from the Cobetura plugin, for projects that have multiple Maven modules you get to see a trend over time, but if the project on has a single module, I get a bar chart that shows me the coverage for the last build.

I saw that Cobertura also calculates the cyclomatic complexity of all classes, b...

I saw that Cobertura also calculates the cyclomatic complexity of all classes, but in the Hudson Cobertura plugin this is not displayed anywhere. I had a look into the source code, it seems the corresponding XML attibute complexity is never evaluated by the plugin.

Can you confirm this? Is support for displaying the cyclomatic complexity planned for the near future?

Hi,
I have created a simple maven project.Having only App.java under main>ja...

Hi,

I have created a simple maven project.Having only App.java under main>java>src and one AppTest.java under test>java>src.
In App.java I have written a class called Calculator having add and substract method.In AppTest.java I have written testAdd and testSubstract.AppTest working fine when I run it through eclipse.Now I copied App.java and AppTest.java into the respective folder of my maven artifact.Now I run "mvn test" it shows "Build Successful"."Total test run 2".Now I have built the project in hudson.In the hudson build console same output is shown.Now I open up sonar and clicked on the sonar job to see the code coverage it shows

Code coverage Test success
- 0 tests
I am not getting why it is showing 0 test success when both in maven and hudson it is showing total test run 2.And one more thing how to see the code coverage.Please help