This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-help-plugin.git

commit b5e01a3e078b4ba6f9c89ffbd9de8b884cf0c798
Author: Efe Gökdemir <[email protected]>
AuthorDate: Wed Sep 23 13:43:32 2026 +0300

    Fix list goals output routing
    
    Signed-off-by: Efe Gökdemir <[email protected]>
---
 .../plugins/help/ListDependencyTypesMojo.java      |  7 +-
 .../plugins/help/ListLifecyclePhasesMojo.java      |  7 +-
 .../maven/plugins/help/ListPackagingMojo.java      |  7 +-
 .../maven/plugins/help/ListMojoOutputTest.java     | 91 ++++++++++++++++++++++
 4 files changed, 106 insertions(+), 6 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugins/help/ListDependencyTypesMojo.java 
b/src/main/java/org/apache/maven/plugins/help/ListDependencyTypesMojo.java
index e45c095..2aec5e1 100644
--- a/src/main/java/org/apache/maven/plugins/help/ListDependencyTypesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/ListDependencyTypesMojo.java
@@ -92,8 +92,11 @@ public class ListDependencyTypesMojo extends 
AbstractHelpMojo {
                 }
                 descriptionBuffer.append(LS);
             }
-            getLog().info(LS + "Maven Dependency Types defined:" + LS + LS + 
descriptionBuffer);
-            writeFile(output, descriptionBuffer);
+            if (output != null) {
+                writeFile(output, descriptionBuffer);
+            } else {
+                getLog().info(LS + "Maven Dependency Types defined:" + LS + LS 
+ descriptionBuffer);
+            }
         } catch (IOException e) {
             throw new MojoFailureException(e);
         }
diff --git 
a/src/main/java/org/apache/maven/plugins/help/ListLifecyclePhasesMojo.java 
b/src/main/java/org/apache/maven/plugins/help/ListLifecyclePhasesMojo.java
index 77ce1f2..8edf1e7 100644
--- a/src/main/java/org/apache/maven/plugins/help/ListLifecyclePhasesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/ListLifecyclePhasesMojo.java
@@ -73,8 +73,11 @@ public class ListLifecyclePhasesMojo extends 
AbstractHelpMojo {
                         .forEach(p -> descriptionBuffer.append(" * 
").append(p).append(LS));
                 descriptionBuffer.append(LS);
             }
-            getLog().info(LS + "Maven lifecycles defined:" + LS + LS + 
descriptionBuffer);
-            writeFile(output, descriptionBuffer);
+            if (output != null) {
+                writeFile(output, descriptionBuffer);
+            } else {
+                getLog().info(LS + "Maven lifecycles defined:" + LS + LS + 
descriptionBuffer);
+            }
         } catch (IOException e) {
             throw new MojoFailureException(e);
         }
diff --git a/src/main/java/org/apache/maven/plugins/help/ListPackagingMojo.java 
b/src/main/java/org/apache/maven/plugins/help/ListPackagingMojo.java
index e57146c..4c560c9 100644
--- a/src/main/java/org/apache/maven/plugins/help/ListPackagingMojo.java
+++ b/src/main/java/org/apache/maven/plugins/help/ListPackagingMojo.java
@@ -107,8 +107,11 @@ public class ListPackagingMojo extends AbstractHelpMojo {
                 }
                 descriptionBuffer.append(LS);
             }
-            getLog().info(LS + "Maven packaging defined:" + LS + LS + 
descriptionBuffer);
-            writeFile(output, descriptionBuffer);
+            if (output != null) {
+                writeFile(output, descriptionBuffer);
+            } else {
+                getLog().info(LS + "Maven packaging defined:" + LS + LS + 
descriptionBuffer);
+            }
         } catch (IOException e) {
             throw new MojoFailureException(e);
         }
diff --git 
a/src/test/java/org/apache/maven/plugins/help/ListMojoOutputTest.java 
b/src/test/java/org/apache/maven/plugins/help/ListMojoOutputTest.java
new file mode 100644
index 0000000..4a05613
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/help/ListMojoOutputTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.plugins.help;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.apache.maven.api.di.Provides;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.plugin.logging.Log;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static 
org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+/** Tests that list goals route output to either the file or the log. */
+@ExtendWith(MockitoExtension.class)
+@MojoTest
+class ListMojoOutputTest {
+
+    @Mock
+    private Log log;
+
+    @TempDir
+    private Path tempDir;
+
+    @Provides
+    private Log provideLogger() {
+        return log;
+    }
+
+    @Test
+    @InjectMojo(goal = "list-dependency-types")
+    void dependencyTypesWriteOnlyToConfiguredFile(ListDependencyTypesMojo 
mojo) throws Exception {
+        Path output = tempDir.resolve("dependency-types.txt");
+        setVariableValueToObject(mojo, "output", output.toFile());
+
+        mojo.execute();
+
+        assertFalse(new String(Files.readAllBytes(output)).isEmpty());
+        verify(log, never()).info(anyString());
+    }
+
+    @Test
+    @InjectMojo(goal = "list-lifecycle-phases")
+    void lifecyclePhasesWriteOnlyToConfiguredFile(ListLifecyclePhasesMojo 
mojo) throws Exception {
+        Path output = tempDir.resolve("lifecycle-phases.txt");
+        setVariableValueToObject(mojo, "output", output.toFile());
+
+        mojo.execute();
+
+        assertFalse(new String(Files.readAllBytes(output)).isEmpty());
+        verify(log, never()).info(anyString());
+    }
+
+    @Test
+    @InjectMojo(goal = "list-packaging")
+    void packagingWritesOnlyToConfiguredFile(ListPackagingMojo mojo) throws 
Exception {
+        Path output = tempDir.resolve("packaging.txt");
+        setVariableValueToObject(mojo, "output", output.toFile());
+
+        mojo.execute();
+
+        assertFalse(new String(Files.readAllBytes(output)).isEmpty());
+        verify(log, never()).info(anyString());
+    }
+}

Reply via email to