Skip to content

Commit 4ee91b1

Browse files
authored
Remove deprecated GeneratorUtils#toText (#1035)
In favor for HtmlToPlainTextConverter
1 parent 2ed4ba2 commit 4ee91b1

4 files changed

Lines changed: 46 additions & 161 deletions

File tree

maven-plugin-tools-generators/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
<artifactId>junit-jupiter-api</artifactId>
111111
<scope>test</scope>
112112
</dependency>
113+
<dependency>
114+
<groupId>org.junit.jupiter</groupId>
115+
<artifactId>junit-jupiter-params</artifactId>
116+
<scope>test</scope>
117+
</dependency>
113118
<dependency>
114119
<groupId>org.slf4j</groupId>
115120
<artifactId>slf4j-simple</artifactId>

maven-plugin-tools-generators/src/main/java/org/apache/maven/tools/plugin/generator/GeneratorUtils.java

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
import javax.swing.text.MutableAttributeSet;
2222
import javax.swing.text.html.HTML;
2323
import javax.swing.text.html.HTMLEditorKit;
24-
import javax.swing.text.html.parser.ParserDelegator;
2524

2625
import java.io.ByteArrayInputStream;
2726
import java.io.ByteArrayOutputStream;
28-
import java.io.IOException;
29-
import java.io.StringReader;
3027
import java.nio.charset.StandardCharsets;
3128
import java.util.Collection;
3229
import java.util.HashMap;
@@ -266,44 +263,6 @@ public static String makeHtmlValid(String description) {
266263
return commentCleaned;
267264
}
268265

269-
/**
270-
* Converts a HTML fragment as extracted from a javadoc comment to a plain text string. This method tries to retain
271-
* as much of the text formatting as possible by means of the following transformations:
272-
* <ul>
273-
* <li>List items are converted to leading tabs (U+0009), followed by the item number/bullet, another tab and
274-
* finally the item contents. Each tab denotes an increase of indentation.</li>
275-
* <li>Flow breaking elements as well as literal line terminators in preformatted text are converted to a newline
276-
* (U+000A) to denote a mandatory line break.</li>
277-
* <li>Consecutive spaces and line terminators from character data outside of preformatted text will be normalized
278-
* to a single space. The resulting space denotes a possible point for line wrapping.</li>
279-
* <li>Each space in preformatted text will be converted to a non-breaking space (U+00A0).</li>
280-
* </ul>
281-
*
282-
* @param html The HTML fragment to convert to plain text, may be <code>null</code>.
283-
* @return A string with HTML tags converted into pure text, never <code>null</code>.
284-
* @since 2.4.3
285-
* @deprecated Replaced by {@link HtmlToPlainTextConverter}
286-
*/
287-
@Deprecated
288-
public static String toText(String html) {
289-
if (html == null || html.isEmpty()) {
290-
return "";
291-
}
292-
293-
final StringBuilder sb = new StringBuilder();
294-
295-
HTMLEditorKit.Parser parser = new ParserDelegator();
296-
HTMLEditorKit.ParserCallback htmlCallback = new MojoParserCallback(sb);
297-
298-
try {
299-
parser.parse(new StringReader(makeHtmlValid(html)), htmlCallback, true);
300-
} catch (IOException e) {
301-
throw new RuntimeException(e);
302-
}
303-
304-
return sb.toString().replace('\"', '\''); // for CDATA
305-
}
306-
307266
/**
308267
* ParserCallback implementation.
309268
*/

maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/GeneratorUtilsTest.java

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -62,126 +62,6 @@ void testShouldWriteDependencies() throws Exception {
6262
assertEquals(pattern, output);
6363
}
6464

65-
/*
66-
@Test
67-
void testMakeHtmlValid()
68-
{
69-
String javadoc = null;
70-
assertEquals( "", GeneratorUtils.makeHtmlValid( javadoc ) );
71-
javadoc = "";
72-
assertEquals( "", GeneratorUtils.makeHtmlValid( javadoc ) );
73-
74-
// true HTML
75-
javadoc = "Generates <i>something</i> for the project.";
76-
assertEquals( "Generates <i>something</i> for the project.", GeneratorUtils.makeHtmlValid( javadoc ) );
77-
78-
// wrong HTML
79-
javadoc = "Generates <i>something</i> <b> for the project.";
80-
assertEquals( "Generates <i>something</i> <b> for the project.</b>", GeneratorUtils.makeHtmlValid( javadoc ) );
81-
82-
// wrong XHTML
83-
javadoc = "Line1<br>Line2";
84-
assertEquals( "Line1<br/>Line2", GeneratorUtils.makeHtmlValid( javadoc ).replaceAll( "\\s", "" ) );
85-
86-
// special characters
87-
javadoc = "& &amp; < > \u00A0";
88-
assertEquals( "&amp; &amp; &lt; &gt; \u00A0", GeneratorUtils.makeHtmlValid( javadoc ) );
89-
90-
// non ASCII characters
91-
javadoc = "\u00E4 \u00F6 \u00FC \u00DF";
92-
assertEquals( javadoc, GeneratorUtils.makeHtmlValid( javadoc ) );
93-
94-
// non Latin1 characters
95-
javadoc = "\u0130 \u03A3 \u05D0 \u06DE";
96-
assertEquals( javadoc, GeneratorUtils.makeHtmlValid( javadoc ) );
97-
}
98-
*/
99-
/*
100-
@Test
101-
void testDecodeJavadocTags()
102-
{
103-
String javadoc = null;
104-
assertEquals( "", GeneratorUtils.decodeJavadocTags( javadoc ) );
105-
106-
javadoc = "";
107-
assertEquals( "", GeneratorUtils.decodeJavadocTags( javadoc ) );
108-
109-
javadoc = "{@code text}";
110-
assertEquals( "<code>text</code>", GeneratorUtils.decodeJavadocTags( javadoc ) );
111-
112-
javadoc = "{@code <A&B>}";
113-
assertEquals( "<code>&lt;A&amp;B&gt;</code>", GeneratorUtils.decodeJavadocTags( javadoc ) );
114-
115-
javadoc = "{@literal text}";
116-
assertEquals( "text", GeneratorUtils.decodeJavadocTags( javadoc ) );
117-
118-
javadoc = "{@literal text} {@literal text}";
119-
assertEquals( "text text", GeneratorUtils.decodeJavadocTags( javadoc ) );
120-
121-
javadoc = "{@literal <A&B>}";
122-
assertEquals( "&lt;A&amp;B&gt;", GeneratorUtils.decodeJavadocTags( javadoc ) );
123-
124-
javadoc = "{@link Class}";
125-
assertEquals( "<code>Class</code>", GeneratorUtils.decodeJavadocTags( javadoc ) );
126-
127-
javadoc = "{@linkplain Class}";
128-
assertEquals( "Class", GeneratorUtils.decodeJavadocTags( javadoc ) );
129-
130-
javadoc = "{@linkplain #field}";
131-
assertEquals( "field", GeneratorUtils.decodeJavadocTags( javadoc ) );
132-
133-
javadoc = "{@linkplain Class#field}";
134-
assertEquals( "Class.field", GeneratorUtils.decodeJavadocTags( javadoc ) );
135-
136-
javadoc = "{@linkplain #method()}";
137-
assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) );
138-
139-
javadoc = "{@linkplain #method(Object arg)}";
140-
assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) );
141-
142-
javadoc = "{@linkplain #method(Object, String)}";
143-
assertEquals( "method()", GeneratorUtils.decodeJavadocTags( javadoc ) );
144-
145-
javadoc = "{@linkplain #method(Object, String) label}";
146-
assertEquals( "label", GeneratorUtils.decodeJavadocTags( javadoc ) );
147-
148-
javadoc = "{@linkplain Class#method(Object, String)}";
149-
assertEquals( "Class.method()", GeneratorUtils.decodeJavadocTags( javadoc ) );
150-
151-
javadoc = "{@linkplain Class#method(Object, String) label}";
152-
assertEquals( "label", GeneratorUtils.decodeJavadocTags( javadoc ) );
153-
}*/
154-
155-
@Test
156-
void testToText() throws Exception {
157-
String javadoc = null;
158-
assertEquals("", GeneratorUtils.toText(javadoc));
159-
javadoc = "";
160-
assertEquals("", GeneratorUtils.toText(javadoc));
161-
162-
// line breaks
163-
javadoc = "Line1\nLine2";
164-
assertEquals("Line1 Line2", GeneratorUtils.toText(javadoc));
165-
javadoc = "Line1\rLine2";
166-
assertEquals("Line1 Line2", GeneratorUtils.toText(javadoc));
167-
javadoc = "Line1\r\nLine2";
168-
assertEquals("Line1 Line2", GeneratorUtils.toText(javadoc));
169-
javadoc = "Line1<br>Line2";
170-
assertEquals("Line1\nLine2", GeneratorUtils.toText(javadoc));
171-
172-
// true HTML
173-
javadoc = "Generates <i>something</i> for the project.";
174-
assertEquals("Generates something for the project.", GeneratorUtils.toText(javadoc));
175-
176-
// wrong HTML
177-
javadoc = "Generates <i>something</i> <b> for the project.";
178-
assertEquals("Generates something for the project.", GeneratorUtils.toText(javadoc));
179-
180-
// javadoc inline tags
181-
// javadoc = "Generates {@code something} for the project.";
182-
// assertEquals( "Generates something for the project.", GeneratorUtils.toText( javadoc ) );
183-
}
184-
18565
@Test
18666
void testExcludeProvidedScopeFormComponentDependencies() {
18767

maven-plugin-tools-generators/src/test/java/org/apache/maven/tools/plugin/generator/HtmlToPlainTextConverterTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818
*/
1919
package org.apache.maven.tools.plugin.generator;
2020

21+
import java.util.stream.Stream;
22+
23+
import org.junit.jupiter.api.DisplayName;
2124
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.params.ParameterizedTest;
26+
import org.junit.jupiter.params.provider.Arguments;
27+
import org.junit.jupiter.params.provider.MethodSource;
2228

2329
import static org.junit.jupiter.api.Assertions.assertEquals;
2430
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -63,6 +69,11 @@ void testNullValue() {
6369
assertNull(converter.convert(null));
6470
}
6571

72+
@Test
73+
void testBlankString() {
74+
assertEquals("", converter.convert(""));
75+
}
76+
6677
@Test
6778
void testExplicitNewline() {
6879
String test =
@@ -73,4 +84,34 @@ void testExplicitNewline() {
7384
+ "and an inline link to foo",
7485
converter.convert(test));
7586
}
87+
88+
@ParameterizedTest(name = "{0} to {1}") // With JUnit 6.0.0 the non-printable chars will be kept in display, see
89+
// https://docs.junit.org/current/user-guide/#writing-tests-parameterized-tests-display-names-quoted-text
90+
@MethodSource("provideConvertParamsBreakLines")
91+
@DisplayName("Should convert from")
92+
void testBreakLines(String javadoc, String expected) {
93+
assertEquals(expected, converter.convert(javadoc));
94+
}
95+
96+
private static Stream<Arguments> provideConvertParamsBreakLines() {
97+
return Stream.of(
98+
Arguments.of("Line1\nLine2", "Line1 Line2"),
99+
Arguments.of("Line1\rLine2", "Line1 Line2"),
100+
Arguments.of("Line1\r\nLine2", "Line1 Line2"),
101+
Arguments.of("Line1<br>Line2", "Line1\nLine2"));
102+
}
103+
104+
@Test
105+
void testTrueHtml() {
106+
assertEquals(
107+
"Generates something for the project.",
108+
converter.convert("Generates <i>something</i> for the project."));
109+
}
110+
111+
@Test
112+
void testWrongHtml() {
113+
assertEquals(
114+
"Generates something for the project.",
115+
converter.convert("Generates <i>something</i> <b>for the project."));
116+
}
76117
}

0 commit comments

Comments
 (0)