in src/main/java/org/apache/maven/buildcache/CacheControllerImpl.java [298:356]
public boolean restoreProjectArtifacts(CacheResult cacheResult) {
final Build build = cacheResult.getBuildInfo();
final CacheContext context = cacheResult.getContext();
final MavenProject project = context.getProject();
try {
RestoredArtifact restoredProjectArtifact = null;
List<RestoredArtifact> restoredAttachedArtifacts = new ArrayList<>();
if (build.getArtifact() != null && isNotBlank(build.getArtifact().getFileName())) {
final Artifact artifactInfo = build.getArtifact();
String originalVersion = artifactInfo.getVersion();
artifactInfo.setVersion(project.getVersion());
// TODO if remote is forced, probably need to refresh or reconcile all files
final Future<File> downloadTask =
createDownloadTask(cacheResult, context, project, artifactInfo, originalVersion);
restoredProjectArtifact = restoredArtifact(
project.getArtifact(), artifactInfo.getType(), artifactInfo.getClassifier(), downloadTask);
}
for (Artifact attachedArtifactInfo : build.getAttachedArtifacts()) {
String originalVersion = attachedArtifactInfo.getVersion();
attachedArtifactInfo.setVersion(project.getVersion());
if (isNotBlank(attachedArtifactInfo.getFileName())) {
if (StringUtils.startsWith(attachedArtifactInfo.getClassifier(), BUILD_PREFIX)) {
// restoring generated sources might be unnecessary in CI, could be disabled for
// performance reasons
// it may also be disabled on a per-project level (defaults to true - enable)
if (cacheConfig.isRestoreGeneratedSources()
&& MavenProjectInput.isRestoreGeneratedSources(project)) {
// generated sources artifact
final Path attachedArtifactFile =
localCache.getArtifactFile(context, cacheResult.getSource(), attachedArtifactInfo);
restoreGeneratedSources(attachedArtifactInfo, attachedArtifactFile, project);
}
} else {
Future<File> downloadTask = createDownloadTask(
cacheResult, context, project, attachedArtifactInfo, originalVersion);
final RestoredArtifact restoredAttachedArtifact = restoredArtifact(
restoredProjectArtifact == null ? project.getArtifact() : restoredProjectArtifact,
attachedArtifactInfo.getType(),
attachedArtifactInfo.getClassifier(),
downloadTask);
restoredAttachedArtifacts.add(restoredAttachedArtifact);
}
}
}
// Actually modify project at the end in case something went wrong during restoration,
// in which case, the project is unmodified and we continue with normal build.
if (restoredProjectArtifact != null) {
project.setArtifact(restoredProjectArtifact);
}
restoredAttachedArtifacts.forEach(project::addAttachedArtifact);
return true;
} catch (Exception e) {
LOGGER.debug("Cannot restore cache, continuing with normal build.", e);
return false;
}
}