Sometimes best way to learn about any new Open source Framework, APIs, Tools etc is to look in their source code. Documentation does help, but most of the time, specially for Open source software they fall short of their purpose.
I usually start by looking at build script, following different targets..corresponding source code and so on. For some of the Frameworks...let's say Log4J, you'll see plenty of targets in build file..It does not stop there, those targets refer other targets that reside in some other build file and it goes on.
Tracking all the build dependency by looking at the build file becomes very difficult, especially for the projects having more than 50-60 targets.
I’m going to show you how you can prepare a diagram for your build file.
I will be using Vizant and GraphViz for this purpose.
<target name="draw">
<vizant antfile="build.xml" outfile="build.dot"/>
<exec executable="dot" ><arg line="-Tpng build.dot -o build.png"/></exec>
</target>
I usually start by looking at build script, following different targets..corresponding source code and so on. For some of the Frameworks...let's say Log4J, you'll see plenty of targets in build file..It does not stop there, those targets refer other targets that reside in some other build file and it goes on.
Tracking all the build dependency by looking at the build file becomes very difficult, especially for the projects having more than 50-60 targets.
I’m going to show you how you can prepare a diagram for your build file.
I will be using Vizant and GraphViz for this purpose.
1) Download Vizant jar file from sourceforge
2) Install GraphViz. You can get .msi file from GraphViz web site. Check this URL for downloading installer. http://www.graphviz.org/Download_windows.php
Once you’re done installing the GraphViz, let’s use a sample build file to see, how it works.
build.xml
<project name="HelloWorld" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}\classes"/>
<property name="jar.dir" value="${build.dir}\jar"/>
<property name="main-class" value="oata.HelloWorld"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar basedir="${classes.dir}"
includes="**\*.class"
destfile="${jar.dir}\${ant.project.name}.jar">
<manifest>
<attribute name="Main-Class"
value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}\${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}\classes"/>
<property name="jar.dir" value="${build.dir}\jar"/>
<property name="main-class" value="oata.HelloWorld"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar basedir="${classes.dir}"
includes="**\*.class"
destfile="${jar.dir}\${ant.project.name}.jar">
<manifest>
<attribute name="Main-Class"
value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}\${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>
3) I will now be adding a new target for preparing an image for this build file.
First I will define a new task:
<taskdef name="vizant" classname="net.sourceforge.vizant.Vizant" classpath="lib/vizant.jar"/>
You can keep vizant.jar in whatever location you want on your local system, I kept it in /lib folder.
Next step, is to add a target that you can invoke for creating a pictorial representation of your build file.
<target name="draw">
<vizant antfile="build.xml" outfile="build.dot"/>
<exec executable="dot" ><arg line="-Tpng build.dot -o build.png"/></exec>
</target>
4) Once you add these lines to your build file, type
D:\Project-RND\RAndD>ant draw
You will see usual output on command window.
Buildfile: D:\Project-RND\RAndD\build.xml
draw:
BUILD SUCCESSFUL
Total time: 0 seconds
draw:
BUILD SUCCESSFUL
Total time: 0 seconds
5) Now check your project folder, you will be seeing two new files: build.dot and build.png
I'm attaching build.png for your reference, and you can now see target dependency tree.
For more information, check this URL: http://vizant.sourceforge.net/#parameters
Happy reading. Leave a comment, if you've any question.
No comments:
Post a Comment