views:

854

answers:

3

My Maven 2 project consists of several sub-modules. It s structured containing and EJB, WAR and Jar sub modules.. Now i want to instrument the packaged EAR that contains all submodules as mentioned.

Example:

Interface Maven Project consists of several modules:
- InterfacePOM --> parent pom
- InterfaceEAR --> EAR module which does not actual code but is the packaging for Domain, EJB and WAR
- InterfaceEJB --> EJB module
- interfaceWAR --> WAR module
- interfaceDomain --> JAR module

When using Cobertura i can succesfully instrument all various independent modules but that generated a .ser file per module. Is there a way to instrument an enitre EAR file at once? So that the result will be a single .ser file which i can use??

+2  A: 

Short answer: no (have a look at this previous answer for more details). You'll need an external plugin like the dashboard (actually, don't use it, see my previous answer), XRadar or Sonar to aggregate the reports. But in this area, Sonar is the clear winner (this project just rocks) and I'd recommend it without any hesitation. Check out Nemo, their public instance, pick up any project and have a look at the drill down of code coverage (for example Apache CXF) to get an idea of what it can do.

UPDATE: It appears that I missed the point of the initial question so I'm updating my answer accordingly. Basically, I now understand the question as "how to instrument an ear with cobertura" and this is indeed a totally different story.

Unfortunately, while cobertura can instrument an ear, sar, zip, war, jar, I' don't think that the cobertura-maven-plugin supports this out-of-the-box and it may be a better option to use cobertura's ant task with the antrun plugin. See MCOBERTURA-86, this thread and this discussion for more background on this (and an antrun sample).

TBH, what you are trying to do is really not easy in terms of build lifecycle, packaging, reporting, etc and is going to be a tough task because of the lack of support from the cobertura plugin. I'd really think about it twice (time to invest to get the whole thing working vs the value generated) or consider spending that time (understand money) to get a clover license (which offers better support for this).

Pascal Thivent
+1 Yeah. Sonar seems to be only reasonable choice for reporting.
cetnar
We already use sonar but it offers no solution for my specific need, i want to get coverage info from inside the JBOSS container and not only outside the container. So while Sonar does a great job in unit testing it is no solution for my need.
Marco
This has nothing to do with Sonar. Sonar aggregates what you give him to aggregate. So, if you instrument your EAR, deploy it (e.g. with Cargo) on JBoss and run your integration tests as part of your build, Sonar would definitely be able to use the data generated by Cobertura. Don't expect any tool to do this magically, you need to handle that at the maven level.
Pascal Thivent
Agree with that, on a later stage we would like to integrate it with Sonar. But the original question is not about the reporting but the instrumenting task. If we can get it instrumented in an relative easy way, we will surely hookup Sonar.
Marco
Ohhh. I actually misunderstood the original question then. I'll update my answer.
Pascal Thivent
+1  A: 

It looks like there is no task in the cobertura-maven-plugin for merging .ser files from individual projects into a single report.

A google search turned up this feature request and patch for the plugin to add a merge task, but it doesn't look like it was accepted. One of the comments suggests using the dashboard plugin to accomplish the same thing, you might have some success with that.

matt b
The only solution i can think of is creating several .ser files from the seperate sub-modules and trying to merge them using the commandline tool. Then feed that into the JBoss container for data enrichment.
Marco
A: 

I implememented a solution now based on your previous answers around Maven 2. It is still not very easy to use but so far it goes ok. The implemetation is as follows:

  1. Modified my parent pom to generate cobertura instrumented classes when giving a specific profile.This generates the .ser files and the instrumented classes.
  2. The instrumented classes are copied to the /target/classes folder by using the maven-resource-plugin, so the actual packaging uses the instrumented classes
  3. As there is no module wide .ser file i manually combine those .ser files from the EJB,WAR,JAR and ear file using the commandline solution given by Cobertura. coberture-merge.bat/.sh
  4. Deploy the .ser file into my JBoss container and also deploy the instrumented EAR.
  5. After testing i run a report on the merged .ser file and voila.. it seems to work..

I surely will look into Clover as the solution implemented is somewhat manual..

Marco