EclEmma 1.4.3 Java Code Coverage for Eclipse EclEmma at SourceForge.net
JaCoCo
Eclipse Community Award 2008

Architecture

Design decisions for the EclEmma plug-in should be based on the following guidelines:

  • A high usability should allow developers to efficiently analyse coverage results and improve test coverage interactively. Technically motivated extra steps must be avoided.
  • Seamless integration into the Eclipse workbench: Use existing tools and paradigms; adopt the Eclipse look & feel.
  • The primary focus are local launches and interactive coverage analysis within the Eclipse workbench. For automated instrumentation builds and report generation EMMA's Ant tasks are the better choice.
  • No project modification: Coverage analysis is a way to look at your projects, but it is not an inherent part of your projects. Therefore a coverage tool should work without touching your project's source tree or configuration.
  • Extensibility: Allow other developers to extend EclEmma's functionality or build new features using the services provided by EclEmma.
  • And finally: Keep it simple!

The following sections provide a high level overview about EclEmma's key implementation strategies.

Separate Backend from GUI

EclEmma is packaged in two plug-ins: The core plug-in offers all functionality for launching and analysis. It has no dependencies on the Eclipse UI and all functionality can also be used in headless mode. The JUnit tests for the core plug-in run headless. The UI plug-in provides the workbench integration and relies on the core's public API only (no "x-friend" declarations). This approach also verifies the usability of the core API.

EMMA Data Files

EMMA creates meta data and coverage result files. To avoid modifying projects these files are stored in the plug-in's state location.

Launching in Coverage Mode

Instead of re-implementing launcher for the different launch types, the existing launchers for the Run mode are used with adjusted launch configurations. The coverage launchers perform these steps:

  1. Instrument selected class files.
  2. Create a temporary working copy of the launch configuration and adjust it to inject the instrumented classes and EMMA runtime properties.
  3. Delegate to the launcher for Run mode of this launch type.

Instrumentation

EclEmma follows the offline instrumentation approach, i.e. class files are prepared before the application is started. The class file instrumentation is triggered by the coverage launcher and always performed incrementally. Depending on the launch type two different instrumentation modes are possible: The class files can be instrumented in-place, i.e. the compiled binaries are replaced with instrumented versions. This is only allowed for class files compiled from source folders, as these file can easily be reconstructed with a new clean build. In copy mode instrumented versions of the class files are stored in the plug-in's state location. While this requires tweaking the classpath also binary libraries can safely be instrumented this way.

EMMA Runtime Properties

At runtime EMMA needs some basic properties like the file's location where to write the coverage information. These properties are defined in a dynamically created emma.properties file, which in turn is packed into a JAR archive and injected into the class path.

Coverage Session

A coverage session (com.mountainminds.eclemma.core.ICoverageSession) is the result of a coverage run (or multiple merged runs) or coverage data imported from an external source. It is an immutable container for all data necessary to

  • provide coverage highlighting in Java editors,
  • populate the Coverage view and
  • export coverage reports using EMMA's reporting capabilities.

Whenever a coverage launch terminates a coverage session is automatically created. While there can be a list of coverage sessions, at most one session can be the active session which is used to provide coverage summaries for Java elements and source code highlighting.

Coverage Analysis

When a coverage session becomes active the corresponding meta data and coverage data files are processed directly using the com.vladium.emma.data package. Coverage information is described by com.mountainminds.eclemma.core.analysis.IJavaElementCoverage instances for each Java model element (see org.eclipse.jdt.core package). An adapter factory allows obtaining the corresponding IJavaElementCoverage instances for a particular Java model element via IJavaElement.getAdapter().

Editor Highlighting

The EclEmma UI plug-in tracks the currently opened Java editors and piggybacks a specialized annotation model to the editors' annotation model.