gnodet opened a new pull request, #14077:
URL: https://github.com/apache/maven/pull/14077

   ## Summary
   
   Introduces a structured **build report** generated at the end of each Maven 
session. The report captures per-mojo timing, status, and log output, as well 
as subproject and build-level metadata, and writes an atomic JSON file to 
`target/build-reports/`.
   
   This complements the unified `Logger/LogEvent/LogSink` API introduced in 
#13832 and uses its fan-out mechanism to route enriched log events to the 
collector without any static coupling.
   
   ---
   
   ## Public API (`api/maven-api-core`)
   
   New package `org.apache.maven.api.build.report` with the following 
`@Experimental` interfaces:
   
   | Interface | Description |
   |---|---|
   | `BuildReport` | Top-level report: status, duration, invocation, 
subprojects, failures, build log |
   | `SubprojectReport` | Per-subproject: status, duration, mojos, log output, 
trace context |
   | `MojoReport` | Per-mojo: goal, phase, status, duration, log output, trace 
context |
   | `FailureReport` | Failure detail: subproject, mojo, exception type, 
message, truncated stack trace |
   | `BuildStatus` | `SUCCESS` / `FAILURE` / `SKIPPED` |
   | `BuildInvocation` | CLI invocation context: goals, profiles, properties, 
make-behavior, etc. |
   
   New constants in `Constants`:
   
   - `MAVEN_BUILD_REPORT_MAX_LOG_EVENTS` — cap on log events per scope 
(default: 500)
   - `MAVEN_BUILD_REPORT_MAX_STACKTRACE_LINES` — cap on stack-trace lines per 
failure (default: 30)
   - `MAVEN_BUILD_REPORT_MAX_THROWABLE_LINES` — cap on throwable lines per log 
event (default: 10)
   
   ---
   
   ## Implementation (`impl/maven-impl`)
   
   `BuildReportCollector` implements `ExecutionListener + LogSink + SpiService` 
and is **auto-discovered** via the existing SPI mechanism 
(`lookupList(SpiService.class)`). No `@Named`/Sisu wiring needed.
   
   **Log capture** is received directly from `ProjectBuildLogAppender` after it 
has enriched events with `projectId`/`mojoId`. Events are routed to per-mojo, 
per-subproject, or build-level ring buffers (each capped, default 500 events), 
then drained into the report at session end.
   
   **Timing and status** are tracked via typed `ExecutionListener` callbacks 
(`sessionStarted`, `mojoStarted`, `mojoSucceeded`, `mojoFailed`, 
`projectStarted`, `projectSucceeded`, `projectFailed`, `sessionEnded`).
   
   **Output**: an atomic `build-report-{timestamp}.json` plus an atomic 
`build-report-latest.json` symlink under `target/build-reports/`. Falls back to 
a plain copy on Windows.
   
   **Thread safety**: concurrent `-T` builds write to their own 
`ConcurrentHashMap` entries. The singleton is reusable across builds (mvnd / 
embedded Maven): `sessionEnded()` clears all per-session state.
   
   ---
   
   ## Fan-out wiring (`impl/maven-core` + `impl/maven-cli`)
   
   `ProjectBuildLogAppender` replaces the former static `reportCapture: 
Consumer<LogEvent>` hook with a clean `secondarySinks: List<LogSink>` fan-out:
   
   - New `setSpiSinks(List<LogSink>)` method on `ProjectBuildLogAppender`
   - `LookupContext` gains a `projectBuildLogAppender` field so `lookup()` can 
reach the already-constructed appender
   - `LookupInvoker.lookup()` discovers all `SpiService` instances that 
implement `LogSink` and wires them in after the DI container is initialized 
(safely after `configureLogging()`)
   
   ---
   
   ## JSON output format
   
   ```json
   {
     "reportVersion": "1.0",
     "invocation": {
       "goals": ["clean", "install"],
       "offline": false,
       "updateSnapshots": false,
       "batchMode": false,
       "threads": 1
     },
     "status": "SUCCESS",
     "startTime": "2025-07-29T14:30:00Z",
     "durationMs": 12345,
     "mavenVersion": "4.2.0",
     "javaVersion": "21.0.2",
     "projectId": "org.example:my-app:1.0.0",
     "multiSubproject": false,
     "threads": 1,
     "subprojects": [
       {
         "groupId": "org.example",
         "artifactId": "my-app",
         "version": "1.0.0",
         "status": "SUCCESS",
         "durationMs": 500,
         "mojos": [
           {
             "goal": "compile",
             "phase": "compile",
             "groupId": "org.apache.maven.plugins",
             "artifactId": "maven-compiler-plugin",
             "version": "3.15.0",
             "executionId": "default-compile",
             "status": "SUCCESS",
             "startTime": "2025-07-29T14:30:00.100Z",
             "durationMs": 300,
             "output": [
               { "level": "INFO", "message": "Compiling 42 source files" }
             ]
           }
         ],
         "output": []
       }
     ],
     "failures": [],
     "problems": [],
     "output": []
   }
   ```
   
   ---
   
   ## Tests
   
   - `BuildReportCollectorTest` (10 tests in `impl/maven-impl`) — full 
lifecycle simulation, log-capture routing, cap enforcement, state-clear between 
builds, trace context capture, mojo skipping
   - `BuildReportJsonWriterTest` (10 tests in `impl/maven-impl` + mirrored in 
`impl/maven-core`) — JSON serialization, truncation of stack traces and 
throwables, edge cases (null fields, empty collections)
   
   ---
   
   ## Checklist
   
   - [x] New API types are `@Experimental`
   - [x] No static coupling between `maven-impl` and `maven-core` (SPI fan-out 
only)
   - [x] `maven-impl` does not depend on `maven-core`
   - [x] Thread-safe for parallel builds (`-T`)
   - [x] mvnd / embedded Maven reuse safe (state cleared at session end)
   - [x] Atomic file writes (temp + rename)
   - [x] Windows fallback (copy instead of symlink)
   - [x] All caps configurable via system/user properties
   
   ---
   
   _Hermes Agent (Claude Sonnet 4.5) on behalf of Guillaume Nodet_
   


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