EclEmma 3.1.9 Java Code Coverage for Eclipse Drag to your running Eclipse workspace to install EclEmma Java Code Coverage
Eclipse Community Award 2008
JaCoCo
Inspected with sonarqube
jobs at mtrail
The Java Specialists' Newsletter

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 builds and report generation JaCoCo's various integrations with build tools like Ant and Maven 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. This approach also verifies the usability of the core API.

JaCoCo Execution Data Files

To avoid modifying projects all data 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. Create a temporary working copy of the launch configuration and adjust the VM arguments to add the JaCoCo agent to the Java VM.
  2. Delegate to the launcher for Run mode of the same launch type.

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 in different formats.

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

As soon as a coverage session becomes active the corresponding execution data is processed and analyzed against the classes in the workspace. Coverage information is described by a org.jacoco.core.analysis.ICoverageNode instances for each Java model element (see org.eclipse.jdt.core package). An adapter factory allows obtaining the corresponding ICoverageNode 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.