2

Generate JavaDoc with UML diagrams

Posted by JOKe on 3/11/2011 12:08:00 PM in

In my life many times has happened when I am assigned to a totally new project that I have no idea what it is about, that has to go live in 2 weeks and that I have to fix some issues in this ultra strange code sometimes even code written in different language.

On my question is there any documentation the answer is: Yes but it is very old or no. So in short they want me to start working on a project with no documentation at all.

My second question is is there a javadoc and the anwer is : yeah … kind of … so I am in a project with 30% javadoc with methods in French language for example ( I don’t know even a single word in French) so in short I am loosing 2 weeks to understand what is using what what is the model what is PersonnePhysique  and what is this crazy domain model.

I believe this has happened with everyone of you at least once so what can you do ?

  • You can start digging into the java code like crazy ( like everyone of us have tried many times)
  • You can install intellij idea and use the great reverse engineering way to create UML diagrams for specific classes but intelliJ idea costs money.
  • You can install netbeans 6.5 and do the same but you have to use this out dated version of NetBeans because this doesn’t exist in newer versions, thanks Oracle.
  • You can install Eclipse + MoDisco + MDT + KML to generate xmisomething file then to generate xml file with KML thingy then to use UML2 tools to view this diagram blah.
  • Or you can find some other way… this is the other way which I believe is very nice and useful and you should use it in every project that you can actually this should be the first thing that the architect should put in the project.

So in short the other way is to generate a UML diagrams each time when a javadoc is generated it will generate a UML diagrams for each class and package which contains whatever you want operations,attributes,constructors just names you can click on them and navigate using them it is AWESOME.

How this will look like ? like this:

uml1

And you can click on items for example on Category which will forward you to the Category javadoc which has a diagram as well which looks like this :

UML2

Awesome right ?

How you can do it ? In my example I will use maven so what you have to do :

use of UmlGraph

use of Graphviz

change of maven pom.xml update (for ant integration check the last link in the blog post)

1) install graphviz on the machine that will generate the javadoc .. usually this is a linux machine which runs hudson or whatever so in case of ubuntu you just need apt-get install graphviz4 otherwise you can download the msi/deb/rpg/source from here http://www.graphviz.org/Download..php then just type “dot –-help” in console to check that the dot executable is in your path.

2) update your pom.xml adding UmlGraph just add:

<plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <aggregate>true</aggregate>
                    <show>private</show>
                    <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
                    <docletArtifact>
                        <groupId>org.umlgraph</groupId>
                        <artifactId>doclet</artifactId>
                        <version>5.1</version>
                    </docletArtifact>
                    <additionalparam>
                        -inferrel -attributes -types -visibility -inferdep -quiet -hide java.* -collpackages java.util.* -qualify -postfixpackage
                        -nodefontsize 9
                        -nodefontpackagesize 7
                            </additionalparam>
                </configuration>
            </plugin>

3) invoke mvn javadoc:javadoc … and you are done. :+) easy right ? You can see explanation about all umlgraph options here http://www.umlgraph.org/doc/indexw.html like do you don’t want to see the attributes, but you want the operations and etc..

Example with operations will look like this:

 

For ant integration check http://java.dzone.com/articles/reverse-engineer-source-code-u


|

2 Comments


That's pretty cool. There's also apiviz which basically does the same thing but looks a bit more modern.


yep this also looks nice :)

Copyright © 2009 JOKe's Blog All rights reserved. Theme based on the Theme by Laptop Geek with changes by JOKe. | Bloggerized by FalconHive.