From ada2d082058b21d44bb434123d4df317ae83b700 Mon Sep 17 00:00:00 2001
From: Guillaume Nodet
Date: Fri, 2 Feb 2024 09:45:41 +0100
Subject: [PATCH 1/2] Parse javadoc tags in xdoc generator (only @since is
supported atm)
---
modello-plugins/modello-plugin-xdoc/pom.xml | 5 +++
.../modello/plugin/xdoc/XdocGenerator.java | 34 ++++++++++++++-----
.../src/test/resources/html4.expected.xml | 7 ++--
.../src/test/resources/html4.mdo | 3 ++
4 files changed, 38 insertions(+), 11 deletions(-)
diff --git a/modello-plugins/modello-plugin-xdoc/pom.xml b/modello-plugins/modello-plugin-xdoc/pom.xml
index ae951d7fd..a6ff61b48 100644
--- a/modello-plugins/modello-plugin-xdoc/pom.xml
+++ b/modello-plugins/modello-plugin-xdoc/pom.xml
@@ -30,6 +30,11 @@
jsoup
1.17.2
+
+ com.github.chhorz
+ javadoc-parser
+ 0.3.1
+
org.xmlunit
xmlunit-core
diff --git a/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java b/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java
index 467094ac6..8cfa03ce3 100644
--- a/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java
+++ b/modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java
@@ -28,14 +28,14 @@
import java.io.File;
import java.io.IOException;
import java.io.Writer;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.Stack;
-
+import java.util.*;
+import java.util.stream.Collectors;
+
+import com.github.chhorz.javadoc.JavaDoc;
+import com.github.chhorz.javadoc.JavaDocParserBuilder;
+import com.github.chhorz.javadoc.OutputType;
+import com.github.chhorz.javadoc.tags.BlockTag;
+import com.github.chhorz.javadoc.tags.SinceTag;
import org.codehaus.modello.ModelloException;
import org.codehaus.modello.ModelloParameterConstants;
import org.codehaus.modello.ModelloRuntimeException;
@@ -688,8 +688,24 @@ private static void writeMarkupElement(XMLWriter w, String name, String markup)
* @return valid XML string
*/
private static String rewrite(String text) {
- Document document = Jsoup.parseBodyFragment(text);
+ JavaDoc javaDoc = JavaDocParserBuilder.withStandardJavadocTags()
+ .withOutputType(OutputType.HTML)
+ .build()
+ .parse(text);
+ String html = javaDoc.getDescription()
+ + javaDoc.getTags().stream()
+ .map(XdocGenerator::renderJavaDocTag)
+ .filter(Objects::nonNull)
+ .collect(Collectors.joining("\n", "\n", ""));
+ Document document = Jsoup.parseBodyFragment(html);
document.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
return document.body().html();
}
+
+ private static String renderJavaDocTag(BlockTag tag) {
+ if (tag instanceof SinceTag) {
+ return "Since: " + ((SinceTag) tag).getSinceText() + "
";
+ }
+ return null;
+ }
}
diff --git a/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml b/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml
index 721c68f75..7796042b2 100644
--- a/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml
+++ b/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml
@@ -17,8 +17,11 @@
- This is a description in HTML4
-
NOTE: HTML linebreak should be converted to selfclosing XML-tag
+ Whether this proxy configuration is the active one. Note: While the type of this field is String for technical reasons, the semantic type is actually boolean.
+
+ This is a description in HTML4
+
NOTE: HTML linebreak should be converted to selfclosing XML-tag
+
Since: Maven 3
| Element |
diff --git a/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo b/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo
index 769cc6f41..ed52ea968 100644
--- a/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo
+++ b/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo
@@ -16,8 +16,11 @@
This is a comment
This is a description in HTML4
NOTE: HTML linebreak should be converted to selfclosing XML-tag
+ @since Maven 3
]]>
Model
From aaef952087e5060819e10549c19089117628a7d4 Mon Sep 17 00:00:00 2001
From: Guillaume Nodet
Date: Mon, 5 Feb 2024 10:24:42 +0100
Subject: [PATCH 2/2] Fix test to cope with jsoup adding a space
---
.../org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java | 6 +++++-
.../src/test/resources/html4.expected.xml | 1 +
.../modello-plugin-xdoc/src/test/resources/html4.mdo | 2 +-
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java b/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java
index 278e1921c..d740643f7 100644
--- a/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java
+++ b/modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java
@@ -23,6 +23,7 @@
*/
import java.io.File;
+import java.nio.file.Files;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
@@ -77,7 +78,10 @@ public void testHtmlToXml() throws Exception {
.withTest(Input.fromFile(new File(getOutputDirectory(), "html4.xml")))
.build();
- assertFalse(diff.toString(), diff.hasDifferences());
+ assertFalse(
+ diff.toString() + "\nGenerated output:\n"
+ + new String(Files.readAllBytes(new File(getOutputDirectory(), "html4.xml").toPath())),
+ diff.hasDifferences());
}
private void checkMavenXdocGenerator() throws Exception {
diff --git a/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml b/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml
index 7796042b2..494ba1d4d 100644
--- a/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml
+++ b/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml
@@ -21,6 +21,7 @@
This is a description in HTML4
NOTE: HTML linebreak should be converted to selfclosing XML-tag
+
Since: Maven 3
diff --git a/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo b/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo
index ed52ea968..cb85dc092 100644
--- a/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo
+++ b/modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo
@@ -19,7 +19,7 @@
Whether this proxy configuration is the active one. Note: While the type of this field
is {@code String} for technical reasons, the semantic type is actually {@code boolean}.
This is a description in HTML4
- NOTE: HTML linebreak should be converted to selfclosing XML-tag
+ NOTE: HTML linebreak should be converted to selfclosing XML-tag
@since Maven 3
]]>