How do I make Jenkins, Sonar and the JaCoCo plugin work together for Eclipse Tycho Plugin Projects (or maybe Cobertura)?
Asked Answered
S

3

8

my setup is:

  • Jenkins 1.448
  • Sonar 2.13
  • Jenkins Sonar Plugin 1.72
  • a MySql database for Sonar

I have the following project:

  • Eclipse Plugin Project
  • using Maven
  • multiple modules (parent maven project, source plugin project, test fragment project)
  • a simple JUnit test testing a class of the source plugin project

What the process is at the moment:

  • Jenkins checks out the parent project from SVN
  • Jenkins builds the project and its modules using Maven and Tycho
  • Jenkins uses Surefire to execute the tests and produce a report
  • Jenkins uses the Jenkins Sonar plugin to start mvn sonar:sonar to execute code analysis
  • Static code analysis is done on each module
  • JaCoCo fails

Sonar has static code analysis statistics available and test success percentage is shown. The only thing that's missing is JaCoCo's code coverage...or maybe even Cobertura's code coverage.

I don't really care at this point, I just want one of these things to produce code coverage results.

Cobertura seems to be unable to produce results possibly because either - it can't instrument the code - it looks for the instrumented code at the wrong place - it can't cope with Tycho or the separate source/test code setup

JaCoCo should be able to "watch" the code coverage on the fly, but its output is

[INFO] [17:44:04.708] Sensor JaCoCoSensor...
[INFO] [17:44:04.717] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/jobs/testPlugin/workspace/testSource/target/jacoco.exec
[INFO] [17:44:04.854] Sensor JaCoCoSensor done: 146 ms

[INFO] [17:44:10.587] Sensor JaCoCoSensor...
[INFO] [17:44:10.587] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/jobs/testPlugin/workspace/testTest/target/jacoco.exec
[INFO] [17:44:10.631] Sensor JaCoCoSensor done: 44 ms

[INFO] [17:44:12.402] Sensor JaCoCoSensor...
[INFO] [17:44:12.402] Project coverage is set to 0% as build output directory doesn't exists: /var/lib/jenkins/jobs/testPlugin/workspace/testParent/target/classes
[INFO] [17:44:12.402] Sensor JaCoCoSensor done: 0 ms

What am I doing wrong? Do I need to enable JaCoCo in my pom.xml somewhere? Do I need surefire? What do I need to do to use Cobertura?

Shaker answered 20/1, 2012 at 16:1 Comment(0)
S
3

I've found a page with an example tycho multi-module project (separate source and test projects). After copying some of the properties and configurations...

it seems that I now use a maven jacoco plugin to generate the jacoco code coverage report and then tell Sonar where to find the report and reuse it.

Why on earth is there next to no documentation for this? Or why is it so hard to find?

https://github.com/Godin/sonar-experiments/tree/master/jacoco-examples/tycho-example

Shaker answered 27/1, 2012 at 14:50 Comment(0)
S
3

You can have a look on the blog post I wrote few months ago : http://mdwhatever.free.fr/index.php/2011/09/quality-analysis-on-eclipse-plugins-with-tycho-sonar-jacoco-and-swtbot/

Savannahsavant answered 6/3, 2012 at 23:8 Comment(0)
L
0

When the code is done being instrumented, surefire has to be ran on that specific code that the instrumentation generates. I've not used your setup, but your error seems very similar to what I got when I was getting Clover code coverage to work; I had to point surefire to run tests out of the directory that the compiled instrumented code was being stored in.

Also, I found specifying the -X option on the Maven command line to be invaluable as reading the logs of each plugin during a build shows you exactly where it's looking for whatever it's trying to find.

Edit:

Instrumented code will have to be compiled before surefire can run against it, so you'll want to point to the post-compilation directory and not the instrumented source itself.

Lappet answered 20/1, 2012 at 20:3 Comment(1)
How do I tell Sonar or Cobertura or JaCoCo where to look for the instrumented code?Shaker

© 2022 - 2024 — McMap. All rights reserved.