However, we don't have to keep making up stories anymore, since this article shows how easy and simple it is to include UML diagrams within your Javadoc and also keep them updated with every change in the source code repository. We can do these in less than a few minutes, and in a few simple steps.
Getting started with UmlGraph takes five steps:
- Download the source code for UMlGraph.
- Download and install Graphviz.
- Make changes to your Ant build file.
- Run the Ant target.
- Add this target to your CI job.
java.lang.UnsupportedClassVersionError: Bad version number in .class fileMake sure you recompile the UMLGraph source code, and copy the library to your project.
Step2 : Download and install Graphviz from here. The dot file needs to be post-processed with Graphviz to produce the actual UML diagram. Running the UmlGraph doclet will generate a Graphviz diagram specification that can be automatically processed to create png drawings. You can also generate other formats using Graphviz as well. If Graphviz isn’t installed you will get an exception as shown below:
BUILD FAILED
/Users/meerasubbarao/Development/webservices-samples/build.xml:107:
Execute failed: java.io.IOException: dot: not found
Total time: 269 milliseconds
Step 3. Changes to your build.xml file.
Assuming you already have a working project, with Ant build file. Add the following target to your build.xml file as shown below:
01.
<
target
name
=
"javadocs"
depends
=
"build"
description
=
"generates javadoc and also UML Diagram"
>
02.
<
mkdir
dir
=
"${reports.dir}/javadoc"
/>
03.
<
javadoc
sourcepath
=
"${src.dir}"
packagenames
=
"com.stelligent.*"
destdir
=
"${reports.dir}/javadoc"
04.
classpathref
=
"java.classpath"
private
=
"true"
>
05.
<
doclet
name
=
"org.umlgraph.doclet.UmlGraphDoc"
06.
path
=
"lib/UMLGraph.jar"
>
07.
<
param
name
=
"-attributes"
/>
08.
<
param
name
=
"-operations"
/>
09.
<
param
name
=
"-qualify"
/>
10.
<
param
name
=
"-types"
/>
11.
<
param
name
=
"-visibility"
/>
12.
</
doclet
>
13.
</
javadoc
>
14.
<
apply
executable
=
"dot"
dest
=
"${reports.dir}"
parallel
=
"false"
>
15.
<
arg
value
=
"-Tpng"
/>
16.
<
arg
value
=
"-o"
/>
17.
<
targetfile
/>
18.
<
srcfile
/>
19.
<
fileset
dir
=
"${reports.dir}"
includes
=
"*.dot"
/>
20.
<
mapper
type
=
"glob"
from
=
"*.dot"
to
=
"*.png"
/>
21.
</
apply
>
22.
</
target
>
A number of options contol the operation of UMLGraph class diagram generator. These can be specified as parameters within your build file as shown above.
Details about a few options are:
-output
Specify the output file (default graph.dot).
-d
Specify the output directory (defaults to the current directory).
-qualify
Produce fully-qualified class names.
-horizontal
Layout the graph in the horizontal direction.
-attributes
Show class attributes (Java fields)
-operations
Show class operations (Java methods)
-constructors
Show a class's constructors
-visibility
Adorn class elements according to their visibility (private, public, protected, package)
-types
Add type information to attributes and operations
-enumerations
Show enumarations as separate stereotyped primitive types.
-enumconstants
When showing enumerations, also show the values they can take.
-all
Same as -attributes -operations -visibility -types -enumerations -enumconstants
Take a look here for more options. Step 4. Run the ant target:
Open a command window and run the ant target: ant javadocs and you should see output as such in your console window:
The javadoc generated is pretty neat with UML diagrams on the top:meera-subbaraos-macbook-9:webservices-samples meerasubbarao$ ant javadocs Buildfile: build.xml init: cleanGenerated: build: [javac] Compiling 22 source files to /Users/meerasubbarao/Development/ci-jobs/jobs/PetStore_Nightly/workspace/webservices-samples/classes [javac] Note: Some input files use unchecked or unsafe operations. [javac] Note: Recompile with -Xlint:unchecked for details. javadocs: [javadoc] Generating Javadoc [javadoc] Javadoc execution [javadoc] Loading source files for package com.stelligent.biz.ws... [javadoc] Loading source files for package com.stelligent.ent.jpa... [javadoc] Constructing Javadoc information... [javadoc] UmlGraphDoc version 5.0, running the standard doclet [javadoc] Standard Doclet version 1.5.0_13 [javadoc] Building tree for all the packages and classes... [javadoc] Building index for all the packages and classes... [javadoc] Building index for all classes... [javadoc] Generating /Users/meerasubbarao/Development/ci-jobs/jobs/PetStore_Nightly/workspace/webservices-samples/reports/javadoc/stylesheet.css... [javadoc] UmlGraphDoc version 5.0, altering javadocs [javadoc] Building Package view for package com.stelligent.biz.ws [javadoc] Building Package view for package com.stelligent.ent.jpa [javadoc] Building Context view for class com.stelligent.biz.ws.SupplierManagerBean [javadoc] Building Context view for class com.stelligent.biz.ws.SupplierManager [javadoc] Building Context view for class com.stelligent.biz.ws.SignonManagerBean [javadoc] Building Context view for class com.stelligent.biz.ws.SignonManager ..... BUILD SUCCESSFUL Total time: 8 seconds meera-subbaraos-macbook-9:webservices-samples meerasubbarao$
Step 5: Add this target to your CI Job.
If you already have a CI server like Hudson up and running, which runs commit builds and nightly builds, adding this new target is a one step process. In my case, I already have a nightly job running, I added this ant target to my default target as shown below:
1.
<
target
name
=
"all"
depends
=
"cleanAndDeployForCoverage, javadocs"
/>
The Javadoc embedded with UML diagrams displayed from within the Hudson dashboard:
Now that we have UML diagram integrated within our build file, and also our CI job, we can ensure that our code base and the UML diagrams are always in sync. We saw how to include these ant targets in our commit builds or nightly builds of our CI jobs, and also published these artifacts as part of our post build process.
Resources:
from: Reverse-engineer Source Code into UML Diagrams
No comments:
Post a Comment