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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4ee91b1f Remove deprecated GeneratorUtils#toText (#1035)
4ee91b1f is described below

commit 4ee91b1f88c6ab02323be397f45e978ebc1064c0
Author: Matthias Bünger <[email protected]>
AuthorDate: Sun Nov 30 11:49:26 2025 +0100

    Remove deprecated GeneratorUtils#toText (#1035)
    
    In favor for HtmlToPlainTextConverter
---
 maven-plugin-tools-generators/pom.xml              |   5 +
 .../tools/plugin/generator/GeneratorUtils.java     |  41 -------
 .../tools/plugin/generator/GeneratorUtilsTest.java | 120 ---------------------
 .../generator/HtmlToPlainTextConverterTest.java    |  41 +++++++
 4 files changed, 46 insertions(+), 161 deletions(-)

diff --git a/maven-plugin-tools-generators/pom.xml 
b/maven-plugin-tools-generators/pom.xml
index 75d7d89c..e91907b3 100644
--- a/maven-plugin-tools-generators/pom.xml
+++ b/maven-plugin-tools-generators/pom.xml
@@ -110,6 +110,11 @@
       <artifactId>junit-jupiter-api</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-params</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
diff --git 
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
 
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
index ff27c17e..5a7fd89f 100644
--- 
a/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
+++ 
b/maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java
@@ -21,12 +21,9 @@ package org.apache.maven.tools.plugin.generator;
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.html.HTML;
 import javax.swing.text.html.HTMLEditorKit;
-import javax.swing.text.html.parser.ParserDelegator;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringReader;
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.HashMap;
@@ -266,44 +263,6 @@ public final class GeneratorUtils {
         return commentCleaned;
     }
 
-    /**
-     * Converts a HTML fragment as extracted from a javadoc comment to a plain 
text string. This method tries to retain
-     * as much of the text formatting as possible by means of the following 
transformations:
-     * <ul>
-     * <li>List items are converted to leading tabs (U+0009), followed by the 
item number/bullet, another tab and
-     * finally the item contents. Each tab denotes an increase of 
indentation.</li>
-     * <li>Flow breaking elements as well as literal line terminators in 
preformatted text are converted to a newline
-     * (U+000A) to denote a mandatory line break.</li>
-     * <li>Consecutive spaces and line terminators from character data outside 
of preformatted text will be normalized
-     * to a single space. The resulting space denotes a possible point for 
line wrapping.</li>
-     * <li>Each space in preformatted text will be converted to a non-breaking 
space (U+00A0).</li>
-     * </ul>
-     *
-     * @param html The HTML fragment to convert to plain text, may be 
<code>null</code>.
-     * @return A string with HTML tags converted into pure text, never 
<code>null</code>.
-     * @since 2.4.3
-     * @deprecated Replaced by {@link HtmlToPlainTextConverter}
-     */
-    @Deprecated
-    public static String toText(String html) {
-        if (html == null || html.isEmpty()) {
-            return "";
-        }
-
-        final StringBuilder sb = new StringBuilder();
-
-        HTMLEditorKit.Parser parser = new ParserDelegator();
-        HTMLEditorKit.ParserCallback htmlCallback = new MojoParserCallback(sb);
-
-        try {
-            parser.parse(new StringReader(makeHtmlValid(html)), htmlCallback, 
true);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-
-        return sb.toString().replace('\"', '\''); // for CDATA
-    }
-
     /**
      * ParserCallback implementation.
      */
diff --git 
a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
 
b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
index d0e10c8e..179249c8 100644
--- 
a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
+++ 
b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java
@@ -62,126 +62,6 @@ class GeneratorUtilsTest {
         assertEquals(pattern, output);
     }
 
-    /*
-        @Test
-        void testMakeHtmlValid()
-        {
-            String javadoc = null;
-            assertEquals( "", GeneratorUtils.makeHtmlValid( javadoc ) );
-            javadoc = "";
-            assertEquals( "", GeneratorUtils.makeHtmlValid( javadoc ) );
-
-            // true HTML
-            javadoc = "Generates <i>something</i> for the project.";
-            assertEquals( "Generates <i>something</i> for the project.", 
GeneratorUtils.makeHtmlValid( javadoc ) );
-
-            // wrong HTML
-            javadoc = "Generates <i>something</i> <b> for the project.";
-            assertEquals( "Generates <i>something</i> <b> for the 
project.</b>", GeneratorUtils.makeHtmlValid( javadoc ) );
-
-            // wrong XHTML
-            javadoc = "Line1<br>Line2";
-            assertEquals( "Line1<br/>Line2", GeneratorUtils.makeHtmlValid( 
javadoc ).replaceAll( "\\s", "" ) );
-
-            // special characters
-            javadoc = "& &amp; < > \u00A0";
-            assertEquals( "&amp; &amp; &lt; &gt; \u00A0", 
GeneratorUtils.makeHtmlValid( javadoc ) );
-
-            // non ASCII characters
-            javadoc = "\u00E4 \u00F6 \u00FC \u00DF";
-            assertEquals( javadoc, GeneratorUtils.makeHtmlValid( javadoc ) );
-
-            // non Latin1 characters
-            javadoc = "\u0130 \u03A3 \u05D0 \u06DE";
-            assertEquals( javadoc, GeneratorUtils.makeHtmlValid( javadoc ) );
-        }
-    */
-    /*
-    @Test
-    void testDecodeJavadocTags()
-    {
-        String javadoc = null;
-        assertEquals( "", GeneratorUtils.decodeJavadocTags( javadoc ) );
-
-        javadoc = "";
-        assertEquals( "", GeneratorUtils.decodeJavadocTags( javadoc ) );
-
-        javadoc = "{@code text}";
-        assertEquals( "<code>text</code>", GeneratorUtils.decodeJavadocTags( 
javadoc ) );
-
-        javadoc = "{@code <A&B>}";
-        assertEquals( "<code>&lt;A&amp;B&gt;</code>", 
GeneratorUtils.decodeJavadocTags( javadoc ) );
-
-        javadoc = "{@literal text}";
-        assertEquals( "text", GeneratorUtils.decodeJavadocTags( javadoc ) );
-
-        javadoc = "{@literal text}  {@literal text}";
-        assertEquals( "text  text", GeneratorUtils.decodeJavadocTags( javadoc 
) );
-
-        javadoc = "{@literal <A&B>}";
-        assertEquals( "&lt;A&amp;B&gt;", GeneratorUtils.decodeJavadocTags( 
javadoc ) );
-
-        javadoc = "{@link Class}";
-        assertEquals( "<code>Class</code>", GeneratorUtils.decodeJavadocTags( 
javadoc ) );
-
-        javadoc = "{@linkplain Class}";
-        assertEquals( "Class", GeneratorUtils.decodeJavadocTags( javadoc ) );
-
-        javadoc = "{@linkplain #field}";
-        assertEquals( "field", GeneratorUtils.decodeJavadocTags( javadoc ) );
-
-        javadoc = "{@linkplain Class#field}";
-        assertEquals( "Class.field", GeneratorUtils.decodeJavadocTags( javadoc 
) );
-
-        javadoc = "{@linkplain #method()}";
-        assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) 
);
-
-        javadoc = "{@linkplain #method(Object arg)}";
-        assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) 
);
-
-        javadoc = "{@linkplain #method(Object, String)}";
-        assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) 
);
-
-        javadoc = "{@linkplain #method(Object, String) label}";
-        assertEquals( "label", GeneratorUtils.decodeJavadocTags( javadoc ) );
-
-        javadoc = "{@linkplain Class#method(Object, String)}";
-        assertEquals( "Class.method()", GeneratorUtils.decodeJavadocTags( 
javadoc ) );
-
-        javadoc = "{@linkplain Class#method(Object, String) label}";
-        assertEquals( "label", GeneratorUtils.decodeJavadocTags( javadoc ) );
-    }*/
-
-    @Test
-    void testToText() throws Exception {
-        String javadoc = null;
-        assertEquals("", GeneratorUtils.toText(javadoc));
-        javadoc = "";
-        assertEquals("", GeneratorUtils.toText(javadoc));
-
-        // line breaks
-        javadoc = "Line1\nLine2";
-        assertEquals("Line1 Line2", GeneratorUtils.toText(javadoc));
-        javadoc = "Line1\rLine2";
-        assertEquals("Line1 Line2", GeneratorUtils.toText(javadoc));
-        javadoc = "Line1\r\nLine2";
-        assertEquals("Line1 Line2", GeneratorUtils.toText(javadoc));
-        javadoc = "Line1<br>Line2";
-        assertEquals("Line1\nLine2", GeneratorUtils.toText(javadoc));
-
-        // true HTML
-        javadoc = "Generates <i>something</i> for the project.";
-        assertEquals("Generates something for the project.", 
GeneratorUtils.toText(javadoc));
-
-        // wrong HTML
-        javadoc = "Generates <i>something</i> <b> for the project.";
-        assertEquals("Generates something for the project.", 
GeneratorUtils.toText(javadoc));
-
-        // javadoc inline tags
-        // javadoc = "Generates {@code something} for the project.";
-        // assertEquals( "Generates something for the project.", 
GeneratorUtils.toText( javadoc ) );
-    }
-
     @Test
     void testExcludeProvidedScopeFormComponentDependencies() {
 
diff --git 
a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/HtmlToPlainTextConverterTest.java
 
b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/HtmlToPlainTextConverterTest.java
index e7f037bc..2792d8d9 100644
--- 
a/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/HtmlToPlainTextConverterTest.java
+++ 
b/maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/HtmlToPlainTextConverterTest.java
@@ -18,7 +18,13 @@
  */
 package org.apache.maven.tools.plugin.generator;
 
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -63,6 +69,11 @@ class HtmlToPlainTextConverterTest {
         assertNull(converter.convert(null));
     }
 
+    @Test
+    void testBlankString() {
+        assertEquals("", converter.convert(""));
+    }
+
     @Test
     void testExplicitNewline() {
         String test =
@@ -73,4 +84,34 @@ class HtmlToPlainTextConverterTest {
                         + "and an inline link to foo",
                 converter.convert(test));
     }
+
+    @ParameterizedTest(name = "{0} to {1}") // With JUnit 6.0.0 the 
non-printable chars will be kept in display, see
+    // 
https://docs.junit.org/current/user-guide/#writing-tests-parameterized-tests-display-names-quoted-text
+    @MethodSource("provideConvertParamsBreakLines")
+    @DisplayName("Should convert from")
+    void testBreakLines(String javadoc, String expected) {
+        assertEquals(expected, converter.convert(javadoc));
+    }
+
+    private static Stream<Arguments> provideConvertParamsBreakLines() {
+        return Stream.of(
+                Arguments.of("Line1\nLine2", "Line1 Line2"),
+                Arguments.of("Line1\rLine2", "Line1 Line2"),
+                Arguments.of("Line1\r\nLine2", "Line1 Line2"),
+                Arguments.of("Line1<br>Line2", "Line1\nLine2"));
+    }
+
+    @Test
+    void testTrueHtml() {
+        assertEquals(
+                "Generates something for the project.",
+                converter.convert("Generates <i>something</i> for the 
project."));
+    }
+
+    @Test
+    void testWrongHtml() {
+        assertEquals(
+                "Generates something for the project.",
+                converter.convert("Generates <i>something</i> <b>for the 
project."));
+    }
 }

Reply via email to