Skip to content

Commit 1ca6d58

Browse files
authored
Parse javadoc tags in xdoc generator (only @SInCE is supported atm) (#414)
1 parent 9a4a130 commit 1ca6d58

File tree

5 files changed

+45
-13
lines changed

5 files changed

+45
-13
lines changed

modello-plugins/modello-plugin-xdoc/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<artifactId>jsoup</artifactId>
3131
<version>1.17.2</version>
3232
</dependency>
33+
<dependency>
34+
<groupId>com.github.chhorz</groupId>
35+
<artifactId>javadoc-parser</artifactId>
36+
<version>0.3.1</version>
37+
</dependency>
3338
<dependency>
3439
<groupId>org.xmlunit</groupId>
3540
<artifactId>xmlunit-core</artifactId>

modello-plugins/modello-plugin-xdoc/src/main/java/org/codehaus/modello/plugin/xdoc/XdocGenerator.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
import java.io.File;
2929
import java.io.IOException;
3030
import java.io.Writer;
31-
import java.util.HashMap;
32-
import java.util.HashSet;
33-
import java.util.List;
34-
import java.util.Map;
35-
import java.util.Properties;
36-
import java.util.Set;
37-
import java.util.Stack;
38-
31+
import java.util.*;
32+
import java.util.stream.Collectors;
33+
34+
import com.github.chhorz.javadoc.JavaDoc;
35+
import com.github.chhorz.javadoc.JavaDocParserBuilder;
36+
import com.github.chhorz.javadoc.OutputType;
37+
import com.github.chhorz.javadoc.tags.BlockTag;
38+
import com.github.chhorz.javadoc.tags.SinceTag;
3939
import org.codehaus.modello.ModelloException;
4040
import org.codehaus.modello.ModelloParameterConstants;
4141
import org.codehaus.modello.ModelloRuntimeException;
@@ -688,8 +688,24 @@ private static void writeMarkupElement(XMLWriter w, String name, String markup)
688688
* @return valid XML string
689689
*/
690690
private static String rewrite(String text) {
691-
Document document = Jsoup.parseBodyFragment(text);
691+
JavaDoc javaDoc = JavaDocParserBuilder.withStandardJavadocTags()
692+
.withOutputType(OutputType.HTML)
693+
.build()
694+
.parse(text);
695+
String html = javaDoc.getDescription()
696+
+ javaDoc.getTags().stream()
697+
.map(XdocGenerator::renderJavaDocTag)
698+
.filter(Objects::nonNull)
699+
.collect(Collectors.joining("\n", "\n", ""));
700+
Document document = Jsoup.parseBodyFragment(html);
692701
document.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
693702
return document.body().html();
694703
}
704+
705+
private static String renderJavaDocTag(BlockTag tag) {
706+
if (tag instanceof SinceTag) {
707+
return "<p><b>Since</b>: " + ((SinceTag) tag).getSinceText() + "</p>";
708+
}
709+
return null;
710+
}
695711
}

modello-plugins/modello-plugin-xdoc/src/test/java/org/codehaus/modello/plugin/xdoc/XdocGeneratorTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
import java.io.File;
26+
import java.nio.file.Files;
2627
import java.util.HashSet;
2728
import java.util.List;
2829
import java.util.Properties;
@@ -77,7 +78,10 @@ public void testHtmlToXml() throws Exception {
7778
.withTest(Input.fromFile(new File(getOutputDirectory(), "html4.xml")))
7879
.build();
7980

80-
assertFalse(diff.toString(), diff.hasDifferences());
81+
assertFalse(
82+
diff.toString() + "\nGenerated output:\n"
83+
+ new String(Files.readAllBytes(new File(getOutputDirectory(), "html4.xml").toPath())),
84+
diff.hasDifferences());
8185
}
8286

8387
private void checkMavenXdocGenerator() throws Exception {

modello-plugins/modello-plugin-xdoc/src/test/resources/html4.expected.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
</source>
1818
<a name="class_model"/>
1919
<subsection name="model">
20-
<p>This is a description in HTML4
21-
<br /><strong>NOTE: </strong> HTML linebreak should be converted to selfclosing XML-tag</p>
20+
<p>Whether this proxy configuration is the active one. Note: While the type of this field is <code>String</code> for technical reasons, the semantic type is actually <code>boolean</code>.
21+
<br />
22+
This is a description in HTML4
23+
<br /><strong>NOTE: </strong> HTML linebreak should be converted to selfclosing XML-tag
24+
<br />
25+
<p><b>Since</b>: Maven 3</p></p>
2226
<table>
2327
<tr>
2428
<th>Element</th>

modello-plugins/modello-plugin-xdoc/src/test/resources/html4.mdo

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
<comment>This is a comment</comment>
1717
<description>
1818
<![CDATA[
19+
Whether this proxy configuration is the active one. Note: While the type of this field
20+
is {@code String} for technical reasons, the semantic type is actually {@code boolean}.<br>
1921
This is a description in HTML4<br>
20-
<strong>NOTE: </strong> HTML linebreak should be converted to selfclosing XML-tag
22+
<strong>NOTE: </strong> HTML linebreak should be converted to selfclosing XML-tag<br>
23+
@since Maven 3
2124
]]>
2225
</description>
2326
<name>Model</name>

0 commit comments

Comments
 (0)