diff --git a/src/it/projects/effective-pom-artifact/pom.xml b/src/it/projects/effective-pom-artifact/pom.xml index 8fc07074..95652047 100644 --- a/src/it/projects/effective-pom-artifact/pom.xml +++ b/src/it/projects/effective-pom-artifact/pom.xml @@ -27,4 +27,16 @@ under the License. 1.0-SNAPSHOT https://issues.apache.org/jira/browse/MPH-106 + + + + org.apache.maven.plugins + maven-help-plugin + @project.version@ + + org.apache.maven.plugins:maven-help-plugin:@project.version@ + + + + diff --git a/src/it/projects/effective-pom-artifact/test.properties b/src/it/projects/effective-pom-artifact/test.properties index 037f045e..ba5a1eec 100644 --- a/src/it/projects/effective-pom-artifact/test.properties +++ b/src/it/projects/effective-pom-artifact/test.properties @@ -16,4 +16,3 @@ # under the License. output = result.txt -artifact = org.apache.maven.plugins:maven-help-plugin diff --git a/src/it/projects/effective-pom-multimodule-artifact/pom.xml b/src/it/projects/effective-pom-multimodule-artifact/pom.xml index bf048a59..0daeb985 100644 --- a/src/it/projects/effective-pom-multimodule-artifact/pom.xml +++ b/src/it/projects/effective-pom-multimodule-artifact/pom.xml @@ -36,6 +36,14 @@ under the License. + + org.apache.maven.plugins + maven-help-plugin + @project.version@ + + org.apache.maven.plugins:maven-help-plugin:@project.version@ + + diff --git a/src/it/projects/effective-pom-multimodule-artifact/test.properties b/src/it/projects/effective-pom-multimodule-artifact/test.properties index 037f045e..ba5a1eec 100644 --- a/src/it/projects/effective-pom-multimodule-artifact/test.properties +++ b/src/it/projects/effective-pom-multimodule-artifact/test.properties @@ -16,4 +16,3 @@ # under the License. output = result.txt -artifact = org.apache.maven.plugins:maven-help-plugin diff --git a/src/it/projects/evaluate-artifact-with-expression-with-output/pom.xml b/src/it/projects/evaluate-artifact-with-expression-with-output/pom.xml index 9ee377e0..5f0d37c2 100644 --- a/src/it/projects/evaluate-artifact-with-expression-with-output/pom.xml +++ b/src/it/projects/evaluate-artifact-with-expression-with-output/pom.xml @@ -41,6 +41,9 @@ under the License. evaluate package + + org.apache.maven.plugins:maven-help-plugin:@project.version@ + diff --git a/src/it/projects/evaluate-artifact-with-expression-with-output/test.properties b/src/it/projects/evaluate-artifact-with-expression-with-output/test.properties index 632b331f..5f9820fd 100644 --- a/src/it/projects/evaluate-artifact-with-expression-with-output/test.properties +++ b/src/it/projects/evaluate-artifact-with-expression-with-output/test.properties @@ -17,4 +17,3 @@ expression = project.name output = result.txt -artifact = org.apache.maven.plugins:maven-help-plugin diff --git a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java index 163a37f8..3b1c3dbd 100644 --- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java @@ -371,7 +371,7 @@ private XStream getXStream() { /** {@inheritDoc} */ @Override public boolean canConvert(Class type) { - return Properties.class == type; + return Properties.class.isAssignableFrom(type); } /** {@inheritDoc} */ diff --git a/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java b/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java index 5fe15de0..994ff260 100644 --- a/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java @@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.util.Properties; import org.apache.maven.api.di.Provides; import org.apache.maven.api.plugin.testing.InjectMojo; @@ -37,6 +38,7 @@ 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.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -184,4 +186,45 @@ void testEvaluateQuiteModeWithOutputOnStdout(EvaluateMojo mojo) throws Exception assertEquals("org.apache.maven.its.help", stdResult); verify(log, never()).warn(anyString()); } + + /** + * Tests that a {@code Properties} subclass (like {@code SortedProperties}) is correctly serialized + * by XStream without falling through to {@code SerializableConverter} which would attempt + * reflective access to {@code java.util.Hashtable.table} (forbidden on Java 18+). + * @throws Exception in case of errors. + */ + @Test + @ResourceLock(Resources.SYSTEM_OUT) + @InjectMojo(goal = "evaluate") + @MojoParameter(name = "forceStdout", value = "true") + @MojoParameter(name = "expression", value = "project.properties") + void testEvaluateWithPropertiesSubclass(EvaluateMojo mojo) throws Exception { + Properties sortedProperties = new AbstractEffectiveMojo.SortedProperties(); + sortedProperties.setProperty("key1", "value1"); + sortedProperties.setProperty("key2", "value2"); + + when(expressionEvaluator.evaluate(anyString())).thenReturn(sortedProperties); + when(log.isInfoEnabled()).thenReturn(false); + + setVariableValueToObject(mojo, "evaluator", expressionEvaluator); + + PrintStream saveOut = System.out; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos)); + + try { + mojo.execute(); + } finally { + System.setOut(saveOut); + baos.close(); + } + + String stdResult = baos.toString(); + // Verify serialization succeeded without falling through to SerializableConverter + assertTrue(stdResult.contains("key1")); + assertTrue(stdResult.contains("value1")); + assertTrue(stdResult.contains("key2")); + assertTrue(stdResult.contains("value2")); + verify(log, never()).warn(anyString()); + } }