Skip to content

[MNG-8547] Introduce Event/Listener hierarchy with ExecutionEvent and ExecutionListener - #13058

Closed
gnodet wants to merge 1 commit into
masterfrom
feature/event-listener-hierarchy
Closed

[MNG-8547] Introduce Event/Listener hierarchy with ExecutionEvent and ExecutionListener#13058
gnodet wants to merge 1 commit into
masterfrom
feature/event-listener-hierarchy

Conversation

@gnodet

@gnodet gnodet commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Description

Introduce a base Event/Listener hierarchy to support multiple event families (execution, repository, etc.) through a single registration point on Session.

This PR refactors the existing Event/Listener/EventType types and introduces new typed specializations for build lifecycle events. The design enables PR #13011 to integrate its RepositoryEvent/RepositoryListener into the same hierarchy by simply extending Event and Listener.

API changes

Type Change
Event Stripped to base marker: @Immutable, single session() noun-style accessor
ExecutionEvent New — typed execution event (extends Event) with type(), project(), mojoExecution(), exception()
ExecutionEventType New — renamed from EventType for clarity, same values in same order
EventType @Deprecated(forRemoval) — alias with bridge methods to ExecutionEventType
ExecutionListener New — typed callbacks (extends Listener) with per-event-type default methods
Listener Refactored to base marker, @FunctionalInterface removed, onEvent() deprecated as default

Impl changes

  • DefaultEvent: implements ExecutionEvent with noun-style accessors
  • EventSpyImpl: dispatches to both legacy Listener.onEvent() and typed ExecutionListener callbacks

Design

Event (@Immutable, base marker)
├── ExecutionEvent (project, mojo, session lifecycle)
└── RepositoryEvent (artifact/metadata — PR #13011)

Listener (@Consumer, base marker)
├── ExecutionListener (typed default callbacks)
└── RepositoryListener (typed default callbacks — PR #13011)

Key properties:

  • Single registration: Session.registerListener(Listener) handles all listener types — no method overloading
  • Extensible: future event categories just add XxxEvent extends Event + XxxListener extends Listener
  • Backward compatible: old Listener.onEvent() stays as @Deprecated default
  • Noun-style accessors on new types, consistent with Switch core API value types to noun-style accessors #13036
  • Session.java, AbstractSession.java, SessionStub.java are unchanged — the existing List<Listener> works for both old and new listener types

Relationship with PR #13011

This PR provides the hierarchy foundation. PR #13011 should merge this, then:

  1. Make RepositoryEvent extends Event (add session() accessor)
  2. Make RepositoryListener extends Listener
  3. Remove the separate registerListener(RepositoryListener)/getRepositoryListeners() methods from Session
  4. Use noun-style accessors on RepositoryEvent and RepositoryMetadata

  • This pull request addresses one issue without unrelated changes.

  • The description explains what the pull request does, how, and why.

  • The commit has a meaningful subject and body.

  • mvn verify passes.

  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004

… ExecutionListener

Introduce a base Event/Listener hierarchy to support multiple event
families (execution, repository, etc.) through a single registration
point on Session.

- Event: minimal base interface with session() accessor
- ExecutionEvent: typed execution event (extends Event) with
  project(), mojoExecution(), exception() accessors
- ExecutionListener: typed callbacks (extends Listener) with
  per-event-type default methods
- ExecutionEventType: renamed from EventType for clarity
- EventType: kept as @deprecated alias
- Listener: refactored to base marker, onEvent() deprecated
- DefaultEvent: implements ExecutionEvent with noun-style accessors
- EventSpyImpl: dispatches to both legacy and typed listeners
@gnodet
gnodet force-pushed the feature/event-listener-hierarchy branch from cb6f143 to 4bda27d Compare September 6, 2026 21:59
@gnodet gnodet added this to the 4.1.0 milestone Sep 6, 2026

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid API design — the hierarchy cleanly separates execution events from the base marker, and the backward compatibility story is well thought out (deprecated bridge methods, dual dispatch). Two minor observations below.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

case PROJECT_FAILED -> listener.projectFailed(event);
case MOJO_SKIPPED -> listener.mojoSkipped(event);
case MOJO_STARTED -> listener.mojoStarted(event);
case MOJO_SUCCEEDED -> listener.mojoSucceeded(event);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Suggestion (low): The default branch is unreachable — all 17 ExecutionEventType values are explicitly handled. Removing it turns this into an exhaustive switch, so the compiler will flag any future enum additions as a compile error rather than silently dropping them.

Suggested change
case MOJO_SUCCEEDED -> listener.mojoSucceeded(event);
case FORKED_PROJECT_FAILED -> listener.forkedProjectFailed(event);

* @see ExecutionListener
* @since 4.0.0
* @since 4.1.0 (renamed from {@link EventType})
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Suggestion (low): @since 4.0.0 is misleading — this type is new in 4.1.0. EventType existed in 4.0.0, but ExecutionEventType didn't. The second @since tag clarifies the rename, but the first tag should match the actual introduction version.

Suggested change
*/
* @since 4.1.0 (renamed from {@link EventType})

@gnodet gnodet closed this Sep 7, 2026
@github-actions github-actions Bot removed this from the 4.1.0 milestone Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant