elharo commented on code in PR #395:
URL:
https://github.com/apache/maven-build-cache-extension/pull/395#discussion_r2576995320
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -163,8 +176,16 @@ public void execute(
.isEmpty()) {
LOGGER.info("Cache storing is skipped since there was no
\"clean\" phase.");
} else {
- final Map<String, MojoExecutionEvent> executionEvents =
mojoListener.getProjectExecutions(project);
- cacheController.save(result, mojoExecutions,
executionEvents);
+ // Validation-time events must exist for cache storage
+ // If they don't exist, this indicates a bug in the
capture logic
+ if (result.getValidationTimeEvents() == null
+ || result.getValidationTimeEvents().isEmpty()) {
+ throw new AssertionError(
+ "Validation-time properties not captured for
project " + projectName
+ + ". This is a bug - validation-time
capture should always succeed when saving to cache.");
Review Comment:
run-on sentence
This is a bug. Validation-itme...
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -434,6 +455,63 @@ private static String normalizedPath(Path path, Path
baseDirPath) {
return normalizedPath;
}
+ /**
+ * Captures plugin properties at validation time for all mojo executions.
+ * This ensures properties are read at the same lifecycle point for all
builds,
+ * eliminating timing mismatches caused by Maven 4's auto-injection of
properties
+ * like --module-version during execution.
+ *
+ * @param session Maven session
+ * @param project Current project
+ * @param mojoExecutions List of mojo executions to capture properties for
+ * @return Map of execution key to MojoExecutionEvent captured at
validation time
+ */
+ private Map<String, MojoExecutionEvent> captureValidationTimeProperties(
+ MavenSession session, MavenProject project, List<MojoExecution>
mojoExecutions) {
+ Map<String, MojoExecutionEvent> validationTimeEvents = new
java.util.HashMap<>();
+
+ for (MojoExecution mojoExecution : mojoExecutions) {
+ // Skip mojos that don't execute or are in clean phase
+ if (mojoExecution.getLifecyclePhase() == null
+ ||
!lifecyclePhasesHelper.isLaterPhaseThanClean(mojoExecution.getLifecyclePhase()))
{
+ continue;
+ }
+
+ Mojo mojo = null;
Review Comment:
declare this inside the try block where initialized
##########
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java:
##########
@@ -434,6 +455,63 @@ private static String normalizedPath(Path path, Path
baseDirPath) {
return normalizedPath;
}
+ /**
+ * Captures plugin properties at validation time for all mojo executions.
+ * This ensures properties are read at the same lifecycle point for all
builds,
+ * eliminating timing mismatches caused by Maven 4's auto-injection of
properties
+ * like --module-version during execution.
+ *
+ * @param session Maven session
+ * @param project Current project
+ * @param mojoExecutions List of mojo executions to capture properties for
+ * @return Map of execution key to MojoExecutionEvent captured at
validation time
+ */
+ private Map<String, MojoExecutionEvent> captureValidationTimeProperties(
+ MavenSession session, MavenProject project, List<MojoExecution>
mojoExecutions) {
+ Map<String, MojoExecutionEvent> validationTimeEvents = new
java.util.HashMap<>();
Review Comment:
java.util.HashMap --> HashMap
##########
src/main/java/org/apache/maven/buildcache/CacheResult.java:
##########
@@ -31,49 +34,91 @@ public class CacheResult {
private final RestoreStatus status;
private final Build build;
private final CacheContext context;
+ private final Map<String, MojoExecutionEvent> validationTimeEvents;
- private CacheResult(RestoreStatus status, Build build, CacheContext
context) {
+ private CacheResult(
+ RestoreStatus status,
+ Build build,
+ CacheContext context,
+ Map<String, MojoExecutionEvent> validationTimeEvents) {
Review Comment:
This exposes mutable private state. Probably should copy for safety
--
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]