Wednesday, May 12, 2010

UML Integration

There are several tools available which can generate class diagrams, but I found this one very useful, which can generate class diagrams when you build your java project using ant.

Download the UmlGraph from http://www.umlgraph.org/

and also download the Graphviz from http://www.graphviz.org/

Modify your build.xml and add following javadoc


<target name="javadocuml" depends="init, init-compile-classpath" description="generates javadoc and also UML Diagram">
<mkdir dir="${DIST_DIR}/report/javadoc">
   <javadoc sourcepath="${SRC_DIR}" packagenames="test.*" destdir="${DIST_DIR}/report/javadoc" classpathref="compile.classpath" private="true">
     <doclet name="org.umlgraph.doclet.UmlGraphDoc" path="${LIB_DIR}/UMLGraph-5.2.jar">
        <param name="-inferrel"/>
           <param name="-inferdep"/>
           <param name="-hide" value="java.*"/>
          <param name="-collpackages" value="java.util.*"/>
           <param name="-qualify"/>
           <param name="-postfixpackage"/>
           <param name="-nodefontsize" value="9"/>
           <param name="-nodefontpackagesize" value="7"/>
           <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"/>
       </doclet>
   </javadoc>
<apply executable="dot" dest="${DIST_DIR}/report" parallel="false">
    <arg value="-Tpng">
  <arg value="-o">
   <targetfile>
   <srcfile>
   <fileset dir="${DIST_DIR}/report" includes="*.dot">
   <mapper type="glob" from="*.dot" to="*.png">
   </mapper></fileset>
   </srcfile>
   </targetfile>
  </arg>
 </arg>
</apply>
</mkdir>
</target>


Run your build.xml with javadocuml ant-task and look for report dir. You can see some class diagrams in your javadoc. Refer to the umlgraph website for more information about things you can do with the class diagrams.


Maven configuration




<dependency>
   <groupId>gr.spinellis</groupId>
   <artifactId>UmlGraph</artifactId>
   <version>5.2</version>
</dependency>   


<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-javadoc-plugin</artifactId>
  <version>2.7</version>
  <configuration>
  <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>

  <!-- <docletPath>/path/to/UmlGraph.jar</docletPath> -->
  <docletArtifact>
      <groupId>org.umlgraph</groupId>
      <artifactId>doclet</artifactId>
      <version>5.1</version>
  </docletArtifact>
  <additionalparam>-inferrel -inferdep -quiet -hide java.*
 -collpackages java.util.* -qualify
 -postfixpackage -nodefontsize 9
 -nodefontpackagesize 7 -outputencoding utf8
  </additionalparam>
  <useStandardDocletOptions>true</useStandardDocletOptions>
  </configuration>
</plugin>

No comments: