charangowdamd-cmd opened a new pull request, #13941:
URL: https://github.com/apache/maven/pull/13941
Closes #13805
### Summary
Enables `Listener`, `ExecutionListener`, and `RepositoryListener`
implementations to be auto-discovered as SPI services without introducing an
inheritance relationship between `Listener` (in `maven-api-core`) and
`SpiService` (in `maven-api-spi`), preventing circular module dependencies.
### Key Changes
1. **Auto-Discovery in `AbstractSession.java`**:
- `getListeners(session, lookup)` queries
`lookup.lookupList(SpiService.class)` when initializing the session's listener
list inside `session.getData().computeIfAbsent(...)`.
- Filters components implementing `Listener` and registers them if not
already added.
- Guaranteed to execute exactly once per underlying
`RepositorySystemSession`, preventing duplicate registrations upon session
derivation (`withRemoteRepositories`, `withContext`).
- Guarded with `catch (LookupException)` for test environments where SPI
services are not bound.
2. **Exception-Handling Documentation**:
- Updated Javadocs on `Listener`, `ExecutionListener`,
`RepositoryListener`, and `Session` documenting that `RuntimeException` thrown
by `onEvent()` is caught and logged at `WARN` level by dispatchers
(`EventSpyImpl`, `MavenRepositoryListener`) and swallowed so listeners cannot
abort the build.
3. **Unit Tests in `EventSpyImplTest.java`**:
- Added `autoDiscoversListenerImplementingSpiService` to verify that
`ExecutionListener` + `SpiService` components are auto-discovered, executed on
events, and not duplicated across derived sessions.
- Added `autoDiscoversRepositoryListenerImplementingSpiService` to verify
that repository listeners implementing `SpiService` are auto-discovered and
receive repository events.
### Verification
- Formatted with `spotless:apply` across `maven-api-core`, `maven-impl`, and
`maven-core`.
--
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]