From 27e1cfaa5c7251248a95bb3873347cfa7ede5975 Mon Sep 17 00:00:00 2001 From: Neil Tomar Date: Sun, 9 Aug 2026 13:10:05 +0530 Subject: [PATCH 1/4] Fixed [#384]: fixed the issue made the properties read-only & added test case. --- .../maven/plugins/help/EffectivePomMojo.java | 2 +- .../plugins/help/EffectivePomMojoTest.java | 122 ++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java index 4fa115c2..ac3294ad 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -178,7 +178,7 @@ private boolean shouldWriteAllEffectivePOMsInReactor() { * @throws MojoExecutionException if any */ private void writeEffectivePom(MavenProject project, XMLWriter writer) throws MojoExecutionException { - Model pom = project.getModel(); + Model pom = project.getModel().clone(); cleanModel(pom); StringWriter sWriter = new StringWriter(); diff --git a/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java new file mode 100644 index 00000000..3e9ce949 --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java @@ -0,0 +1,122 @@ +/* + * 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 javax.inject.Inject; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.Properties; + +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoParameter; +import org.apache.maven.api.plugin.testing.MojoTest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Model; +import org.apache.maven.plugin.MojoExecution; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; +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.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.Mockito.when; + +/** + * Test class for the effective-pom mojo of the Help Plugin. + */ +@ExtendWith(MockitoExtension.class) +@MojoTest +class EffectivePomMojoTest { + + @Inject + private MavenProject project; + + @Inject + private MavenSession mavenSession; + + @Mock + private Log log; + + @Mock + private MojoExecution mojoExecution; + + @TempDir + private Path tempDir; + + private Path outputPath; + + private Model model; + + private Properties originalProperties; + + private Properties expectedProperties; + + @BeforeEach + void setup() throws IOException { + originalProperties = new Properties(); + originalProperties.setProperty("b.property", "b-value"); + originalProperties.setProperty("a.property", "a-value"); + + model = new Model(); + model.setProperties(originalProperties); + + when(project.getModel()).thenReturn(model); + + outputPath = Files.createTempFile(tempDir, "maven-help-plugin-test-", ".xml"); + mavenSession.getUserProperties().setProperty("outputPath", outputPath.toString()); + } + + /** + * The effective-pom goal only displays the model, so it must not modify the project it reads from. + * + * @throws Exception in case of errors. + */ + @Test + @InjectMojo(goal = "effective-pom") + @MojoParameter(name = "output", value = "${outputPath}") + void testExecuteDoesNotModifyProjectModel(EffectivePomMojo mojo) throws Exception { + // snapshot of the contents before the mojo runs, to detect in-place modification + expectedProperties = new Properties(); + expectedProperties.putAll(originalProperties); + + setVariableValueToObject(mojo, "projects", Collections.singletonList(project)); + setVariableValueToObject(mojo, "mojoExecution", mojoExecution); + + mojo.execute(); + + assertSame( + originalProperties, + model.getProperties(), + "effective-pom must not replace the properties of the project model"); + + assertEquals( + expectedProperties, + model.getProperties(), + "effective-pom must not modify the properties of the project model"); + } +} From 731fde47378d3a5829c01f9333bd069f3a841ca2 Mon Sep 17 00:00:00 2001 From: Neil Tomar Date: Sat, 22 Aug 2026 12:47:53 +0530 Subject: [PATCH 2/4] minor fix --- .../plugins/help/EffectivePomMojoTest.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java index 3e9ce949..2fb9a72e 100644 --- a/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java @@ -32,7 +32,6 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Model; import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -59,35 +58,26 @@ class EffectivePomMojoTest { @Inject private MavenSession mavenSession; - @Mock - private Log log; - @Mock private MojoExecution mojoExecution; @TempDir private Path tempDir; - private Path outputPath; - - private Model model; - - private Properties originalProperties; + private final Model model = new Model(); - private Properties expectedProperties; + private final Properties originalProperties = new Properties(); @BeforeEach void setup() throws IOException { - originalProperties = new Properties(); originalProperties.setProperty("b.property", "b-value"); originalProperties.setProperty("a.property", "a-value"); - model = new Model(); model.setProperties(originalProperties); when(project.getModel()).thenReturn(model); - outputPath = Files.createTempFile(tempDir, "maven-help-plugin-test-", ".xml"); + Path outputPath = Files.createTempFile(tempDir, "maven-help-plugin-test-", ".xml"); mavenSession.getUserProperties().setProperty("outputPath", outputPath.toString()); } @@ -101,7 +91,7 @@ void setup() throws IOException { @MojoParameter(name = "output", value = "${outputPath}") void testExecuteDoesNotModifyProjectModel(EffectivePomMojo mojo) throws Exception { // snapshot of the contents before the mojo runs, to detect in-place modification - expectedProperties = new Properties(); + Properties expectedProperties = new Properties(); expectedProperties.putAll(originalProperties); setVariableValueToObject(mojo, "projects", Collections.singletonList(project)); From 487f0eab6023835a2b7db389c6f6e93b8718a98e Mon Sep 17 00:00:00 2001 From: Neil Tomar Date: Mon, 24 Aug 2026 23:35:52 +0530 Subject: [PATCH 3/4] removed comments from test. --- .../apache/maven/plugins/help/EffectivePomMojoTest.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java index 2fb9a72e..c2f7ac3c 100644 --- a/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java @@ -34,7 +34,6 @@ import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; @@ -81,12 +80,6 @@ void setup() throws IOException { mavenSession.getUserProperties().setProperty("outputPath", outputPath.toString()); } - /** - * The effective-pom goal only displays the model, so it must not modify the project it reads from. - * - * @throws Exception in case of errors. - */ - @Test @InjectMojo(goal = "effective-pom") @MojoParameter(name = "output", value = "${outputPath}") void testExecuteDoesNotModifyProjectModel(EffectivePomMojo mojo) throws Exception { From ce65c78c4a3012cfbe4f254394e5a6b7c128a7f9 Mon Sep 17 00:00:00 2001 From: Neil Tomar Date: Mon, 24 Aug 2026 23:40:59 +0530 Subject: [PATCH 4/4] minor fix --- .../org/apache/maven/plugins/help/EffectivePomMojoTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java index c2f7ac3c..03924248 100644 --- a/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java @@ -34,6 +34,7 @@ import org.apache.maven.plugin.MojoExecution; import org.apache.maven.project.MavenProject; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; @@ -80,6 +81,7 @@ void setup() throws IOException { mavenSession.getUserProperties().setProperty("outputPath", outputPath.toString()); } + @Test @InjectMojo(goal = "effective-pom") @MojoParameter(name = "output", value = "${outputPath}") void testExecuteDoesNotModifyProjectModel(EffectivePomMojo mojo) throws Exception {