gnodet-bot commented on code in PR #13832:
URL: https://github.com/apache/maven/pull/13832#discussion_r4592408366


##########
impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java:
##########
@@ -589,7 +600,7 @@ protected BindingStyler getBindingStyler() {
             injector.bindInstance(Session.class, sessionV4);
             injector.bindInstance(Project.class, project);
             injector.bindInstance(org.apache.maven.api.MojoExecution.class, 
execution);
-            injector.bindInstance(Log.class, log);
+            injector.bindInstance(org.apache.maven.api.plugin.Log.class, log);

Review Comment:
   🔴 **`org.apache.maven.api.logging.Logger` is not bound — `@Inject Logger` 
will fail at runtime**
   
   `DefaultLogger` implements **both** `org.apache.maven.api.plugin.Log` and 
`org.apache.maven.api.logging.Logger`, but only `Log.class` is bound:
   
   ```java
   injector.bindInstance(org.apache.maven.api.plugin.Log.class, log);
   // Missing: injector.bindInstance(org.apache.maven.api.logging.Logger.class, 
(Logger) log);
   ```
   
   Any v4 plugin that injects the new unified API type:
   
   ```java
   @Inject
   private org.apache.maven.api.logging.Logger logger;
   ```
   
   will fail at runtime with an unsatisfied binding exception. Since `Logger` 
is the primary type advertised by this PR, it must be injected alongside `Log`.
   
   **Fix:**
   ```suggestion
               injector.bindInstance(org.apache.maven.api.plugin.Log.class, 
log);
               injector.bindInstance(org.apache.maven.api.logging.Logger.class, 
(org.apache.maven.api.logging.Logger) log);
   ```



##########
impl/maven-core/src/main/java/org/apache/maven/classrealm/DefaultClassRealmManager.java:
##########
@@ -111,6 +111,7 @@ public DefaultClassRealmManager(
 
         Map<String, ClassLoader> apiV4Imports = new HashMap<>();
         apiV4Imports.put("org.apache.maven.api", containerRealm);
+        apiV4Imports.put("org.apache.maven.logging", containerRealm);

Review Comment:
   🔴 **Exporting the entire `org.apache.maven.logging` implementation package 
to plugins**
   
   Adding `org.apache.maven.logging` to `apiV4Imports` makes the full 
implementation package — including `ProjectBuildLogAppender`, 
`AsyncDrainWriter`, `LoggingOutputStream`, `BuildEventListener` and other 
internals — visible to every plugin's classloader.
   
   The correct scope for plugin injection is `org.apache.maven.api.logging` 
(the public API in `maven-api-log`). Implementation classes in 
`org.apache.maven.logging` are core internals that plugins have no business 
referencing directly.
   
   Consider limiting the import:
   ```suggestion
           apiV4Imports.put("org.apache.maven.api.logging", containerRealm);
   ```
   If plugins need to receive `LogEvent`, `Logger`, `LogSink` from the API 
module, `org.apache.maven.api.logging` is the right package. If 
`DefaultLoggerManager` or `DefaultLogger` must be reachable from plugin code, 
that is an architectural red flag — those types should be accessed only through 
the API interface.



##########
impl/maven-core/src/main/resources/META-INF/maven/extension.xml:
##########
@@ -34,6 +34,7 @@ under the License.
     <exportedPackage>org.apache.maven.feature</exportedPackage>
     <exportedPackage>org.apache.maven.graph</exportedPackage>
     <exportedPackage>org.apache.maven.lifecycle</exportedPackage>
+    <exportedPackage>org.apache.maven.logging</exportedPackage>

Review Comment:
   🟡 **`extension.xml` exports the implementation package, not the API package**
   
   ```xml
   <exportedPackage>org.apache.maven.logging</exportedPackage>
   ```
   
   This exports the entire `impl/maven-core` logging implementation to 
extensions and plugins. The public contract lives in 
`org.apache.maven.api.logging` (from `maven-api-log`). Exporting the 
implementation package allows extensions to depend on internal types that could 
change between Maven releases.
   
   If the goal is to allow extensions to receive log events, the exported 
package should be `org.apache.maven.api.logging`, not 
`org.apache.maven.logging`.



##########
impl/maven-logging/src/main/java/org/apache/maven/logging/impl/DefaultLoggerManager.java:
##########
@@ -0,0 +1,388 @@
+/*
+ * 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.logging.impl;
+
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.maven.api.Constants;
+import org.apache.maven.api.logging.LogEvent;
+import org.apache.maven.api.logging.LogLevel;
+import org.apache.maven.api.logging.LogSink;
+import org.apache.maven.api.logging.Logger;
+import org.apache.maven.api.logging.LoggerManager;
+
+/**
+ * Default {@link LoggerManager} implementation. Owns:
+ * <ul>
+ *   <li>Per-logger level configuration (loaded from properties files)</li>
+ *   <li>The active {@link LogSink}</li>
+ *   <li>Severity tracking for {@code --fail-on-severity}</li>
+ * </ul>
+ * <p>
+ * This class has no SLF4J dependency. The SLF4J adapter layer creates
+ * an instance and registers it via {@link LoggerManager#set(LoggerManager)}.
+ *
+ * @since 4.2.0
+ */
+public class DefaultLoggerManager implements LoggerManager {
+
+    private static final String CONFIGURATION_FILE = "maven.logger.properties";
+
+    @Deprecated(since = "4.0.0")
+    private static final String LEGACY_CONFIGURATION_FILE = 
"simplelogger.properties";
+
+    private static final String LEGACY_PREFIX = "org.slf4j.simpleLogger.";
+
+    public static final int LOG_LEVEL_TRACE = 0;
+    public static final int LOG_LEVEL_DEBUG = 10;
+    public static final int LOG_LEVEL_INFO = 20;
+    public static final int LOG_LEVEL_WARN = 30;
+    public static final int LOG_LEVEL_ERROR = 40;
+    public static final int LOG_LEVEL_OFF = 50;
+
+    private static final AtomicLong SEQUENCE = new AtomicLong();

Review Comment:
   â„šī¸ **`SEQUENCE` is `static` but accessed through an instance method**
   
   ```java
   private static final AtomicLong SEQUENCE = new AtomicLong();
   ```
   
   ```java
   public long nextSequenceNumber() {         // instance method on line ~220
       return SEQUENCE.getAndIncrement();
   }
   ```
   
   `DefaultLoggerManager` is designed as a singleton (registered via 
`LoggerManager.set()`), so the static counter works in practice. However, the 
mismatch between `static` field and `public` instance accessor is confusing — 
either:
   
   - Make `SEQUENCE` an instance field (since there is only one 
`DefaultLoggerManager`), or
   - Make `nextSequenceNumber()` a `static` method (to signal that it is not 
instance-state).
   
   The current mix suggests the accessor might be overridable or that multiple 
instances are possible, neither of which is true.



##########
its/core-it-suite/src/test/resources/gh-13522-logger-context/src/main/java/org/apache/maven/its/gh13522/CheckContextMojo.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.its.gh13522;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.maven.api.logging.LogEvent;
+import org.apache.maven.api.logging.LoggerManager;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.logging.ProjectBuildLogAppender;

Review Comment:
   🟡 **IT fixture plugin imports implementation class — teaches wrong pattern 
to plugin authors**
   
   ```java
   import org.apache.maven.logging.ProjectBuildLogAppender;
   ```
   
   This IT fixture is part of the Maven codebase and effectively serves as a 
canonical example for plugin development. Importing an implementation class 
(`org.apache.maven.logging.*`) from an IT fixture normalises a pattern that 
will break when Maven is updated.
   
   The mojo should demonstrate the correct approach using only the public API 
(`org.apache.maven.api.logging.*`). If `ProjectBuildLogAppender` context values 
need to be verified in the IT, the mojo could check them via the `Logger` or 
`LogEvent` fields that the API exposes, rather than accessing the 
implementation class directly.



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