OSGi code coverage with Cobertura, part II

This is the second installment of OSGi-code-coverage post. Please read the first part: OSGi code coverage with Cobertura.

In this part I'll experiment with more than one bundle being code-coveraged, and I will also use Spring Dynamic Modules to activate the bundles (instead of BundleActivator that I used previously).

Please notice the source code attached at the end of this text.

Many bundles

There is a source code attached at the end of this text, so go and have a look at it (osgi-coverage-cobertura-many-bundles.zip).

My next step was to check what happens if I have more than one bundle. I created three of them:

  • bundles A and B - which exposes some methods
  • bundle-activator - which calls those exposed methods

It went smoothly. First, I created bundles A and B. Then, I copied them to some other dir, and instrumented at once. The cobertura ant task looks like this (both jars reside in ${lib.dir} and the instrumented versions are copied into ${instrumented.dir}):

<cobertura-instrument todir="${instrumented.dir}">
  <fileset dir="${lib.dir}">
    <include name="**.jar" />
  </fileset>
</cobertura-instrument>

Ok, now I have these two instrumented bundles. I deploy them to Apache Felix, and I also copy cobertura.ser file to FELIX_HOME. Than I build and copy the bundle-activator bundle. During the deployment it calls some methods of bundle A and B. Then I stop the bundle-activator bundle. Now, in FELIX_HOME I have the updated version of cobertura.ser. Good. I copy it to COBERTURA_HOME and execute:

java -cp cobertura.jar:lib/asm-2.2.1.jar:lib/log4j-1.2.9.jar:lib/jakarta-oro-2.0.8.jar net.sourceforge.cobertura.reporting.Main --datafile cobertura.ser --destination report --srcdir /home/tomek/work/osgi-bundle-a/src/main/java/ /home/tomek/work/osgi-bundle-b/src/main/java

As you have probably notice, I needed to give both src directories. The report looks fine, except that it shows all the packages - including Cobertura - and not only my packages.

P.S. I have also tested this on Fuse ESB 4.0.0.3 and it also worked fine (not very suprising, as Fuse ESB is based on ServiceMix 4-m1, and ServiceMix uses Apache Felix underneath...).

Same stuff on FuseESB with Spring DM

Ok, next step. I commented out <Bundle-Activator> in both pom.xmls of osgi-bundle-a and -b, and added simple Spring DM configuration files. Then I did exactly the same thing for Fuse ESB that I previously did with Apache Felix. And guess what ? - it also worked.

The end ? probably, yes

I don't have time to play with OSGi-code-coverage anymore, so for now, it's over. But who knows, maybe I'll be back.

AttachmentSize
osgi-coverage-cobertura-many-bundles.zip17.41 KB

 
 
 
This used to be my blog. I moved to http://tomek.kaczanowscy.pl long time ago.

 
 
 

Please comment using