Cobertura for J2ME

Coverage tool for the Java(™) ME platform


Developer's corner

This section is intented for people interested in extending/maintaing Cobertura for J2ME. It provides basic information on how to build and deploy as well as a rough description of the design.


Were can I find the source code?

The source code is available on SVN (https://svn.sourceforge.net/svnroot/cobertura4j2me).

topback to top

How do I setup my build environement?

An ant script is provided to perform the different build steps
  1. The first thing to do is to either unzip the source archive in the location of you choice (e.g. C:\WORK\cobertura-j2me\) or check out the trunk directory from the SVN repository. You should see a directory structure as follows:
    +- doc/
    +- lib/
    +- res/
    +- src/
    - build.xml
    - build.properties

    where 'src/' contains the source code.

  2. Make sure ant is installed on your system. Check out http://ant.apache.org for more information.
  3. You also need Sun's Wireless Toolkit (version 2.2 onwards). Visit http://java.sun.com/javame.
  4. Then you need to modify build.properties:
    # the build version
    cobertura4j2me-version=1.1.0

    ### MODIFY HERE ###
    # MUST BE CLDC1.1
    jar.cldc=C:/APPS/WTK22/lib/cldcapi11.jar
    jar.midp=C:/APPS/WTK22/lib/midpapi20.jar
    jar.jsr75-file=C:/APPS/WTK22/lib/jsr75.jar
    preverifier.exe=C:/APPS/WTK22/bin/preverify.exe

topback to top

How do I build?

Simply type the following command:
ant build

This script will generate the output in a folder called release. This directory should contain 2 zip files:

- cobertura4j2me-x_y_z-bin.zip
- cobertura4j2me-x_y_z-src.zip

Where x_y_z is the version specified in the properties file

topback to top

What do I need to know before modifying the code?

The following section describes how the source code is organized and how the coverage data is collected and persisted.

First of all, the code is organized as follows:

  • org.cobertura4j2me.ant
  • org.cobertura4j2me.merge
  • org.cobertura4j2me.reporting
  • org.cobertura4j2me.reporting.html
  • org.cobertura4j2me.reporting.html.files
  • org.cobertura4j2me.reporting.xml
  • org.cobertura4j2me.runtime
  • org.cobertura4j2me.runtime.j2se
  • org.cobertura4j2me.runtime.midp
  • org.cobertura4j2me.util
I will concentrate on the runtime packages and the coverage data handling. Below are listed the key points of the design:

  • The coverage data is represented by the class CoverageData which encapsulates the data for a class.

  • Each CoverageData is a composition of LineInformation which records the coverage data of a particular line of the source code.

  • At intrumentation-time, the list of classes and lines that are instrumented are recorded and serialized (see interface Persistent) into cobertura-instr.ser.
    The actual instructions added during instrumenting correspond to the following source code:
    Factory.getInstance().newCoverageData("MyClass").touch(126);
    which will, when exceuted, record that the line 126 of the class MyClass has been executed.

  • At runtime, if some instrumented code is invoked, it is logged and upon MIDlet exit the coverage data is serialized into the file cobertura.ser.

  • There are two different implementations of the CoverageDataPersistence interface. One is to be used on the device for runtime data handling (MIDPCoverageDataPersistence), and one on the PC-side (J2SECoverageDataPersistence).

  • The class SaveOnExitHook is used to make sure that the most up-to-date coverage data is saved upon MIDlet exit. The intrumenter adds a call to this hook as the last operation of MIDlet.destroyApp()

topback to top