There are several tools for creating UML models of program source code. Some work for java, some for C++, and some not at all. Unfortunately, the latter case seems to be prominent. I searched google and looked in wikipedia. I saw many comments in forums lamenting that there are no useful uml diagram utilities in linux. In this post I comment on some of these methods and present two simple shell scripts for generating class dependency graphs.
One tool I tried is umbrello, which at the first try worked nicely, then however crashed (maybe there was too much source code) and never launched. I have seen people commenting similar behavior with umbrello. ArgoUML is another java-based tool, which produced diagrams from my code, however hardly legible ones. Class names overlapped and were not readable at all.
Actually, if you just want to see the dependency of you classes, it should not be so difficult to generate. Dependency diagrams from source code can be made in a very simple way, by using a bash 3-line shell script and visualizing with graphviz (see my introduction to graphviz).
For C++, you just parse the header files and find "class bar: public foo {." Then you parse this line and output to a file (here diagram.dot):
echo "digraph G {"> diagram.dot
sed -n -e "s/class [ ]*\([a-zA-Z0-9_]*\)[ ]*:[ ]*public [ ]*\([a-zA-Z0-9_]*\)[ ]*[{][ ]*/\1 -> \2 ;/p" *.h >> diagram.dot
echo "}" >> diagram.dot
compile to pdf:
And finished. You can see the inheritance of your classes in the pdf. Note that this script -- as it is -- only handles single inheritance from public classes.
You can use very similar commands for Java:
echo "digraph G {"> diagram.dot
sed -n -e "s/class [ ]*\([a-zA-Z0-9_]*\)[ ]* extends [ ]*\([a-zA-Z0-9_]*\)[ ]*[{][ ]*/\1 -> \2 ;/p" *.java >> diagram.dot
echo "}" >> diagram.dot
Enjoy. Please leave a comment for questions or suggestions.
U COMMENT
I FOLLOW

I used Umbrello in Ubuntu because it was feature-rich and produce nice-looking uml diagrams. Unfortunately it still has some bugs (version for KDE4), for example exporting to image doesn't work, some text comment boxes get automatically resized when opening the file, etc.
Still I would recommend Umbrello for Linux as it is easy to use, has a friendly interface and a lot of functionalities.
Hi Marc, thanks for the feedback. Umbrello is quite nice, but for my programs umbrello just crashed. Maybe it is not made to handle bigger programs. I think it is worth to try newer releases to see whether it has improved with the recent releases. Anyways, the article was to show that for very simple use cases, a simple bash command can do the job.
Subscribe to replies to this post
This conversation is missing your voice. Your feedback is appreciated.
Post a Comment
You can use some HTML tags, such as <b>, <i>, <a>
You can follow the discussion of this post by subscribing.
You are free to include information from this article on your own site if you provide a backlink. You can use the following markup: