gnodet commented on code in PR #13058:
URL: https://github.com/apache/maven/pull/13058#discussion_r3945583491
##########
impl/maven-core/src/main/java/org/apache/maven/internal/impl/EventSpyImpl.java:
##########
@@ -40,25 +42,53 @@ public void init(Context context) throws Exception {}
@Override
public void onEvent(Object arg) throws Exception {
- if (arg instanceof ExecutionEvent ee) {
+ if (arg instanceof org.apache.maven.execution.ExecutionEvent ee) {
InternalMavenSession session =
InternalMavenSession.from(ee.getSession().getSession());
- EventType eventType = convert(ee.getType());
+ ExecutionEventType eventType = convert(ee.getType());
Collection<Listener> listeners = session.getListeners();
if (!listeners.isEmpty()) {
- Event event = new DefaultEvent(session, ee, eventType);
+ ExecutionEvent event = new DefaultEvent(session, ee,
eventType);
for (Listener listener : listeners) {
+ // Call deprecated generic handler for backward
compatibility
listener.onEvent(event);
+ // Call typed handler for new-style listeners
+ if (listener instanceof ExecutionListener el) {
+ dispatchTyped(el, event, eventType);
+ }
}
}
}
}
+ private void dispatchTyped(ExecutionListener listener, ExecutionEvent
event, ExecutionEventType type) {
+ switch (type) {
+ case PROJECT_DISCOVERY_STARTED ->
listener.projectDiscoveryStarted(event);
+ case SESSION_STARTED -> listener.sessionStarted(event);
+ case SESSION_ENDED -> listener.sessionEnded(event);
+ case PROJECT_SKIPPED -> listener.projectSkipped(event);
+ case PROJECT_STARTED -> listener.projectStarted(event);
+ case PROJECT_SUCCEEDED -> listener.projectSucceeded(event);
+ case PROJECT_FAILED -> listener.projectFailed(event);
+ case MOJO_SKIPPED -> listener.mojoSkipped(event);
+ case MOJO_STARTED -> listener.mojoStarted(event);
+ case MOJO_SUCCEEDED -> listener.mojoSucceeded(event);
Review Comment:
💡 **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.
```suggestion
case FORKED_PROJECT_FAILED ->
listener.forkedProjectFailed(event);
```
##########
api/maven-api-core/src/main/java/org/apache/maven/api/ExecutionEventType.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.api;
+
+import org.apache.maven.api.annotations.Experimental;
+
+/**
+ * The possible types of execution events during the Maven build lifecycle.
+ *
+ * @see ExecutionEvent
+ * @see ExecutionListener
+ * @since 4.0.0
+ * @since 4.1.0 (renamed from {@link EventType})
+ */
Review Comment:
💡 **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.
```suggestion
* @since 4.1.0 (renamed from {@link EventType})
```
--
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]