in src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java [97:156]
public void execute(
List<MojoExecution> mojoExecutions, MavenSession session, MojoExecutionRunner mojoExecutionRunner)
throws LifecycleExecutionException {
try {
final MavenProject project = session.getCurrentProject();
final Source source = getSource(mojoExecutions);
// execute clean bound goals before restoring to not interfere/slowdown clean
CacheState cacheState = DISABLED;
CacheResult result = CacheResult.empty();
boolean skipCache = cacheConfig.isSkipCache() || MavenProjectInput.isSkipCache(project);
boolean cacheIsDisabled = MavenProjectInput.isCacheDisabled(project);
// Forked execution should be thought as a part of originating mojo internal implementation
// If forkedExecution is detected, it means that originating mojo is not cached so forks should rerun too
boolean forkedExecution = lifecyclePhasesHelper.isForkedProject(project);
if (source == Source.LIFECYCLE && !forkedExecution) {
List<MojoExecution> cleanPhase = lifecyclePhasesHelper.getCleanSegment(project, mojoExecutions);
for (MojoExecution mojoExecution : cleanPhase) {
mojoExecutionRunner.run(mojoExecution);
}
if (!cacheIsDisabled) {
cacheState = cacheConfig.initialize();
} else {
LOGGER.info(
"Cache is explicitly disabled on project level for {}", getVersionlessProjectKey(project));
}
if (cacheState == INITIALIZED || skipCache) {
result = cacheController.findCachedBuild(session, project, mojoExecutions, skipCache);
}
}
boolean restorable = result.isSuccess() || result.isPartialSuccess();
boolean restored = result.isSuccess(); // if partially restored need to save increment
if (restorable) {
restored &= restoreProject(result, mojoExecutions, mojoExecutionRunner, cacheConfig);
} else {
for (MojoExecution mojoExecution : mojoExecutions) {
if (source == Source.CLI
|| mojoExecution.getLifecyclePhase() == null
|| lifecyclePhasesHelper.isLaterPhaseThanClean(mojoExecution.getLifecyclePhase())) {
mojoExecutionRunner.run(mojoExecution);
}
}
}
if (cacheState == INITIALIZED && (!restorable || !restored)) {
final Map<String, MojoExecutionEvent> executionEvents = mojoListener.getProjectExecutions(project);
cacheController.save(result, mojoExecutions, executionEvents);
}
if (cacheConfig.isFailFast() && !result.isSuccess() && !skipCache && !forkedExecution) {
throw new LifecycleExecutionException(
"Failed to restore project[" + getVersionlessProjectKey(project)
+ "] from cache, failing build.",
project);
}
} catch (MojoExecutionException e) {
throw new LifecycleExecutionException(e.getMessage(), e);
}
}