<?xml version="1.0"?>

<project name="report">

   <!-- Redefine to make included build file self contained and
      make eclipse happy. -->
   <property name="base.dir" value="../"/>
  
   <!-- The ruleset files -->
   <property name="pmd.rules" value="${base.dir}/config/jcoderz-pmd.xml"/>
   <property name="checkstyle.rules" value="${base.dir}/config/jcoderz-checkstyle.xml" />
   <property name="findbugs.rules" value="${base.dir}/config/jcoderz-findbugs.xml" />
   <property name="filter.rules" value="${base.dir}/config/jcoderz-report-filter.xsl" />

   <target name="summary-report">
      <!-- This is the classpath used by the JcReportAntTask -->   
      <path id="jcreport.classpath">
         <pathelement path="${base.dir}/build/classes"/>
         <fileset dir="${base.dir}/lib">
            <include name="default/jaxb/*.jar"/>
            <include name="default/chart2d/*.jar"/>
            <include name="default/jedit/*.jar"/>
         </fileset>
      </path>
      <taskdef name="jcsummaryreport"
               classname="org.jcoderz.phoenix.report.JcSummaryReportAntTask">
         <classpath refid="jcreport.classpath"/>
      </taskdef>
      <jcsummaryreport name="fawkez-summary"
                       summary="${env.CRUISECONTROL_HOME}/artifacts/${name}/global/history.csv"
                       dest="${build.dir}/doc/summary"
                       basedir="${env.CRUISECONTROL_HOME}/artifacts/${name}"/>
   </target>

   <target name="report">
   	
    <path id="emma.lib">
      <pathelement location="${base.dir}/lib/default/emma/emma.jar"/>
      <pathelement location="${base.dir}/lib/default/emma_ant/emma_ant.jar"/>
    </path>
    <taskdef resource="emma_ant.properties" classpathref="emma.lib"/>
    <emma enabled="${build.coverage}" >
      <merge outfile="${build.dir}/full-coverage.es">
        <fileset dir="${build.dir}" includes="*.em, *.ec" />
        <fileset dir="${base.dir}" includes="*.em, *.ec">
          <exclude name="full-coverage.es"/>
        </fileset>
      </merge>
    </emma>
   	<delete>
        <fileset dir="${base.dir}">
          <include name="*.em"/>
          <include name="*.ec"/>
        </fileset>
   	</delete>
   	
      <!-- This is the classpath used by the JcReportAntTask -->   
      <path id="jcreport.classpath">
         <pathelement path="${base.dir}/build/classes"/>
         <fileset dir="${base.dir}/lib">
            <include name="default/jaxb/*.jar"/>
            <include name="default/chart2d/*.jar"/>
            <include name="default/emma/*.jar"/>
         </fileset>
        <fileset dir="${build.dir}">
           <include name="jedit-syntax.jar"/>
        </fileset>
      </path>
      <taskdef name="jcreport"
               classname="org.jcoderz.phoenix.report.JcReportAntTask">
         <classpath refid="jcreport.classpath" />
      </taskdef>

      <!-- This classpath is used by the checkstyle process -->   
      <path id="checkstyle.classpath">
         <fileset dir="${base.dir}/lib">
            <include name="default/antlr/*.jar"/>
            <include name="default/checkstyle/*.jar"/>
            <include name="default/commons-beanutils/*.jar"/>
            <include name="default/commons-beanutils-core/*.jar"/>
            <include name="default/commons-cli/*.jar"/>
            <include name="default/jcl-over-slf4j/*.jar"/>
            <include name="default/slf4j-api/*.jar"/>
            <include name="default/slf4j-jdk14/*.jar"/>
         </fileset>
         <path location="${base.dir}/build/classes"/>
         <fileset dir="${base.dir}/lib">
           <include name="default/jaxb/jaxb-api.jar"/>
         </fileset>
      </path>
      <!-- This classpath is used by the pmd and cpd process -->   
      <path id="pmd.classpath">
         <fileset dir="${base.dir}/lib">
            <include name="default/pmd/*.jar"/>
            <include name="default/asm*/*.jar"/>
            <include name="default/backport-util-concurrent/*.jar"/>
            <include name="default/jaxen/*.jar"/>
            <include name="default/oro/*.jar"/>
         </fileset>
      </path>
      <!-- This classpath is used by the findbugs process -->   
      <path id="findbugs.classpath">
         <fileset dir="${base.dir}/lib">
            <include name="default/findbugs/*.jar"/>
            <include name="default/asm*/*.jar"/>
            <include name="default/jaxen/*.jar"/>
            <include name="default/dom4j/*.jar"/>
            <include name="default/commons-lang/*.jar"/>
            <exclude name="**/fb-contrib.jar"/>
         </fileset>
      </path>
      <path id="findbugs.plugins">
        <path location="${base.dir}/lib/default/fb-contrib/fb-contrib.jar"/>
      </path>
      <!-- This is the auxiliary classpath used by findbugs -->   
      <path id="findbugs.aux.classpath">
         <path location="${base.dir}/build/classes"/>
         <path location="${env.JAVA_HOME}/lib/tools.jar"/>
         <fileset dir="${base.dir}/lib">
            <include name="default/**/*.jar"/>
         </fileset>
      </path>

   	  
   	
      <delete dir="${base.dir}/build/jcreport"/>
      <jcreport name="fawkez"
                dest="${base.dir}/build/doc/findings-report"
                wikibase="http://www.jcoderz.org/fawkez/wiki/jcreport:"
                webrcsbase="http://www.jcoderz.org/fawkez/browser/trunk"
                webrcssuffix=""
                packagebase="org.jcoderz"
                projectbase="${base.dir}"
                tempfolder="${base.dir}/build/jcreport"
                debug="false"
                maxheap="128"
                encoding="US-ASCII"
                cpus="1"
                oldReportFile="${env.CRUISECONTROL_HOME}/artifacts/${name}/global/jcoderz-report.xml"> 
         <classpath refid="jcreport.classpath"/>
         <reports>   
            <report name="fawkez-test"
                    level="test"
                    sourcepath="${base.dir}/test/java"
                    classpath="${build.dir}/test-classes">
            </report>
            <report name="fawkez-prod"
                    level="prod"
                    sourcepath="${base.dir}/src/java"
                    classpath="${build.dir}/classes">
            </report>
         </reports>
         <mappings>
            <webrcs pattern="**/fawkez" url="http://" suffix=""/>
         </mappings>   
         <tools>
            <pmd config="${pmd.rules}"
                 targetjdk="1.4">
               <classpath refid="pmd.classpath"/>
            </pmd>
            <cpd minimumtokens="100">
               <classpath refid="pmd.classpath"/>
            </cpd>
           <!-- Could not disable UnreadFields cause further dependencies -->
           <findbugs maxheap="256" 
              effort="max"
              debug="false"
              omitVisitors="RuntimeExceptionCapture,FindUncalledPrivateMethods,CustomBuiltXML,DeclaredRuntimeException,PossiblyRedundantMethodCalls,ExceptionSoftening"
              warninglevel="low">
               <classpath refid="findbugs.classpath"/>
               <auxclasspath refid="findbugs.aux.classpath"/>
               <pluginlist refid="findbugs.plugins"/>
            </findbugs>
            <checkstyle config="${checkstyle.rules}"
              maxHeap="256"> 
               <classpath refid="checkstyle.classpath" />
            </checkstyle>
            <!-- cobertura datafile="x.ser">
            </cobertura -->
            <emma datafile="${build.dir}/full-coverage.es"/>
         </tools>
         <logfiles>
           <logfile file="${build.dir}/javadoc.log" type="JavaDoc"/> 
           <logfile file="${build.dir}/javac.log" type="javac"/> 
         </logfiles>
         <filters>
            <filter file="${filter.rules}"/>
         </filters>
      </jcreport>   
    <!-- TODO: Only do this on the cc machine. -->
    <copy 
        file="${base.dir}/build/doc/findings-report/jcoderz-report.xml"
        tofile="${env.CRUISECONTROL_HOME}/artifacts/${name}/global/jcoderz-report.xml" />
   </target>   

   <target name="view-report" depends="report, view-report-nodeps"
           description="Generates a report and displays it on the os default browser."/>
   <target name="view-report-nodeps">
   <!-- TODO: for not win os we might check if the $BROWSER environment
              variable is set and if use this as command -->
      <exec executable="cmd.exe" spawn="true" os="Windows XP">
         <arg value="/C" />
         <arg file="${build.dir}/build/doc/findings-report/index.html"/>
      </exec>
   </target>

</project>
