Tag Archives: Javadoc

Another (better) way to generate Javadoc with UML diagrams

Today I want to tell you about my favorite documentation generator. This is Doxygen.

It’s totally free, supports a lot of languages, generates graphs, can link source code and even process code without comments. The output formats are: HTML, Latex, RTF, PDF and others. Also it can be tuned for many aspects, so it’s nearly ideal!

I used Doxygen for making documents for Qt project (C++) and it had worked perfectly. To tell the truth, Doxygen is de facto standard for generating documentation from C++ source, but how it deal with Java?

Brilliantly! You need to do just four steps:

  • download and install Graphviz. I wrote about it in my previous post.
  • download and install Doxygen.
  • open doxywizard
  • specify all the options and Run – Run doxygen!

Configuring Doxygen could presents someĀ difficulties for beginners, so I share my doxygen file, that tuned on generating RTF and html documentation with all the graphs.

Take the file, go to doxywizard and File – Open. You have to tune some fields in {}’s and fields in Expert – Project window. My changes are highlighted with red color.

Link to file.

Javadoc with UML diagrams for Android project using (almost) only Gradle!

One of the important moments of documenting source code is creation UML diagrams. UML diagrams – a simple, unified and at the same time powerful means of description your of project from different sides.

Well, the project have written and commented in javadoc manner, how can you create and insert charts in documentation? You need a software, that makes reverse-engineering work for you. In Android case, actually, your choice is not so great: there are about five free solutions for convert your source code in javadoc with UML diagrams, but they are quite mighty.

In this post I show you how to use UMLGraph with Gradle to build docs from console.

  • first of all, you should download and install Graphviz. Graphviz is open source graph visualization software that process the output of UML doclet to png image diagram.
  • open build.gradle of your app module and add this code:
    allprojects {
    configurations {
        umljavadoc
    }

    dependencies {
        umljavadoc 'org.umlgraph:umlgraph:5.6'
    }

    //
    // While javadoc is not typically dependent on compilation, the compile steps
    // sometimes generate some sources that we wish to have in the Javadoc.
    //
    task javadoc(overwrite: true, dependsOn: build) {
        setDescription('Generates Javadoc API documentation with UMLGraph diagrams')
        setGroup(JavaBasePlugin.DOCUMENTATION_GROUP)

        doLast {
            def javaFilePath = file('src/main/java')
            if (javaFilePath.exists())
            {
                ant.javadoc(classpath: "{path_to_android_sdk}/android.jar",
                        sourcepath: file('src/main/java'),
                        packagenames: '*',
                        destdir: "{path_to_project}/javadoc",
                        private: 'true',
                        docletpath: configurations.umljavadoc.asPath,
                        charset: 'UTF-8',
                        encoding: 'UTF-8',
                        docencoding: 'UTF-8') {
                    doclet(name: 'org.umlgraph.doclet.UmlGraphDoc')
                            {
                                param(name: '-nodefontsize', value: '9')
                                param(name: '-nodefontpackagesize', value: '7')
                                param(name: '-qualify')
                                param(name: '-postfixpackage')
                                param(name: '-hide', value: 'java.*')
                                param(name: '-collpackages', value: 'java.util.*')
                                param(name: '-inferrel')
                                param(name: '-inferdep')
                                param(name: '-link', value: 'http://java.sun.com/j2se/1.5.0/docs/guide/javadoc/doclet/spec')
                                param(name: '-link', value: 'http://java.sun.com/j2se/1.5/docs/api')
                            }
                }
            }
            else
            {
                print("!!! Cannot find source path !!!");
            }
        }
    }
}
  • Specify your own classpath, destdir and other params you need.
  • open console and in project’s dir type gradlew javadoc.
  • That’s all! There is documentation with UML class diagrams in {path_to_project}/javadoc!