Child pages
  • Cobertura Plugin
Skip to end of metadata
Go to start of metadata

Plugin Information

Plugin ID

cobertura

Changes

In Latest Release
Since Latest Release

Latest Release
Latest Release Date
Required Core
Dependencies

1.11 (archives)
Aug 09, 2017
2.13
dashboard-view (version:2.9.9, optional)

Source Code
Issue Tracking
Pull Requests
Maintainer(s)

GitHub
Open Issues
Pull Requests
Steven Christou (id: schristou)
Michael Barrientos (id: mbarrien)
Jeff Pearce (id: jeffpearce)

Usage

Installations

2016-Nov 16078
2016-Dec 15859
2017-Jan 16654
2017-Feb 16766
2017-Mar 17670
2017-Apr 17224
2017-May 18026
2017-Jun 18030
2017-Jul 17954
2017-Aug 18567
2017-Sep 18470
2017-Oct 18650

The current thinking is to merge this plugin into more generic coverage plugin. Help appreciated.

This plugin allows you to capture code coverage report from Cobertura. Jenkins will generate the trend report of coverage.The Cobertura plugin can be downloaded here.

Configuring the Cobertura Plugin

  1. Install the cobertura plugin (via Manage Jenkins -> Manage Plugins)
  2. Configure your project's build script to generate cobertura XML reports (See below for examples with Ant and Maven2)
  3. Enable the "Publish Cobertura Coverage Report" publisher
  4. Specify the directory where the coverage.xml report is generated.
  5. (Optional) Configure the coverage metric targets to reflect your goals.

Configuring build tools

Here are the configuration details for common build tools. Please feel free to update this with corrections or additions.

Maven 2

Quick configuration

You can either, enable "cobertura" analysis in your 'pom.xml' files or just tell Jenkins to run "cobertura" goal.

If you don't want to change your pom files, just add the goal 'cobertura:cobertura' to your Maven project in Jenkins.

Single Project

If you are using a single module configuration, add the following into your pom.xml. This will cause cobertura to be called each time you run "mvn package".

<project ...>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <formats>
                        <format>xml</format>
                    </formats>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
    ...
</project>

 

Execute cobertura only from Jenkins 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 Jenkins. The configuration below shows how to enable the plugin based on the information if maven was started by Jenkins.

 

<project ...>
    ...
    <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>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>cobertura-maven-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <formats>
                                <format>xml</format>
                            </formats>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>cobertura</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    ...
</project>

Project hierarchies

If 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>
                    <configuration>
                        <formats>
                            <format>xml</format>
                        </formats>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>cobertura</goal>
                            </goals>
                        </execution>
                    </executions>
                </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>

Execute cobertura only from Jenkins 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 Jenkins. The following excerpt from the parent shows how to do so:

<project ...>
    ...
    <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.2</version>
                            <configuration>
                                <formats>
                                    <format>xml</format>
                                </formats>
                            </configuration>
                            <executions>
                                <execution>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>cobertura</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>
    ...
</project>

 Now that your parent is only using the plugin management section if it is running from within Jenkins, you need the childern poms adapted as well:

<project ...>
    ...
    <!-- If we are running in Jenkins use cobertura. -->
    <profiles>
        <profile>
            <id>jenkins</id>
            <activation>
                <property>
                    <name>env.BUILD_NUMBER</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>cobertura-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    ...
</project>

Ant

You must first tell Ant about the Cobertura Ant tasks using a taskdef statement. The best place to do this is near the top of your build.xml script, before any target statements.

<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 that JUnit will be testing (not the test classes themselves) as such:

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

<cobertura-report format="xml" destdir="${coveragereport.dir}" srcdir="${src.dir}" />
You can use multiple source directories this way:
<cobertura-report format="xml" destdir="${coveragereport.dir}" >

	<fileset dir="${src.dir.java}">

		<include name="**/*.java" />

	</fileset>

	<fileset dir="${src.dir.main}">

		<include name="**/*.java" />

	</fileset>

</cobertura-report>

Gradle

Running Cobertura in gradle, copied from Piotr Gabryanczyk's post at http://piotrga.wordpress.com/2010/04/17/gradle-cobertura-integration-revisited/ and tweaked to work for gradle 1.5:

Create cobertura.gradle in the root of your project:

logger.info "Configuring Cobertura Plugin"

configurations{
  coberturaRuntime {extendsFrom testRuntime}
}

dependencies {
  coberturaRuntime 'net.sourceforge.cobertura:cobertura:1.9.4'
}

def serFile="${project.buildDir}/cobertura.ser"
def classes="${project.buildDir}/classes/main"
def classesCopy="${classes}-copy"


task cobertura(type: Test){
  dependencies {
    testRuntime 'net.sourceforge.cobertura:cobertura:1.9.4'
  }

  systemProperty "net.sourceforge.cobertura.datafile", serFile
}

cobertura.doFirst  {
  logger.quiet "Instrumenting classes for Cobertura"
  ant {
    delete(file:serFile, failonerror:false)
    delete(dir: classesCopy, failonerror:false)
    copy(todir: classesCopy) { fileset(dir: classes) }

    taskdef(resource:'tasks.properties', classpath: configurations.coberturaRuntime.asPath)
    'cobertura-instrument'(datafile: serFile) {
      fileset(dir: classes,
              includes:"**/*.class",
              excludes:"**/*Test.class")
    }
  }
}

cobertura.doLast{
  if (new File(classesCopy).exists()) {
    //create html cobertura report
    ant.'cobertura-report'(destdir:"${project.reportsDir}/cobertura",
            format:'html', srcdir:"src/main/java", datafile: serFile)
    //create xml cobertura report
     ant.'cobertura-report'(destdir:"${project.reportsDir}/cobertura",
            format:'xml', srcdir:"src/main/java", datafile: serFile)
    ant.delete(file: classes)
    ant.move(file: classesCopy, tofile: classes)
  }
}

Apply Cobertura.gradle in your build.gradle

Either (if single project build)

apply plugin: 'java'
apply from: 'cobertura.gradle'

Or (if multi project build)

subprojects {
  apply plugin: 'java'
  apply from: "${parent.projectDir.canonicalPath}/cobertura.gradle"
}

Version History

Version 1.12 (12-Nov-2017)

  • Show why build failed when it missed coverage targets (JENKINS-47639)
  • Prefix all logs with `[Cobertura]` (JENKINS-25781)
  • Fix Phabricator compatibility regression (Issue #73)
  • Add support for pipeline snippet generator

Version 1.11 (09-Aug-2017)

  • Added pipline support for coverage targets (Issue #67)
  • Publish jobs when onlyStable is false even if job fails (Issue #59)

Version 1.10 (25-Apr-2017)

  • Support Jenkins pipeline (JENKINS-30700)

  • Avoid error when CoverageMetric EnumSet is empty (JENKINS-6425)
  • Remove deprecated use of ChartUtil.generateGraph (JENKINS-17800)
  • Fix typo in Spanish properties

Version 1.9.8 (8-May-2016)

Version 1.9.7  (4-Mar-2015)

Version 1.9.6 (25-Oct-2014)

  • Fixed URL to coverage results in views and folders (JENKINS-24436)

Version 1.9.5 (24-Apr-2014)

  • Added coverage column that shows line/branch coverage in views

Version 1.9.4 (17-Apr-2014)

  • Fix display when data for one of the columns is missing (JENKINS-22412)

Version 1.9.3 (16-Oct-2013)

  • More fixes of file descriptor leaks

Version 1.9.2 (9-Aug-2013)

  • Cobertura Unable to delete coverage.xml on windows (JENKINS-18858).

Version 1.9.1 (14-Jun-2013)

  • Added "most recent N builds" limiting option for coverage graph.
  • Fixed columns order on dashboard(JENKINS-18218).

Version 1.9 (28-Apr-2013)

  • SourceCodePainter overwrites original files (JENKINS-16252).
  • table.source font-family should not specify courier (JENKINS-3567).
  • show greenbar collectly in IE Quirks Mode (JENKINS-8568).
  • There should be a cobertura summary item on the build status page (JENKINS-8441).
  • show legend under the graph.
  • sort order of metrics. package, file, class, method, line, condition.
  • Cobertura plugin does not provide data to the REST API (JENKINS-13877).
  • Cobertura ClassCastException (JENKINS-15703).

Version 1.8 (15-Dec-2012)

  • Crop unusaged whitespace in coverage graph(JENKINS-16038).
  • testing if workspace permissions
  • fixed layout: added align="right" to be displayed collectly
  • Cannot plublish cobertura reports if org.codehaus.mojo:cobertura-maven-plugin is not invoked(JENKINS-14552).
  • Cobertura - add option to make build as unstable (or not at all) instead of failed when no coverage xml files are found (JENKINS-12857).

Version 1.7.1 (17-Oct-2012)

Version 1.7 (11-Oct-2012)

Version 1.6 (17-Aug-2012)

Version 1.5 (20-May-2012)

  • Code Coverages dashboard portlet missing column("METHODS") (JENKINS-7366).
  • cobertura coverage dashboard portlet not using numeric sort for percent columns (JENKINS-13250).
  • updated Japanese localization.
  • some fixes.

Version 1.4 (5-May-2012)

  • cobertura conditionals not available with a French server + regexps optimizations (JENKINS-7540).
  • Cobertura gives LinkageError in new Jenkins version (JENKINS-11398).
  • Cobertura plugin should not fail maven build for maven release (JENKINS-12640) (pull-6).

Version 1.3 (13-Aug-2011)

  • Change so output format will be in alphabetical order by default
  • Put <pre>...</pre> tags around source code content in case cobertura directory is linked to source code
  • Added description of the Source Encoding

Version 1.2 (25-Feb-2011)

  • Update for Jenkins

Version 1.1 (11-Jan-2011)

Version 1.0 (30-Jul-2010)

  • Fix so 0/0 is counted as 100% instead of 0% coverage (ie, a method with no conditionals). (JENKINS-6790)
  • Fix in source viewer so "\n" and "\r" (backslash+n/r, not actual newlines) are not omitted. (JENKINS-3566)
  • Add support for dashboard plugin

Version 0.8.11 (22-Mar-2010)

  • Fixed: source code unavailable when unstable (JENKINS-4803)
  • Fixed an issue in internationalization on static enum clases which made some texts be shown in English.
  • Fixed a bug in the way the tables were sorted (same problem than emma JENKINS-4173). Now they are sorted numerically instead of alphabetically.
  • Added Spanish internationalization.

Version 0.8.10 (15-Jan-2010)

  • Reorganize data structures to allow processing larger result files
  • Use EnumMap and EnumSet for more compact in-memory representation of data
  • Update code for more recent Hudson
  • Change report colors as described here
  • Internationalize messages (JENKINS-4920)

Version 0.8.9 (8-Jul-2009)

  • Added green/red results bars to statistic blocks (JENKINS-3869)
  • Improved support for multi-module SCMs other than Subversion (such as CVS) (JENKINS-1323)
  • Fixed an issue that broke source highlighting for module build result pages (JENKINS-3938)

Version 0.8.8 (11-Jun-2009)

  • Revert the memory usage fixes in 0.8.7, since they were breaking source highlighting (JENKINS-3597)

Version 0.8.7 (4-Jun-2009)

  • Improved help and error messages to attempt to avoid "Can not find coverage-results" (JENKINS-1423)
  • Fixed "Consider only stable builds" setting (JENKINS-3475)
  • Improved memory usage when drawing trend graphs (JENKINS-3597)

Version 0.8.6 (7-May-2009)

  • The plugin runs before notifications are sent out, to avoid inconsistency in build status reporting (JENKINS-1285)
  • The cobertura statistics graphic on a project window isn't rendered (JENKINS-2851)

Version 0.8.4 (21-Oct-2007)

  • ???

Version 0.8.3 (12-Oct-2007)

Version 0.8.2 (4-Oct-2007)

Version 0.8.1 (28-Sep-2007)

  • Fixes issues running under JDK 1.5
  • Fixes some issues with finding source code

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)

Version 0.3 (28-Aug-2007)

  • Fixed NPE parsing some cobertura reports generated by Cobertura version 1.8.
  • Project level report should now work (except possibly when a build is in progress) 

Version 0.2 (28-Aug-2007)

  • Fixed problem with configuration (was not persisting configuration details)
  • Changed health reporting configuration (now handles the more generic code)
  • Tidy-up of reports
  • Known issues:
    • Project level report does not work in all cases
    • Class and Method level reports should display source code with coverage if source code is available (in workspace) 

Version 0.1 (27-Aug-2007)

  • Initial release.  Only parses xml report. Some rough edges in the UI.


64 Comments

  1. Anonymous

    After some hours, I got it to work with the Netbeans makefile. (smile)

    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.

    1. Unknown User (stephenconnolly2)

      Could you please add a section into this page detailing how to get this plugin working with the Netbeans makefile?

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

  2. Anonymous

    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?

  3. Anonymous

    +1 for integrating the plain Cobertura reports in some way or another.

    The plugin is great by the way (wink) 

  4. Unknown User (stephenconnolly2)

    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.

    1. Unknown User (stephenconnolly2)

      See Version 0.5 which was released today

      1. Anonymous

        The HTML coverage report is produced now (smile) - 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. (wink)

        1. Anonymous

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

          1. Unknown User (stephenconnolly2)

            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.

            1. Anonymous

              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?

              1. Unknown User (stephenconnolly2)

                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)

  5. Anonymous

    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)

    1. Anonymous

      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.

  6. Anonymous

    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?

    1. Anonymous

      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

  7. Anonymous

    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.

    1. Anonymous

      i second that.

      1. Unknown User (stephenconnolly2)

        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. 

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

  8. Unknown User (michael.r.caron@gmail.com)

    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... (wink)

  9. Unknown User (fabrice@xeberon.net)

    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.

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

    1. Unknown User (fabrice@xeberon.net)

      ouf I am not alone on this new problem (smile)

      help us (smile)

      1. Fabrice,

         I've checked out version 0.8.5-SNAPSHOT and its working.

         But anyway, the coverage reports only apper at module page

        1. Unknown User (fabrice@xeberon.net)

          Ok nice

          It would be nice too if we have a new stable release. When ?

    2. Unknown User (nvaslavsky@csc.com)

      Jose,

      I have the same problem "

      Build ok, coverage.xml being generated just as expected in this tutorial. but I get no image nor link on the status page."

      I use cobertura plugin version 0.8.4.

      Have you bee able to solve?

  11. Unknown User (ptvnga)

    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?

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

    1. Hi,
      in order to execute cobertura during test phase just add following in your root pom.xml file

                    <groupId>org.codehaus.mojo</groupId>
                      <artifactId>cobertura-maven-plugin</artifactId>
                      <version>2.2</version>
                      <executions>
                          <execution>
                              <phase>test</phase>
                              <goals>
                                  <goal>cobertura</goal>
                              </goals>
                          </execution>
                      </executions>
                    </groupId>
      

      After that cobertura task will be executed during test phase.
      But how to avoid execution of tests twice I don't know.

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

  14. Unknown User (dvk)

    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 ?

    I would like to contribute patch but I'm not sure how to do it.

    And sorry for my bad English  - it is not my native language.

  15. Unknown User (ww@touk.pl)

    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

    1. Have you released this modified plugin? I'm not able to find any more information on top.touk.pl than what's in your blog post there.

    2. Doesn't seem to be available anymore?

  16. Unknown User (drudman@gmail.com)

    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.

    Thanks!

    1. Unknown User (nvaslavsky@csc.com)

      What version of Hudson can be used with cobertura plugin 0.8.5.

      I have 1.226.

      I have a hudson error while configuring a project.

      Thanks

  17. Unknown User (jmorcate)

    Hi,

    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.

        <property name="cobertura.dir" location="/usr/share/tools/cobertura-1.9.1" />
        <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" />
     
    
  18. Hello,

    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.

     PK
         uØ:                   META-INF/PK
       uØ:èl Cw   †      META-INF/MANIFEST.MFM‹½
    Â0€÷@ÞáFT- Ö©Ðê ¸Ê5ž˜Á«Ü¥HßÞ¸¹~?r~w%Ñ<ñ¢Ö4üGš7¦'AeUî}´æ(„...î®]~ý·[ܺ1l`u™†œdÒE½:N~mÍ
         uØ:               org/PK
         uØ:            
       org/netbeans/PK
    

    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?

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

  19. Unknown User (john.bolton@quest.com)

    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.

    Does anybody have any ideas why this is crashing?

    [INFO] Cobertura Report generation was successful.
    [HUDSON] Recording coverage results
    [INFO] ------------------------------------------------------------------------
    [ERROR] FATAL ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] org.apache.maven.plugin.PluginManagerException.<init>(Ljava/lang/String;Ljava/lang/Exception;)V
    [INFO] ------------------------------------------------------------------------
    [INFO] Trace
    java.lang.NoSuchMethodError: org.apache.maven.plugin.PluginManagerException.<init>(Ljava/lang/String;Ljava/lang/Exception;)V
    	at hudson.maven.agent.PluginManagerInterceptor.executeMojo(PluginManagerInterceptor.java:195)
    	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
    	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
    	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    	at org.apache.maven.lifecycle.LifecycleExecutorInterceptor.execute(LifecycleExecutorInterceptor.java:65)
    	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    	at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    	at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    	at hudson.maven.agent.Main.launch(Main.java:165)
    	at hudson.maven.MavenBuilder.call(MavenBuilder.java:159)
    	at hudson.maven.MavenModuleSetBuild$Builder.call(MavenModuleSetBuild.java:687)
    	at hudson.maven.MavenModuleSetBuild$Builder.call(MavenModuleSetBuild.java:633)
    	at hudson.remoting.UserRequest.perform(UserRequest.java:104)
    	at hudson.remoting.UserRequest.perform(UserRequest.java:48)
    	at hudson.remoting.Request$2.run(Request.java:244)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:619)
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 5 minutes 41 seconds
    [INFO] Finished at: Tue Sep 29 16:01:53 PDT 2009
    [INFO] Final Memory: 23M/104M
    [INFO] ------------------------------------------------------------------------
    channel stopped
    Skipping Cobertura coverage report as build was not UNSTABLE or better ...
    

    Thanks for your time,

    John

    1. Unknown User (john.bolton@quest.com)

      FYI, I reinstalled the OS and all of the software. The problem has gone away. I'm not sure what caused the problem however I don't believe the plug-in was doing anything wrong.

  20. Unknown User (cmoesel)

    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?

    1. Yes, I believe that the plug-in is doing its own aggregation of results.  This allows it to take multiple independent coverage.xml files and provide a single unified view of the coverage.

  21. Unknown User (peter.x.kreidermacher@healthpartners.com)

    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.

    Does anyone have any idea why this started to happen all of a sudden?

    Thanks!

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

    Is there any way to always display the trend graph?

  23. I'm trying to get coverage Information across two modules, meaning one module (a test module) is running tests on the other module.

    Unfortunately the cobertura plugin here doesn't consider cross module test coverage... or at least I haven't figured out how. I've already tried moving the configuration to the parent pom, but alas, no luck.

    Any ideas how this could be done?

    Thanks

  24. The information for this plugin at Hudson now reads:

    Moved to Jenkins

    This plugin is now supported and documented at Jenkins.

    As a user this doesn't give me a warm fuzzy that the plugin will continue to be compatible with Hudson.  Can you confirm?  Thanks.

  25. The coverage report doesn't list packages or files in alphabetical order which makes it difficult to find a package or class.  Could this be changed or made configurable?  Or the column sortable?

    Thanks.

  26. When accessing the api\xml report the element result only includes the ratio.  Could it also include the numerator and denominator so that consumers can sensibly combine them across jobs (without having to get the details)?

  27. We have it set up to run the code coverage via the cobertura:cobertura which works well except when we do a release.

    As the release is run calls maven with mvn release:prepare release:perform - it doesn't execute the cobertura (which is what we want). The build goes through to the very end and then fails the build (after successfully uploading all the artifacts) with below.
    Any ideas how to stop it failing the build? Or just raise a jira?
    INFO Deployment done in 1.8 sec
    Publishing Cobertura coverage report...
    No coverage results were found using the pattern '**/target/site/cobertura/coverage.xml' relative to '/tmp/hudson_slave/workspace/trunk'. Did you enter a pattern relative to the correct directory? Did you generate the XML report(s) for Cobertura?
    Build step 'Publish Cobertura Coverage Report' changed build result to FAILURE
    An attempt to send an e-mail to empty list of recipients, ignored.
    Finished: FAILURE

  28. I checked the the source code tree under .../jobs/<myjob>/cobertura/se/....

    and found that it has not been changed for a while. Anyone with a similair experience?

    //mike

  29. - -

    May I suggest updating the version of the Cobertura plugin in the POM example? The problem is 2.2 seems to have bugs with coverage detection - being new to Cobertura, I've spent 2+ hours trying to solve the problem, which turned out to be as easy as changing the Maven plugin version to 2.5.1 (the latest at the time of writing).

    I don't want to edit the page myself, as I don't know whether 2.5.1 is actually the recommended version for this Jenkins plugin.

  30. Hi,
    I want to use cobertura plugin for gcov data on c files. But generated cobertura report shows java specific entities - "packages", "classes". Is it possible to somehow simple remove these metrics from report?

  31. Request to add a Build Setter compatibility (or Token Macros) name to all references to a job.

    I currently have my Build Setter named to a pipeline number, and hence require Cobertura reports to point to that rather than an Hudson Job number.

    Thanks for the awesome cobertura integration though.

    Cheers!

  32. Hi,

    I would like to only show the configured metrics in the Code coverage graph. I only defined three (classes, methods and lines) but it display all the metrics (Packages, Files, Classes, Methods, Lines, and Conditionals)

    Is it possible to do with the current version (1.9.1) or can you add the option in future release ?

    Anyway, thanks for your great plugin.

  33. Hi

    I´ve just installed version 1.9.3 and I think I've found a bug or something like that.

    In the advanced configurations options I can change the "health history" (sun, cloud, rain, storm) of a project, based on coverage percentage of classes, packages, methods, lines, etc.

    For my project, I set "sunny" 70%, and "stormy" 10% of lines coverage. I had 69% of lines coverage, so I was expecting to get a "cloud" (or "rain" at most), but I got "storm".

    I thought the health could be interpolated, based on max. and min. values.

  34. I want to exclude  sub project in cobertura.gradle from cobertura task in GRADLE . I tried to exclude/skip as below. But no Luck. Please share the right way of excluding sub project in cobertura.gradle asap. I stuck here-----------------------------------

    coberturaTask.enabled = false 

    ********AND************

    project('test-modules:functional-tests') {
    cobertura

    Unknown macro: { skip = true }

    }

  35. I want to exclude  sub project in cobertura.gradle from cobertura task in GRADLE . I tried to exclude/skip as below. But no Luck. Please share the right way of excluding sub project in cobertura.gradle asap. I stuck here-----------------------------------

    coberturaTask.enabled = false 

    ********AND************

    project('test-modules:functional-tests') {
    cobertura

    Unknown macro: { skip = true }

    }

  36. I want to show gcov result by cobertura, and my xml generated by gcovr as follows, the "name="api">" link to covertura api path, how can i solve this issue?

    <?xml version="1.0" ?>
    <!DOCTYPE coverage
      SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>
    <coverage branch-rate="0.0" line-rate="0.00923787528868"
     timestamp="1399387640" version="gcovr 3.1-prerelease">
     <sources>
    <source>/p/jenkins/workspace/UIFramework_UnitTest/framework/service/WidgetService/</source>
     </sources>
     <packages>
      <package branch-rate="0.0" complexity="0.0" line-rate="0.00943396226415"
       name="api">
       <classes>
        <class branch-rate="0.0" complexity="0.0"
         filename="api/AWidgetApiHandler.cpp" line-rate="0.0"
         name="AWidgetApiHandler_cpp">
         <methods/>
         <lines>
    <?xml version="1.0" ?>

    <!DOCTYPE coverage

      SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'>

    <coverage branch-rate="0.0" line-rate="0.00923787528868"

     timestamp="1399387640" version="gcovr 3.1-prerelease">

     <sources>

    <source>/p/jenkins/workspace/UIFramework_UnitTest/framework/service/WidgetService/</source>

     </sources>

     <packages>

      <package branch-rate="0.0" complexity="0.0" line-rate="0.00943396226415"

       name="api">

       <classes>

        <class branch-rate="0.0" complexity="0.0"

         filename="api/AWidgetApiHandler.cpp" line-rate="0.0"

         name="AWidgetApiHandler_cpp">

         <methods/>

         <lines>

  37. I was looking through the history of the updates and it explicitly says when the plugin was updated to work with JDK 5 and 6. I was wondering if the current plugin works with JDK 7. I know people are using it but it seems to have a good many problems. So does it actually work with Java 7, or are people just finding work-arounds for the problems they run into? Also what are the dependent versions of Jenkins, Maven, and Cobertura  needed for the current plugin? (1.9.5) Thank You

  38. I am using it for Java code and want to know if there is way of configuring for email notification when the coverage (for java package/s) is less than what it was in the previous build. 

  39. Is there a way to use custom title/label instead of the default "Code Coverage"?

    I generate reports from PHP and JS in my project, and there's no way to customize the title/label of the generated output.

    I'm so confused every time I see two reports with the same title/label listed one next to other.

Write a comment…