cowwoc commented on code in PR #394:
URL:
https://github.com/apache/maven-build-cache-extension/pull/394#discussion_r2582220969
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -138,33 +139,58 @@ public void execute(
boolean restorable = result.isSuccess() ||
result.isPartialSuccess();
boolean restored = false; // if partially restored need to save
increment
+
if (restorable) {
CacheRestorationStatus cacheRestorationStatus =
restoreProject(result, mojoExecutions,
mojoExecutionRunner, cacheConfig);
restored = CacheRestorationStatus.SUCCESS ==
cacheRestorationStatus;
executeExtraCleanPhaseIfNeeded(cacheRestorationStatus,
cleanPhase, mojoExecutionRunner);
}
- if (!restored) {
- for (MojoExecution mojoExecution : mojoExecutions) {
- if (source == Source.CLI
- || mojoExecution.getLifecyclePhase() == null
- ||
lifecyclePhasesHelper.isLaterPhaseThanClean(mojoExecution.getLifecyclePhase()))
{
- mojoExecutionRunner.run(mojoExecution);
+
+ try {
+ if (!restored && !forkedExecution) {
+ // Move pre-existing artifacts to staging directory to
prevent caching stale files
+ // from previous builds (e.g., after git branch switch, or
from cache restored
+ // with clock skew). This ensures save() only sees fresh
files built during this session.
+ // Skip for forked executions since they don't cache and
shouldn't modify artifacts.
+ try {
+ cacheController.stagePreExistingArtifacts(session,
project);
+ } catch (IOException e) {
+ LOGGER.warn("Failed to stage pre-existing artifacts:
{}", e.getMessage());
+ // Continue build - if staging fails, we'll just cache
what exists
Review Comment:
Done. Try now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]