1

So I have a java project in Eclipse. I build the war file via ant. Which I can invoke from Eclipse, or from the command line or via Jenkins. I am setting up the environment is such a way as to try and keep all three of those ways of building working, and with as little changing of the environment as possible to make it happen.

So I am currently doing the compile, creating the war, generating javadoc, and running junits via my ant build.xml

Trying to add Cobertura code coverage to the mix.

I have installed the Jenkins for Cobertura and I'm now trying to get the junit running to work with Cobertura to properly instrument the classes and generate the coverage file.

The cobertura doc says to start by defining the task as follows.

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

Don't like that C:\ obviously ... I need a valid cobertura.dir ... but it is not really obvious how to configure it. Jenkins puts all the classes for the plugin here

.jenkins/plugins/cobertura

And the file structure underneath this is as follows.

drwxrwxr-x 2 vpbuild vpbuild 4096 Jan 4 10:42 images drwxrwxr-x 3 vpbuild vpbuild 4096 Dec 15 12:36 META-INF -rw-rw-r-- 1 vpbuild vpbuild 0 Jan 4 10:41 .timestamp drwxrwxr-x 4 vpbuild vpbuild 4096 Dec 15 12:36 WEB-INF

So if this was to be my cobertura.dir there is no lib subdirectory defined here. There is in WEB-INF, but there is no cobertura jar there ... so none of it seems quite right.

I have also downloaded the cobertura jar separately, and put that in ANT_HOME/lib, to hopefully assist with making the cobertura tasks more visible to ANT, but not sure how that would affect what I need to do as far as the build.xml.

Anyone have any experience with configuring cobertura so that it can run via ant both within and outside jenkins in this way ? What does the build.xml need to look like to make it happen ?

-Jim

James Gawron
  • 871
  • 10
  • 27

1 Answers1

3

The Jenkins Cobertura plugin merely processes and displays your code coverage results; it doesn't include the Cobertura tool itself.

You should download the latest Cobertura binaries and unpack them into your C:\javastuff\cobertura directory. You'll then have cobertura.jar plus a lib subdirectory containing the other required dependencies that go into cobertura.classpath.

gareth_bowles
  • 20,760
  • 5
  • 52
  • 82
  • Ok, helpful to know that the plugin isnt the tool. lol. I have downloaded the jar file as well. I will be able to configure ant to look at it easily enough. There is no lib directory within the binary however, so I'm not sure what that entry is all about. – James Gawron Jan 04 '13 at 23:10
  • If you download one of the binary package formats from the link I gave in my answer and extract it, you'll find a lib subdirectory together with an example subdirectory. – gareth_bowles Jan 04 '13 at 23:58
  • Downloaded the binary ... put the contents in .jenkins/tools/Cobertura ... used that directory and subdirectory to create the cobertura classpath ... added the "instrument" task as shown in the example build.xml ... when I invoke the instrument target however I'm getting a NoClassDefFound error on log4j.logger ... tried adding classpath elements to the cobertura instrument to no avail.... – James Gawron Jan 14 '13 at 17:02
  • Fixed that ... needed to remove the cobertura jar I had earlier placed in ANT_HOME/lib .... that was messing it up... found solution here http://stackoverflow.com/questions/1774889/cobertura-ant-script-is-missing-log4j-classes – James Gawron Jan 14 '13 at 17:18