Copilot commented on code in PR #522:
URL:
https://github.com/apache/maven-build-cache-extension/pull/522#discussion_r3746730931
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -261,6 +280,48 @@ private Source getSource(List<MojoExecution>
mojoExecutions) {
return Source.LIFECYCLE;
}
+ /**
+ * Decides whether a set of goals typed on the command line can be cached.
+ * <p>
+ * Every goal has to be non-aggregator and bound by default (via {@code
@Mojo(defaultPhase=...)}) to a real
+ * phase after clean. This keeps single-goal caching to goals that produce
the same output the matching phase
+ * would — e.g. {@code compiler:compile} is really the {@code compile}
phase — and it naturally leaves out
+ * long-running goals like {@code jetty:run} or {@code exec:java} (no
default phase) and clean-bound goals.
+ *
+ * @param mojoExecutions the goals requested on the command line
+ * @return true if the whole invocation can go through the normal
phase-based caching
+ */
+ private boolean isCacheableCliInvocation(List<MojoExecution>
mojoExecutions) {
+ if (mojoExecutions == null || mojoExecutions.isEmpty()) {
+ return false;
+ }
+ for (MojoExecution mojoExecution : mojoExecutions) {
+ if (mojoExecution.getMojoDescriptor() == null
+ || mojoExecution.getMojoDescriptor().isAggregator()) {
+ return false;
+ }
Review Comment:
`isCacheableCliInvocation` doesn’t verify that each `MojoExecution` actually
originated from the CLI. In mixed invocations (phase + goal), `getSource()`
returns `Source.CLI`, and this method can still return true if the lifecycle
mojos happen to have a default phase after clean. That would enable caching for
mixed lifecycle+CLI runs, contradicting the documented/established behavior
that such invocations bypass caching entirely (see
`AdditionalGoalAfterLifecycleTest` rationale).
--
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]