Search code examples
regexgroovyjavadocdoxygen

How to parse the java comments of a groovy file to html format?


I have a set of .groovy files (Java). All of these files have the same comment format. I developed a tool with which I'm able to read those files and applying a REGEX to get all the comments in a list. (Finally I just have to copy paste these comments to .html file) I would like to know if it's a correct practice in order to generate a HTML page with the comment (a kind of documentation). If not, what would you recommend?

I read about Doxygen and Javadoc, but I'm not sure about using them (if they can be really useful in my case since the comments are already written)

If you can suggest a library in order to generate easily a HTML Webpage or any other advice.

Any help is appreciated.


Solution

  • There exists Groovydoc which is roughly the equivalent of Javadoc, just for Groovy.

    As your setup is not that (you already have comments, probably not in Groovydoc format, and you have half the tooling), there are still multiple ways open to you. As you already extract the documentation from groovy, if I were you, I would do a minimal post-formatting, if necessary, and output the documentation as markdown (e.g., github markdown) or asciidoc (e.g., asciidoctor). Then you can use any preferred tool to convert the post-formatted documentation into HTML.

    To answer the question "How to parse the java comments" – you shouldn't. If possible, especially in a new project, stick with the standard tooling. In the case of Groovy that's Groovydoc. The normal (non Java/Groovy-Doc style) comments themselves you should never need to extract from the source code. They should be so much context-specific, that without the corresponding code they are anyways useless.