<?xml version="1.0" encoding="iso-8859-1" ?>

<!-- 
Test the quality of code with PMD, JDepend, ...
Designed to be imported by main build.xml , 
so don't worry about eclipse editor's message about target "compile".

Tested with eclipse Version: 3.2.0 Build id: I20060217-1115
$Header$
-->

<project basedir="../.." default="pmd" name="quality-tests">

    <!-- import default properties from file -->
    <property file="build.properties"/>
 
	<!-- You must put tools/ant/lib/jdepend-2.9.jar in the classpath,
	     sorry this an Ant problem. -->
    <target name="jdepend" description="Run jdepend" depends="compile">
    
        <taskdef name="jdepend" loaderref="ant.classpath"
                classname="org.apache.tools.ant.taskdefs.optional.jdepend.JDependTask">
            <classpath>
                <pathelement path="$(tools.ant)/lib/jdepend-2.9.jar" />
            </classpath>
        </taskdef>

        <!-- TODO make this not hardcoded -->
        <mkdir dir="test/jdepend/data" />
        <mkdir dir="test/jdepend/html" />

        <jdepend outputfile="test/jdepend/data/jdepend.xml" format="xml">
            <exclude name="java.*"/>
            <exclude name="javax.*"/>
            <classespath>
                <pathelement location="${build.classes}" />
            </classespath>
        </jdepend>

        <xslt in="test/jdepend/data/jdepend.xml" out="test/jdepend/html/jdepend.html"
                style="${tools.ant}/etc/jdepend-frames.xsl">
        </xslt>

    </target>
	
    <available file="${tools.ant}/lib/pmd-3.6.jar" property="jars-present" />

    <target name="check-jars-present" unless="jars-present">
    	
        <get src="http://www.ibiblio.org/maven2/pmd/pmd/3.6/pmd-3.6.jar"
                dest="${tools.ant}/lib/pmd-3.6.jar" verbose="true" />
    	
        <get src="http://www.ibiblio.org/maven2/jaxen/jaxen/1.1-beta-8/jaxen-1.1-beta-8.jar"
                dest="${tools.ant}/lib/jaxen-1.1-beta-8.jar" verbose="true" />
           
        <get src="http://www.ibiblio.org/maven2/oro/oro/2.0.8/oro-2.0.8.jar"
                dest="${tools.ant}/lib/oro-2.0.8.jar" verbose="true" />
                
    </target>

    <target name="pmd" description="Run PMD" depends="check-jars-present">
    
        <!-- TODO make this not hardcoded -->
        <mkdir dir="test/pmd" />
    	
        <!-- At "java.lang.ClassNotFoundException: 
             net.sourceforge.pmd.rules.XPathRule please rerun build pmd -->
        <taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
            <classpath>
                <fileset dir="${tools.ant}/lib">
                    <include name="jaxen-1.1-beta-8.jar" />
                    <include name="oro-2.0.8.jar" />
                    <include name="pmd*.jar" />
                </fileset>
            </classpath>
        </taskdef>
        
        <echo message="Please wait, running PMD...."/>
        
        <pmd classpath="tools">
            <ruleset>basic</ruleset>
            <ruleset>codesize</ruleset>
            <ruleset>design</ruleset>
            <ruleset>unusedcode</ruleset>
<!--    		
    		<ruleset>imports</ruleset>
    		<ruleset>naming</ruleset>
    		<ruleset>scratchpad</ruleset>
    		<ruleset>sunsecure</ruleset>
    		<ruleset>braces</ruleset>
    		<ruleset>javabeans</ruleset>
    		<ruleset>logging-java</ruleset>
    		<ruleset>logging-jakarta-commons</ruleset>
-->
            <ruleset>optimizations</ruleset>
            <ruleset>strictexception</ruleset>
            <ruleset>clone</ruleset>
            <ruleset>coupling</ruleset>
            <ruleset>finalizers</ruleset>
            <ruleset>junit</ruleset>
            <ruleset>strings</ruleset>  
    		
            <formatter type="text" toFile="test/pmd/report.txt" linkPrefix="src" />
            <formatter type="html" toFile="test/pmd/report.html"/>
            <formatter type="xml"  toFile="test/pmd/report.xml" />
            
            <fileset dir="src">
                <include name="**/*.java" />
                <exclude name="**/parser/*.java" />
            </fileset>
        </pmd>
    </target>

</project>
