From 3b29d3892292a591f1e09b16a216c6798d9e157c Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 12 Dec 2025 09:25:34 +0100 Subject: [PATCH 1/9] [MPH-219] Make AbstractEffectiveMojo a static util class --- ...tiveMojo.java => EffectiveMojoWriter.java} | 34 +++++++++---------- .../maven/plugins/help/EffectivePomMojo.java | 9 +++-- .../plugins/help/EffectiveSettingsMojo.java | 9 +++-- 3 files changed, 30 insertions(+), 22 deletions(-) rename src/main/java/org/apache/maven/plugins/help/{AbstractEffectiveMojo.java => EffectiveMojoWriter.java} (83%) diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java similarity index 83% rename from src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java rename to src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java index 4bb3099..a10fa9c 100644 --- a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java @@ -33,10 +33,8 @@ import java.util.Properties; import java.util.Set; -import org.apache.maven.project.ProjectBuilder; import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; -import org.eclipse.aether.RepositorySystem; import org.jdom2.Document; import org.jdom2.JDOMException; import org.jdom2.input.SAXBuilder; @@ -49,21 +47,17 @@ * @author Vincent Siveton * @since 2.1 */ -public abstract class AbstractEffectiveMojo extends AbstractHelpMojo { - - protected AbstractEffectiveMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { - super(projectBuilder, repositorySystem); - } +public final class EffectiveMojoWriter { /** * Utility method to write an XML content to a given file. * - * @param output is the wanted output file. + * @param output is the wanted output file. * @param content contains the XML content to be written to the file. * @throws IOException if any * @see AbstractHelpMojo#writeFile(File, String) if encoding is null. */ - protected static void writeXmlFile(File output, String content) throws IOException { + public static void writeXmlFile(File output, String content) throws IOException { if (output == null) { return; } @@ -79,7 +73,7 @@ protected static void writeXmlFile(File output, String content) throws IOExcepti * * @param writer not null */ - protected static void writeHeader(XMLWriter writer) { + public static void writeHeader(XMLWriter writer) { XmlWriterUtil.writeCommentLineBreak(writer); XmlWriterUtil.writeComment(writer, " "); XmlWriterUtil.writeComment(writer, "Generated by Maven Help Plugin"); @@ -91,10 +85,10 @@ protected static void writeHeader(XMLWriter writer) { /** * Write comments in a normalize way. * - * @param writer not null + * @param writer not null * @param comment not null */ - protected static void writeComment(XMLWriter writer, String comment) { + public static void writeComment(XMLWriter writer, String comment) { XmlWriterUtil.writeCommentLineBreak(writer); XmlWriterUtil.writeComment(writer, " "); XmlWriterUtil.writeComment(writer, comment); @@ -103,12 +97,12 @@ protected static void writeComment(XMLWriter writer, String comment) { } /** - * @param effectiveModel not null - * @param encoding not null + * @param effectiveModel not null + * @param encoding not null * @param omitDeclaration whether the XML declaration should be omitted from the effective pom * @return pretty format of the xml or the original {@code effectiveModel} if an error occurred. */ - protected static String prettyFormat(String effectiveModel, String encoding, boolean omitDeclaration) { + public static String prettyFormat(String effectiveModel, String encoding, boolean omitDeclaration) { SAXBuilder builder = new SAXBuilder(); builder.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); builder.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); @@ -135,11 +129,15 @@ protected static String prettyFormat(String effectiveModel, String encoding, boo /** * Properties which provides a sorted keySet(). */ - protected static class SortedProperties extends Properties { - /** serialVersionUID */ + public static class SortedProperties extends Properties { + /** + * serialVersionUID + */ static final long serialVersionUID = -8985316072702233744L; - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @SuppressWarnings({"rawtypes", "unchecked"}) @Override public Set keySet() { 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 4fa115c..2ed3b11 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -45,6 +45,11 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.eclipse.aether.RepositorySystem; +import static org.apache.maven.plugins.help.EffectiveMojoWriter.prettyFormat; +import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeComment; +import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeHeader; +import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeXmlFile; + /** * Displays the effective POM as an XML for this build, with the active profiles factored in, or a specified artifact. * If verbose, a comment is added to each XML element describing the origin of the line. @@ -52,7 +57,7 @@ * @since 2.0 */ @Mojo(name = "effective-pom", aggregator = true) -public class EffectivePomMojo extends AbstractEffectiveMojo { +public class EffectivePomMojo extends AbstractHelpMojo { // ---------------------------------------------------------------------- // Mojo parameters // ---------------------------------------------------------------------- @@ -208,7 +213,7 @@ private void writeEffectivePom(MavenProject project, XMLWriter writer) throws Mo * @param pom not null */ private static void cleanModel(Model pom) { - Properties properties = new SortedProperties(); + Properties properties = new EffectiveMojoWriter.SortedProperties(); properties.putAll(pom.getProperties()); pom.setProperties(properties); } diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java index cec9a80..a774d82 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java @@ -44,6 +44,11 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.eclipse.aether.RepositorySystem; +import static org.apache.maven.plugins.help.EffectiveMojoWriter.prettyFormat; +import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeComment; +import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeHeader; +import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeXmlFile; + /** * Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance * of the global settings into the user-level settings. @@ -51,7 +56,7 @@ * @since 2.0 */ @Mojo(name = "effective-settings", requiresProject = false) -public class EffectiveSettingsMojo extends AbstractEffectiveMojo { +public class EffectiveSettingsMojo extends AbstractHelpMojo { // ---------------------------------------------------------------------- // Mojo parameters // ---------------------------------------------------------------------- @@ -232,7 +237,7 @@ private static void writeEffectiveSettings(Settings settings, XMLWriter writer) private static void cleanSettings(Settings settings) { List profiles = settings.getProfiles(); for (Profile profile : profiles) { - Properties properties = new SortedProperties(); + Properties properties = new EffectiveMojoWriter.SortedProperties(); properties.putAll(profile.getProperties()); profile.setProperties(properties); } From ece82a88fb2e6e4178a5a08b6f678fe17808e7a2 Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 12 Dec 2025 09:41:42 +0100 Subject: [PATCH 2/9] [MPH-219] Remove identical method --- .../plugins/help/EffectiveMojoWriter.java | 24 +------------------ .../maven/plugins/help/EffectivePomMojo.java | 3 +-- .../plugins/help/EffectiveSettingsMojo.java | 3 +-- 3 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java index a10fa9c..d527b07 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java @@ -20,12 +20,9 @@ import javax.xml.XMLConstants; -import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; -import java.io.Writer; -import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; @@ -42,32 +39,13 @@ import org.jdom2.output.XMLOutputter; /** - * Base class with common utilities to write effective Pom/settings. + * Utility class with common utilities to write effective Pom/settings. * * @author Vincent Siveton * @since 2.1 */ public final class EffectiveMojoWriter { - /** - * Utility method to write an XML content to a given file. - * - * @param output is the wanted output file. - * @param content contains the XML content to be written to the file. - * @throws IOException if any - * @see AbstractHelpMojo#writeFile(File, String) if encoding is null. - */ - public static void writeXmlFile(File output, String content) throws IOException { - if (output == null) { - return; - } - - output.getParentFile().mkdirs(); - try (Writer out = Files.newBufferedWriter(output.toPath())) { - out.write(content); - } - } - /** * Write comments in the Effective POM/settings header. * 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 2ed3b11..3e260ab 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -48,7 +48,6 @@ import static org.apache.maven.plugins.help.EffectiveMojoWriter.prettyFormat; import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeComment; import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeHeader; -import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeXmlFile; /** * Displays the effective POM as an XML for this build, with the active profiles factored in, or a specified artifact. @@ -137,7 +136,7 @@ public void execute() throws MojoExecutionException { if (output != null) { try { - writeXmlFile(output, effectivePom); + writeFile(output, effectivePom); } catch (IOException e) { throw new MojoExecutionException("Cannot write effective-POM to output: " + output, e); } diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java index a774d82..d7b6de0 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java @@ -47,7 +47,6 @@ import static org.apache.maven.plugins.help.EffectiveMojoWriter.prettyFormat; import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeComment; import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeHeader; -import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeXmlFile; /** * Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance @@ -113,7 +112,7 @@ public void execute() throws MojoExecutionException { if (output != null) { try { - writeXmlFile(output, effectiveSettings); + writeFile(output, effectiveSettings); } catch (IOException e) { throw new MojoExecutionException("Cannot write effective-settings to output: " + output, e); } From 48e02e78d343cc426aff0042b37ccae1201706f3 Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 12 Dec 2025 09:57:08 +0100 Subject: [PATCH 3/9] [MPH-219] Make SortedProperties class interal --- ...tiveMojoWriter.java => EffectiveMojoUtils.java} | 14 ++++++++++++-- .../maven/plugins/help/EffectivePomMojo.java | 12 ++++++------ .../maven/plugins/help/EffectiveSettingsMojo.java | 10 +++++----- 3 files changed, 23 insertions(+), 13 deletions(-) rename src/main/java/org/apache/maven/plugins/help/{EffectiveMojoWriter.java => EffectiveMojoUtils.java} (91%) diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java similarity index 91% rename from src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java rename to src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java index d527b07..5a82b55 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveMojoWriter.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java @@ -44,7 +44,9 @@ * @author Vincent Siveton * @since 2.1 */ -public final class EffectiveMojoWriter { +public final class EffectiveMojoUtils { + + private EffectiveMojoUtils() {} /** * Write comments in the Effective POM/settings header. @@ -104,10 +106,18 @@ public static String prettyFormat(String effectiveModel, String encoding, boolea } } + public static Properties sortProperties(Properties properties) { + Properties sortedProperties = new SortedProperties(); + for (Object key : properties.keySet()) { + sortedProperties.put(key, properties.get(key)); + } + return sortedProperties; + } + /** * Properties which provides a sorted keySet(). */ - public static class SortedProperties extends Properties { + private static class SortedProperties extends Properties { /** * serialVersionUID */ 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 3e260ab..c3cbe83 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -45,9 +45,10 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.eclipse.aether.RepositorySystem; -import static org.apache.maven.plugins.help.EffectiveMojoWriter.prettyFormat; -import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeComment; -import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeHeader; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.prettyFormat; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.sortProperties; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeComment; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeHeader; /** * Displays the effective POM as an XML for this build, with the active profiles factored in, or a specified artifact. @@ -212,9 +213,8 @@ private void writeEffectivePom(MavenProject project, XMLWriter writer) throws Mo * @param pom not null */ private static void cleanModel(Model pom) { - Properties properties = new EffectiveMojoWriter.SortedProperties(); - properties.putAll(pom.getProperties()); - pom.setProperties(properties); + Properties sortedProperties = sortProperties(pom.getProperties()); + pom.setProperties(sortedProperties); } private static class InputLocationStringFormatter extends InputLocation.StringFormatter { diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java index d7b6de0..9240c69 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java @@ -44,9 +44,10 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.eclipse.aether.RepositorySystem; -import static org.apache.maven.plugins.help.EffectiveMojoWriter.prettyFormat; -import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeComment; -import static org.apache.maven.plugins.help.EffectiveMojoWriter.writeHeader; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.prettyFormat; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.sortProperties; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeComment; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeHeader; /** * Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance @@ -236,8 +237,7 @@ private static void writeEffectiveSettings(Settings settings, XMLWriter writer) private static void cleanSettings(Settings settings) { List profiles = settings.getProfiles(); for (Profile profile : profiles) { - Properties properties = new EffectiveMojoWriter.SortedProperties(); - properties.putAll(profile.getProperties()); + Properties properties = sortProperties(profile.getProperties()); profile.setProperties(properties); } } From a0f0d6853888787b9d304c3d98ac0bfa736263d6 Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 9 Jan 2026 11:08:43 +0100 Subject: [PATCH 4/9] [MPH-219] Add missing tests --- .../plugins/help/EffectiveMojoUtilsTest.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java diff --git a/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java b/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java new file mode 100644 index 0000000..881934d --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java @@ -0,0 +1,95 @@ +package org.apache.maven.plugins.help; + +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; +import org.codehaus.plexus.util.xml.XMLWriter; +import org.codehaus.plexus.util.xml.XmlWriterUtil; +import org.junit.jupiter.api.Test; + +import java.io.StringWriter; +import java.nio.charset.Charset; +import java.util.Properties; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class EffectiveMojoUtilsTest { + + private final StringWriter w = new StringWriter(); + private final String encoding = Charset.defaultCharset().displayName(); + private final XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null); + + + @Test + void writeHeader_shouldWriteHeaderComments() { + EffectiveMojoUtils.writeHeader(writer); + + assertEquals(String.format("\n", encoding) + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n", + w.toString()); + } + + @Test + void writeComment_shouldWriteGivenComment() { + EffectiveMojoUtils.writeComment(writer, "This is a comment"); + + assertEquals(String.format("\n", encoding) + + "\n" + + "\n" + + "\n" + + "\n" + + "\n", + w.toString()); + } + + @Test + void sortProperties_shouldSortProperties() { + final Properties props = new Properties(); + props.setProperty("z", "last"); + props.setProperty("a", "first"); + props.setProperty("g", "middle"); + + final Properties sortedProps = EffectiveMojoUtils.sortProperties(props); + + final Object[] sortedValues = sortedProps.values().toArray(); + assertEquals("first", sortedValues[0]); + assertEquals("middle", sortedValues[1]); + assertEquals("last", sortedValues[2]); + + final Object[] sortedKeys = sortedProps.keySet().toArray(); + assertEquals("a", sortedKeys[0]); + assertEquals("g", sortedKeys[1]); + assertEquals("z", sortedKeys[2]); + } + + @Test + void prettyFormat_shouldFormatXmlString() throws Exception { + final String xml = "value"; + + final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, false); + + assertEquals("\n" + + "\n" + + " \n" + + " value\n" + + " \n" + + "\n", prettyXml); + } + + @Test + void prettyFormat_shouldOmitDeclarationWhenSpecified() throws Exception { + final String xml = "value"; + + final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, true); + + assertEquals("\n" + + " \n" + + " value\n" + + " \n" + + "\n", prettyXml); + } +} \ No newline at end of file From ba221a8fe4654ab6a8a8dedcfb76d9e77028a491 Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 9 Jan 2026 11:24:08 +0100 Subject: [PATCH 5/9] [MPH-219] Test names should match format --- .../maven/plugins/help/EffectiveMojoUtilsTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java b/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java index 881934d..33a19c6 100644 --- a/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java +++ b/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java @@ -20,7 +20,7 @@ class EffectiveMojoUtilsTest { @Test - void writeHeader_shouldWriteHeaderComments() { + void writeHeaderShouldWriteHeaderComments() { EffectiveMojoUtils.writeHeader(writer); assertEquals(String.format("\n", encoding) + @@ -34,7 +34,7 @@ void writeHeader_shouldWriteHeaderComments() { } @Test - void writeComment_shouldWriteGivenComment() { + void writeCommentShouldWriteGivenComment() { EffectiveMojoUtils.writeComment(writer, "This is a comment"); assertEquals(String.format("\n", encoding) + @@ -47,7 +47,7 @@ void writeComment_shouldWriteGivenComment() { } @Test - void sortProperties_shouldSortProperties() { + void sortPropertiesShouldSortProperties() { final Properties props = new Properties(); props.setProperty("z", "last"); props.setProperty("a", "first"); @@ -67,7 +67,7 @@ void sortProperties_shouldSortProperties() { } @Test - void prettyFormat_shouldFormatXmlString() throws Exception { + void prettyFormatShouldFormatXmlString() { final String xml = "value"; final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, false); @@ -81,7 +81,7 @@ void prettyFormat_shouldFormatXmlString() throws Exception { } @Test - void prettyFormat_shouldOmitDeclarationWhenSpecified() throws Exception { + void prettyFormatShouldOmitDeclarationWhenSpecified() { final String xml = "value"; final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, true); From c3e66f3c1e0ee80b5867418deee54cfd80d2da72 Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 9 Jan 2026 13:09:43 +0100 Subject: [PATCH 6/9] [MPH-219] Automatic spotless apply after rebase with master --- .../plugins/help/EffectiveMojoUtilsTest.java | 81 ++++++++++++------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java b/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java index 33a19c6..9297c97 100644 --- a/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java +++ b/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java @@ -1,35 +1,54 @@ +/* + * 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.io.StringWriter; +import java.nio.charset.Charset; +import java.util.Properties; + import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.junit.jupiter.api.Test; -import java.io.StringWriter; -import java.nio.charset.Charset; -import java.util.Properties; - import static org.junit.jupiter.api.Assertions.assertEquals; class EffectiveMojoUtilsTest { private final StringWriter w = new StringWriter(); private final String encoding = Charset.defaultCharset().displayName(); - private final XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null); - + private final XMLWriter writer = new PrettyPrintXMLWriter( + w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null); @Test void writeHeaderShouldWriteHeaderComments() { EffectiveMojoUtils.writeHeader(writer); - assertEquals(String.format("\n", encoding) + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n", + assertEquals( + String.format("\n", encoding) + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n", w.toString()); } @@ -37,12 +56,13 @@ void writeHeaderShouldWriteHeaderComments() { void writeCommentShouldWriteGivenComment() { EffectiveMojoUtils.writeComment(writer, "This is a comment"); - assertEquals(String.format("\n", encoding) + - "\n" + - "\n" + - "\n" + - "\n" + - "\n", + assertEquals( + String.format("\n", encoding) + + "\n" + + "\n" + + "\n" + + "\n" + + "\n", w.toString()); } @@ -72,12 +92,13 @@ void prettyFormatShouldFormatXmlString() { final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, false); - assertEquals("\n" + - "\n" + - " \n" + - " value\n" + - " \n" + - "\n", prettyXml); + assertEquals( + "\n" + "\n" + + " \n" + + " value\n" + + " \n" + + "\n", + prettyXml); } @Test @@ -86,10 +107,8 @@ void prettyFormatShouldOmitDeclarationWhenSpecified() { final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, true); - assertEquals("\n" + - " \n" + - " value\n" + - " \n" + - "\n", prettyXml); + assertEquals( + "\n" + " \n" + " value\n" + " \n" + "\n", + prettyXml); } -} \ No newline at end of file +} From 8a2e360c82e450149ffb7b21eb04dc6497004862 Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 9 Jan 2026 13:35:02 +0100 Subject: [PATCH 7/9] [MPH-219] Make line seperator system independant --- .../plugins/help/EffectiveMojoUtilsTest.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java b/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java index 9297c97..9e8e897 100644 --- a/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java +++ b/src/test/java/org/apache/maven/plugins/help/EffectiveMojoUtilsTest.java @@ -28,6 +28,7 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.junit.jupiter.api.Test; +import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.assertEquals; class EffectiveMojoUtilsTest { @@ -42,13 +43,13 @@ void writeHeaderShouldWriteHeaderComments() { EffectiveMojoUtils.writeHeader(writer); assertEquals( - String.format("\n", encoding) - + "\n" - + "\n" - + "\n" - + "\n" - + "\n" - + "\n", + format("%n", encoding) + + format("%n") + + format("%n") + + format("%n") + + format("%n") + + format("%n") + + format("%n"), w.toString()); } @@ -57,12 +58,12 @@ void writeCommentShouldWriteGivenComment() { EffectiveMojoUtils.writeComment(writer, "This is a comment"); assertEquals( - String.format("\n", encoding) - + "\n" - + "\n" - + "\n" - + "\n" - + "\n", + format("%n", encoding) + + format("%n") + + format("%n") + + format("%n") + + format("%n") + + format("%n"), w.toString()); } @@ -93,11 +94,12 @@ void prettyFormatShouldFormatXmlString() { final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, false); assertEquals( - "\n" + "\n" - + " \n" - + " value\n" - + " \n" - + "\n", + format("%n", encoding) + + format("%n") + + format(" %n") + + format(" value%n") + + format(" %n") + + format("%n"), prettyXml); } @@ -108,7 +110,11 @@ void prettyFormatShouldOmitDeclarationWhenSpecified() { final String prettyXml = EffectiveMojoUtils.prettyFormat(xml, encoding, true); assertEquals( - "\n" + " \n" + " value\n" + " \n" + "\n", + format("%n") + + format(" %n") + + format(" value%n") + + format(" %n") + + format("%n"), prettyXml); } } From 042a98fabd9f880fa1753f0a3cd04d15c3c93689 Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 9 Jan 2026 15:32:51 +0100 Subject: [PATCH 8/9] [MPH-219] Revert changing public API, deprecate instead --- .../plugins/help/AbstractEffectiveMojo.java | 112 ++++++++++++++++++ .../plugins/help/EffectiveMojoUtils.java | 3 - .../maven/plugins/help/EffectivePomMojo.java | 9 +- .../plugins/help/EffectiveSettingsMojo.java | 9 +- 4 files changed, 116 insertions(+), 17 deletions(-) create mode 100644 src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java new file mode 100644 index 0000000..244bcdc --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.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 java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +import org.apache.maven.project.ProjectBuilder; +import org.codehaus.plexus.util.xml.XMLWriter; +import org.eclipse.aether.RepositorySystem; + +/** + * Base class with common utilities to write effective Pom/settings. + * + * @author Vincent Siveton + * @since 2.1 + * + * @deprecated use {@link EffectiveMojoUtils} instead + */ +@Deprecated +public abstract class AbstractEffectiveMojo extends AbstractHelpMojo { + + protected AbstractEffectiveMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { + super(projectBuilder, repositorySystem); + } + + /** + * Utility method to write an XML content to a given file. + * + * @param output is the wanted output file. + * @param content contains the XML content to be written to the file. + * @throws IOException if any + * @see AbstractHelpMojo#writeFile(File, String) if encoding is null. + */ + protected static void writeXmlFile(File output, String content) throws IOException { + writeFile(output, content); + } + + /** + * Write comments in the Effective POM/settings header. + * + * @param writer not null + */ + protected static void writeHeader(XMLWriter writer) { + EffectiveMojoUtils.writeHeader(writer); + } + + /** + * Write comments in a normalize way. + * + * @param writer not null + * @param comment not null + */ + protected static void writeComment(XMLWriter writer, String comment) { + EffectiveMojoUtils.writeComment(writer, comment); + } + + /** + * @param effectiveModel not null + * @param encoding not null + * @param omitDeclaration whether the XML declaration should be omitted from the effective pom + * @return pretty format of the xml or the original {@code effectiveModel} if an error occurred. + */ + protected static String prettyFormat(String effectiveModel, String encoding, boolean omitDeclaration) { + return EffectiveMojoUtils.prettyFormat(effectiveModel, encoding, omitDeclaration); + } + + /** + * Properties which provides a sorted keySet(). + */ + protected static class SortedProperties extends Properties { + /** serialVersionUID */ + static final long serialVersionUID = -8985316072702233744L; + + /** {@inheritDoc} */ + @SuppressWarnings({"rawtypes", "unchecked"}) + @Override + public Set keySet() { + Set keynames = super.keySet(); + List list = new ArrayList(keynames); + Collections.sort(list); + + return new LinkedHashSet<>(list); + } + + protected static Properties sortProperties(Properties properties) { + return EffectiveMojoUtils.sortProperties(properties); + } + } +} diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java index 5a82b55..570d2b2 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java @@ -40,9 +40,6 @@ /** * Utility class with common utilities to write effective Pom/settings. - * - * @author Vincent Siveton - * @since 2.1 */ public final class EffectiveMojoUtils { 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 c3cbe83..db14676 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -45,11 +45,6 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.eclipse.aether.RepositorySystem; -import static org.apache.maven.plugins.help.EffectiveMojoUtils.prettyFormat; -import static org.apache.maven.plugins.help.EffectiveMojoUtils.sortProperties; -import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeComment; -import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeHeader; - /** * Displays the effective POM as an XML for this build, with the active profiles factored in, or a specified artifact. * If verbose, a comment is added to each XML element describing the origin of the line. @@ -57,7 +52,7 @@ * @since 2.0 */ @Mojo(name = "effective-pom", aggregator = true) -public class EffectivePomMojo extends AbstractHelpMojo { +public class EffectivePomMojo extends AbstractEffectiveMojo { // ---------------------------------------------------------------------- // Mojo parameters // ---------------------------------------------------------------------- @@ -213,7 +208,7 @@ private void writeEffectivePom(MavenProject project, XMLWriter writer) throws Mo * @param pom not null */ private static void cleanModel(Model pom) { - Properties sortedProperties = sortProperties(pom.getProperties()); + Properties sortedProperties = SortedProperties.sortProperties(pom.getProperties()); pom.setProperties(sortedProperties); } diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java index 9240c69..7e99ecb 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java @@ -44,11 +44,6 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.eclipse.aether.RepositorySystem; -import static org.apache.maven.plugins.help.EffectiveMojoUtils.prettyFormat; -import static org.apache.maven.plugins.help.EffectiveMojoUtils.sortProperties; -import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeComment; -import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeHeader; - /** * Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance * of the global settings into the user-level settings. @@ -56,7 +51,7 @@ * @since 2.0 */ @Mojo(name = "effective-settings", requiresProject = false) -public class EffectiveSettingsMojo extends AbstractHelpMojo { +public class EffectiveSettingsMojo extends AbstractEffectiveMojo { // ---------------------------------------------------------------------- // Mojo parameters // ---------------------------------------------------------------------- @@ -237,7 +232,7 @@ private static void writeEffectiveSettings(Settings settings, XMLWriter writer) private static void cleanSettings(Settings settings) { List profiles = settings.getProfiles(); for (Profile profile : profiles) { - Properties properties = sortProperties(profile.getProperties()); + Properties properties = SortedProperties.sortProperties(profile.getProperties()); profile.setProperties(properties); } } From f5e23f4c7b7bcbd76bfa6924ce14b978732cc2b6 Mon Sep 17 00:00:00 2001 From: Giovanni van der Schelde Date: Fri, 9 Jan 2026 21:36:49 +0100 Subject: [PATCH 9/9] Revert "[MPH-219] Revert changing public API, deprecate instead" This reverts commit 042a98fabd9f880fa1753f0a3cd04d15c3c93689. --- .../plugins/help/AbstractEffectiveMojo.java | 112 ------------------ .../plugins/help/EffectiveMojoUtils.java | 3 + .../maven/plugins/help/EffectivePomMojo.java | 9 +- .../plugins/help/EffectiveSettingsMojo.java | 9 +- 4 files changed, 17 insertions(+), 116 deletions(-) delete mode 100644 src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java diff --git a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java b/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java deleted file mode 100644 index 244bcdc..0000000 --- a/src/main/java/org/apache/maven/plugins/help/AbstractEffectiveMojo.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -import org.apache.maven.project.ProjectBuilder; -import org.codehaus.plexus.util.xml.XMLWriter; -import org.eclipse.aether.RepositorySystem; - -/** - * Base class with common utilities to write effective Pom/settings. - * - * @author Vincent Siveton - * @since 2.1 - * - * @deprecated use {@link EffectiveMojoUtils} instead - */ -@Deprecated -public abstract class AbstractEffectiveMojo extends AbstractHelpMojo { - - protected AbstractEffectiveMojo(ProjectBuilder projectBuilder, RepositorySystem repositorySystem) { - super(projectBuilder, repositorySystem); - } - - /** - * Utility method to write an XML content to a given file. - * - * @param output is the wanted output file. - * @param content contains the XML content to be written to the file. - * @throws IOException if any - * @see AbstractHelpMojo#writeFile(File, String) if encoding is null. - */ - protected static void writeXmlFile(File output, String content) throws IOException { - writeFile(output, content); - } - - /** - * Write comments in the Effective POM/settings header. - * - * @param writer not null - */ - protected static void writeHeader(XMLWriter writer) { - EffectiveMojoUtils.writeHeader(writer); - } - - /** - * Write comments in a normalize way. - * - * @param writer not null - * @param comment not null - */ - protected static void writeComment(XMLWriter writer, String comment) { - EffectiveMojoUtils.writeComment(writer, comment); - } - - /** - * @param effectiveModel not null - * @param encoding not null - * @param omitDeclaration whether the XML declaration should be omitted from the effective pom - * @return pretty format of the xml or the original {@code effectiveModel} if an error occurred. - */ - protected static String prettyFormat(String effectiveModel, String encoding, boolean omitDeclaration) { - return EffectiveMojoUtils.prettyFormat(effectiveModel, encoding, omitDeclaration); - } - - /** - * Properties which provides a sorted keySet(). - */ - protected static class SortedProperties extends Properties { - /** serialVersionUID */ - static final long serialVersionUID = -8985316072702233744L; - - /** {@inheritDoc} */ - @SuppressWarnings({"rawtypes", "unchecked"}) - @Override - public Set keySet() { - Set keynames = super.keySet(); - List list = new ArrayList(keynames); - Collections.sort(list); - - return new LinkedHashSet<>(list); - } - - protected static Properties sortProperties(Properties properties) { - return EffectiveMojoUtils.sortProperties(properties); - } - } -} diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java index 570d2b2..5a82b55 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveMojoUtils.java @@ -40,6 +40,9 @@ /** * Utility class with common utilities to write effective Pom/settings. + * + * @author Vincent Siveton + * @since 2.1 */ public final class EffectiveMojoUtils { 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 db14676..c3cbe83 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -45,6 +45,11 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.eclipse.aether.RepositorySystem; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.prettyFormat; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.sortProperties; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeComment; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeHeader; + /** * Displays the effective POM as an XML for this build, with the active profiles factored in, or a specified artifact. * If verbose, a comment is added to each XML element describing the origin of the line. @@ -52,7 +57,7 @@ * @since 2.0 */ @Mojo(name = "effective-pom", aggregator = true) -public class EffectivePomMojo extends AbstractEffectiveMojo { +public class EffectivePomMojo extends AbstractHelpMojo { // ---------------------------------------------------------------------- // Mojo parameters // ---------------------------------------------------------------------- @@ -208,7 +213,7 @@ private void writeEffectivePom(MavenProject project, XMLWriter writer) throws Mo * @param pom not null */ private static void cleanModel(Model pom) { - Properties sortedProperties = SortedProperties.sortProperties(pom.getProperties()); + Properties sortedProperties = sortProperties(pom.getProperties()); pom.setProperties(sortedProperties); } diff --git a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java index 7e99ecb..9240c69 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectiveSettingsMojo.java @@ -44,6 +44,11 @@ import org.codehaus.plexus.util.xml.XmlWriterUtil; import org.eclipse.aether.RepositorySystem; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.prettyFormat; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.sortProperties; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeComment; +import static org.apache.maven.plugins.help.EffectiveMojoUtils.writeHeader; + /** * Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance * of the global settings into the user-level settings. @@ -51,7 +56,7 @@ * @since 2.0 */ @Mojo(name = "effective-settings", requiresProject = false) -public class EffectiveSettingsMojo extends AbstractEffectiveMojo { +public class EffectiveSettingsMojo extends AbstractHelpMojo { // ---------------------------------------------------------------------- // Mojo parameters // ---------------------------------------------------------------------- @@ -232,7 +237,7 @@ private static void writeEffectiveSettings(Settings settings, XMLWriter writer) private static void cleanSettings(Settings settings) { List profiles = settings.getProfiles(); for (Profile profile : profiles) { - Properties properties = SortedProperties.sortProperties(profile.getProperties()); + Properties properties = sortProperties(profile.getProperties()); profile.setProperties(properties); } }