elharo commented on code in PR #414:
URL: https://github.com/apache/maven-help-plugin/pull/414#discussion_r3835817540
##########
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();
Review Comment:
My question is more does this return a Cloneable object? What's the contract
on Model?
##########
src/test/java/org/apache/maven/plugins/help/EffectivePomMojoTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.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 MojoExecution mojoExecution;
+
+ @TempDir
+ private Path tempDir;
+
+ private final Model model = new Model();
+
+ private final Properties originalProperties = new Properties();
+
+ @BeforeEach
+ void setup() throws IOException {
+ originalProperties.setProperty("b.property", "b-value");
+ originalProperties.setProperty("a.property", "a-value");
+
+ model.setProperties(originalProperties);
+
+ when(project.getModel()).thenReturn(model);
+
+ Path 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.
Review Comment:
not really needed on test
--
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]