Class SCoverageForkedLifecycleConfigurator
This configurator is essential for integrating Scoverage into multi-module Maven projects, especially in concurrent build environments. Its primary role is to modify the project's build output directories and artifact paths to facilitate Scoverage's requirements (e.g., compiling instrumented code into a separate directory) and then restore the original configuration for reactor projects after Scoverage processing is complete.
Workflow:
The configurator operates in two main phases:
-
Entering Forked Scoverage Lifecycle (
afterForkedLifecycleEnter):- The current project's build output directory (
project.build.outputDirectory) is switched from its default (e.g.,target/classes) to a Scoverage-specific directory (e.g.,target/scoverage-classes). - The project's main artifact file (
project.artifact.file) is temporarily nulled out to force Maven to re-resolve it against the new output directory. - All direct reactor dependencies of the current project are also configured similarly, by backing up their original paths and switching to forked paths.
- The current project's build output directory (
-
Exiting Forked Scoverage Lifecycle (
afterForkedLifecycleExit):- The Scoverage-specific build output directory and artifact file paths are
retrieved from the
project.getExecutionProject()and stored for reference. - For any projects in the reactor that were previously modified (identified by the presence of backup properties), their original build configuration is restored. Note: This restoration is not applied to the main project that entered the lifecycle, only to the projects found in the reactor list.
- The Scoverage-specific build output directory and artifact file paths are
retrieved from the
Thread-Safety:
To ensure correctness and prevent race conditions in multi-threaded Maven builds (e.g., using -T flag),
all modifications to a MavenProject's configuration are performed under a per-project ReentrantLock.
This guarantees that only one thread can modify a given project's state at any time, maintaining consistency.
- Author:
- Grzegorz Slowikowski
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidafterForkedLifecycleEnter(MavenProject project, List<MavenProject> reactorProjects, Map<String, String> additionalProjectPropertiesMap) Configures project and dependent modules in multi-module project when entering forkedscoveragelife cycle.static voidafterForkedLifecycleExit(MavenProject project, List<MavenProject> reactorProjects) Restores original configuration after leaving forkedscoveragelife cycle.
-
Constructor Details
-
SCoverageForkedLifecycleConfigurator
public SCoverageForkedLifecycleConfigurator()
-
-
Method Details
-
afterForkedLifecycleEnter
public static void afterForkedLifecycleEnter(MavenProject project, List<MavenProject> reactorProjects, Map<String, String> additionalProjectPropertiesMap) Configures project and dependent modules in multi-module project when entering forkedscoveragelife cycle.
Thread-safe for concurrent execution in multi-threaded Maven builds. This method first configures the current project for scoverage, then identifies and updates its reactor dependencies to also use the scoverage configuration.- Parameters:
project- Maven project inscoverageforked life cycle.reactorProjects- all reactor Maven projects.additionalProjectPropertiesMap- additional project properties to set.
-
afterForkedLifecycleExit
public static void afterForkedLifecycleExit(MavenProject project, List<MavenProject> reactorProjects) Restores original configuration after leaving forkedscoveragelife cycle.
projectis a project in default life cycle,project.getExecutionProject()is a project in just finished forkedscoveragelife cycle.
Thread-safe for concurrent execution in multi-threaded Maven builds.- Parameters:
project- Maven project in default life cycle.reactorProjects- all reactor Maven projects.
-