Java
  Home arrow Java arrow Page 10 - Development and Build System with ANT
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Development and Build System with ANT
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2005-09-08

    Table of Contents:
  • Development and Build System with ANT
  • Continuous Integration
  • Automating the Build Process with Apache’s Ant
  • Introduction to Ant
  • More on Targets
  • Properties
  • Case Study: Building the Technology Conference Management System with Ant
  • JavaDoc Generation
  • Checking Code Conventions with Checkstyle
  • Generating Source-Code Metrics
  • The all Target

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Development and Build System with ANT - Generating Source-Code Metrics


    (Page 10 of 11 )

    Although we don’t advocate counting code lines, classes, or methods as a measure of a project’s success, static code analysis can help you pinpoint some areas of unnecessary complexity that can lead to the discovery of potential bugs or high-maintenance code.

    JavaNCSS is a simple source-measurement tool for Java that provides the following basic types of analysis:

     

    • NCSS: Noncommenting source statements provide counts of many features of the code such as lines of code, declarations, methods, statements, constructors, and so on.

       

    • CCN: Cyclomatic complexity number (McCabe metric). McCabe’s cyclomatic complexity metric looks at a program’s control flow graph as a measure of its complexity.

       

    You can download JavaNCSS fromhttp://www.kclee.com/clemens/java/javancss/as a simple ZIP file that includes an Ant task. Place all JAR files located under the distribution’s lib directory in a directory named javancss under the lib/development directory of the TCMS project. Next, create a directory named xslt under the lib/javancss and copy the contents of the xslt directory under the JavaNCSS distribution directory.

    The Ant task can generate a report in plain text of the XML format. As with the Checkstyle target, you’ll use the style task to transform the reports to HTML, as shown here:

    <!-- Javancss - kclee.com/clemens/java/javancss -->
    <taskdef
       
    name="javancss"
       
    classname="javancss.JavancssAntTask"
       
    classpathref="javancss.class.path"
       
    />
    <!-- ====================================================== -->
    <!-- Source Code Metrics
    -->
    <!-- ====================================================== -->
    <target
       
    name="metrics"
       
    depends="metrics-init"
       
    description="Generates Code Metrics Reports."
       
    >
        <!-- business tier source metrics -->
       
    <javancss
            srcdir="${src-java}"
            includes="**/*.java"
            excludes="**/entities/*Bean.java"
            generateReport="true"
            outputfile="${javancss-xml-business}"
            format="xml"
            functionMetrics="false"
            />

        
    <style
            in="${javancss-xml-business}"
            out="${javancss-html-business}"
            style="${javancss-stylesheet}"
            />
    />
    <target name="metrics-init">
        <mkdir dir="${metrics-reports}"/>
    </target>
    <target name="metrics-clean">
        <delete dir="${metrics-reports}"/>
    </target>

    The generated HTML reports look like the one shown in Figure 3-11.

     
    Figure 3-11.  A JavaNCSS HTML report

    Generating Browseable Source Code

    One useful feature for sharing knowledge about a project is the ability to generate a browseable version of the code for viewing online. Many Open Source projects use this as a way to allow others to view the source to a particular class without having to download a source distribution or having to use CVS. Java2Html is a tool that enables you to take a Java class or a snippet of Java code and generate a syntax-highlighted HTML version of the code.

    The Java2Html tool can be obtained fromhttp://www.java2html.deas a single ZIP file that contains one JAR file (java2html.jar). As with the other third-party Ant tasks, place the JAR file in a directory named java2html under the TCMS lib directory.

    As mentioned previously, you should load the task using the taskdef task. The generated HTML source will be placed under the location pointed to by the property ${browseable-source}, as shown here:

    <!-- Java2Html - java2html.de -->
    <taskdef
        name="java2html" 
        classname="de.java2html.anttasks.Java2HtmlTask"
        classpathref="java2html.class.path"
        />
    <property name="browseable-source" location="${docs}/browseable-source" />
    <!-- ===================================================== -->
    <!-- Generates browseable source code in HTML format
    -->
    <!-- ===================================================== -->
    <target
       
    name="java2html"
        depends="java2html-init"
        description="Generates browseable HTML version of the source code."
        >
        <java2html
           
    srcdir="${src}"
            destdir="${browseable-source}"
            includes="**/*.java"
            outputFormat="html"
            tabs="4"
            style="eclipse"
            showLineNumbers="true"
            showFileName="true"
            showTableBorder="true"
            includeDocumentHeader="true"
            includeDocumentFooter="true"
            addLineAnchors="true"
           
    lineAnchorPrefix="fff"/>
    </target>
    <target name="java2html-init">
       
    <mkdir dir="${browseable-source}"/>
    </target>
    <target name="java2html-clean">
       
    <delete dir="${browseable-source}"/>
    </target>

    Figure 3-12 shows an example of an HTML page generated by Java2HTML

    Cleaning Up

    The build process produces many files and directories. Getting the project directory to the same state as when the source was checked out of a repository is important for determining what has changed. Many Ant users recommend having a “clean” target that can remove all the products of the build process.

    The problem with this approach is that for large builds it’s easy to accidentally delete files that are needed and it’s also easy to miss files or directories that need to be deleted. For this reason you should include a clean subtarget for each main target in the buildfile. By doing this you’ll easily be able to determine what needs to be clean at the target level. Then for the global clean target you can simply invoke all individual clean subtargets by adding them to its list of dependencies as shown here:

    <!-- ====================================================== -->
    <!-- Cleans everything
    -->
    <!-- ====================================================== -->
    <target
       
    name="clean"
       
    depends="compile-clean,...,target N"
       
    description="Cleans all build products"
       
    >
       
    <delete dir="${build}"/>
    </target>

      
    Figure 3-12.  An HTML page generated by Java2HTML

    More Java Articles
    More By Apress Publishing


     

    Buy this book now. This article is taken from chapter three of the book Enterprise Java Development on a Budget, written by Brian Sam-Bodden and Christopher M. Judd (Apress, 2004; ISBN: 1590591259). Check it out at your favorite bookstore today. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT