<!-- 

Sample Ant Buildscript for multiple projects

This Ant script copies all sources from multiple projects into a single source folder (merged-sources).
Then it instruments all the files there, builds and runs them and finally
generates an HTML CodeCover report.

The analyze and generate-CodeCover-report part has been modified to use the command line interface 
instead of the CodeCover-Ant-Task, 
because the Ant Task produced an error:
[ERROR] A SAX error occurred: cvc-complex-type.3.2.2: Attribute 'Date' is not allowed to appear in element 'TestSessionContainer'. ).

(see http://sourceforge.net/forum/forum.php?thread_id=1911056&forum_id=738682)

CodeCover: http://www.codecover.org (Version 1.0.0.1 is recommended)

@author: Johannes Fiala (Fiala Web Development GmbH, http://www.fwd.at)
@created: 2009-06-25
-->
<project name="SampleServiceCodeCoverage" default="create-report">

	<property file="build.properties"/>

	<property name="sourceDir" value="src" />
	<property name="instrumentedSourceDir" value="instrumented" />
	<property name="mainClassName" value="at.fwd.sample.MainClass" />
	<property name="lib.home" value="" />
	<property name="codecoverExecDir" value="" />
	<property name="mavenRepo" value="" />


  <taskdef name="codecover"
           classname="org.codecover.ant.CodecoverTask"
           classpath="${codecoverExecDir}/lib/codecover-ant.jar" />

  <target name="clean">
    <delete>
      <fileset dir="." includes="*.clf"/>

    </delete>
    <delete file="codecover.xml" />
    <delete file="report.html" />
    <delete dir="report.html-files" />
  </target>

<!-- Copy sources of multiple projects together -->
  <target name="copy-sources" depends="clean">
  	<delete dir="merged-sources" />
  	<mkdir dir="merged-sources" />
  	<copy todir="merged-sources" >
  		<fileset dir="../sample-common/src/main/java" />
  		<fileset dir="../sample-common/src/main/resources" />
  		<fileset dir="../sample-common/src/main/test" />

  		<fileset dir="src/main/java" />
  		<fileset dir="src/main/resources" />
  		<fileset dir="src/main/test" />
  	</copy>
  </target>

<!-- Instrument the source files -->
  <target name="instrument-sources" depends="copy-sources">
  	<delete dir="${instrumentedSourceDir}" />
  	<mkdir dir="${instrumentedSourceDir}" />
    <codecover>
      <instrument containerId="c" language="java" destination="${instrumentedSourceDir}"
                  charset="utf-8" copyUninstrumented="yes">
        <source dir="merged-sources">
          <include name="**/*.java" />
        </source>
      </instrument>
      <save containerId="c" filename="codecover.xml" />
    </codecover>
  </target>

<!--  Compile and run the sources -->

<path id="compile.classpath">
		<!-- include all JARs in lib-directory -->
		<fileset dir="${lib.home}/">
			<include name="*.jar" />
		</fileset>
		<fileset dir="${codecoverExecDir}/lib/">
			<include name="codecover-instrumentation-java.jar" />
		</fileset>
		<fileset dir="${mavenRepo}/log4j/log4j/1.2.14">
			<include name="log4j-1.2.14.jar" />
		</fileset>
		<fileset dir="${mavenRepo}/junit/junit/3.8.1">
			<include name="junit-3.8.1.jar" />
		</fileset>
		<fileset dir="${mavenRepo}/commons-logging/commons-logging/1.0.2">
			<include name="commons-logging-1.0.2.jar" />
		</fileset>
		<fileset dir="${mavenRepo}/javax/transaction/jta/1.1">
			<include name="jta-1.1.jar" />
		</fileset>
		<fileset dir="${mavenRepo}/postgresql/postgresql/8.3-603.jdbc4">
			<include name="postgresql-8.3-603.jdbc4.jar" />
		</fileset>


	</path>

  <target name="compile-instrumented" depends="instrument-sources">
    <javac srcdir="${instrumentedSourceDir}"
           destdir="${instrumentedSourceDir}"
           encoding="utf-8"
           target="1.5"
           debug="true"
           classpath=""
           includeAntRuntime="false">
		<classpath refid="compile.classpath" />
    </javac>
  </target>

  <target name="run-instrumented" depends="compile-instrumented, run-instrumented-alone" />

  <target name="run-instrumented-alone" depends="">
    <java classpath="${instrumentedSourceDir}:${codecoverDir}/lib/codecover-instrumentation-java.jar:src/main/resources:src/main/test:../sample-common/src/main/resources:../sample-common/src/main/test"
          fork="true"
          failonerror="true"
          classname="${mainClassName}">
      <classpath refid="compile.classpath" />
      <jvmarg value="-Dorg.codecover.coverage-log-file=test.clf" />
    </java>

  </target>

	<target name="create-report" depends="run-instrumented,create-report-standalone">

	</target>

<!-- Analyze and create the report -->
  <target name="create-report-standalone" >
  	  <echo message="Analyzing report" />
	  <exec executable="${codecoverExecDir}/codecover.bat" dir="."  >
	    <arg line="analyze -c codecover.xml -g test.clf -n test1"/>

	  </exec>
	  <echo message="Creating report" />
	  <delete dir="reports/" />
	  <mkdir dir="reports/" />
	  <exec executable="${codecoverExecDir}/codecover.bat" dir="."  >
	    <arg line="report -c codecover.xml -s test1 -t ${codecoverExecDir}/report-templates/HTML_Report_hierarchic.xml -d reports/report_sample.html"/>

	  </exec>


    
  </target>
</project>

