Copilot commented on code in PR #522:
URL: 
https://github.com/apache/maven-build-cache-extension/pull/522#discussion_r3753973759


##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -116,8 +116,24 @@ public void execute(
             // so forks should rerun too
             boolean forkedExecution = 
lifecyclePhasesHelper.isForkedProject(project);
             String projectName = getVersionlessProjectKey(project);
+            // Full caching (look up, restore and save) applies to a normal 
lifecycle build, or to goals typed
+            // on the command line when they all map to a real phase after 
clean (e.g. mvn compiler:compile).
+            boolean cacheEligible = !forkedExecution
+                    && (source == Source.LIFECYCLE
+                            || (source == Source.CLI
+                                    && cacheConfig.isCacheSingleGoal()
+                                    && 
isCacheableCliInvocation(mojoExecutions)));
+            // When a command-line goal forks a lifecycle (e.g. jetty:run 
forks test-compile via
+            // @Execute(phase=...)), let that fork restore from cache but 
never save. We skip forks that happen
+            // inside a normal build: that build already handles caching, and 
joining in would just cause an
+            // extra, pointless cache lookup (see ForkedExecutionsTest / 
ForkedExecutionCoreExtensionTest).
+            boolean forkedRestoreEligible = forkedExecution
+                    && cacheConfig.isRestoreForkedExecutions()
+                    && source == Source.LIFECYCLE
+                    && isCliOriginatedFork(project)
+                    && forkReachesCacheablePhase(project, mojoExecutions);

Review Comment:
   Fork restore is enabled based only on the execution phases, not on whether 
the cache entry can restore the outputs those phases produce. With this test 
project's empty cache config, an `install` entry stores the JAR but not 
`target/classes`/`target/test-classes`; `restoreProject()` can then skip the 
compiler executions while restoring only the JAR, leaving a clean checkout with 
no classes for the run-style goal. The same occurs for entries created with 
`cacheCompile=false` or when attached-output restoration is disabled. Only 
accept a fork cache hit when the required compiled-output directories are 
actually restorable; otherwise execute the fork normally.



-- 
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]

Reply via email to