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


##########
its/core-it-suite/src/test/resources/gh-13522-logger-context/src/main/java/org/apache/maven/its/gh13522/CheckContextMojo.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.di.Inject;
+import org.apache.maven.api.logging.LogEvent;
+import org.apache.maven.api.logging.Logger;
+import org.apache.maven.api.logging.LoggerManager;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+
+/**
+ * Verifies that a DI-injected {@link Logger} carries the correct
+ * {@code projectId}, {@code mojoId}, and {@code pluginId} on each
+ * {@link LogEvent} it emits.
+ *
+ * <p>The mojo wraps the global {@link LoggerManager} sink, captures
+ * the first event it emits, extracts the context fields, and writes
+ * them to {@code target/log-context.properties} so the IT verifier
+ * can assert their values.</p>
+ */
+@Mojo(name = "check-context", defaultPhase = 
org.apache.maven.api.Lifecycle.Phase.VALIDATE, projectRequired = false)

Review Comment:
   ⚠️ `projectRequired = false` is inconsistent with the mojo's behavior — 
`${project.build.directory}` is a project-scoped expression, and 
`Paths.get(buildDirectory)` has no null guard. If this mojo were invoked 
without a project (e.g. in a test harness or aggregator context without a 
current project), `buildDirectory` would be null and throw NPE at line 88. The 
IT always provides a project so the test passes, but the annotation should be 
`projectRequired = true`.
   
   ```suggestion
   @Mojo(name = "check-context", defaultPhase = 
org.apache.maven.api.Lifecycle.Phase.VALIDATE, projectRequired = true)
   ```



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