<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<!--
  build.xml - The Green solver build script

  Public targets:
    build (default)   compile classes
    test              run all unit tests
    clean             remove the files generated by the build process
    package           create a jar file of the project
-->

<project name="green" default="build" basedir=".">

<!--
    Settings
-->

    <loadproperties srcFile="build.properties"/>
    <property name="output.dir" value="bin"/>
    <property environment="env"/>
    <property name="junit.dir" value="bin/junit"/>
    <property name="jar.file" value="green.jar"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <path id="green.classpath">
        <pathelement location="${output.dir}"/>
        <pathelement location="lib/apfloat.jar"/>
        <pathelement location="lib/commons-exec-1.2.jar"/>
        <pathelement location="lib/junit_4.8.2.jar"/>
        <pathelement location="lib/org.hamcrest.core_1.1.0.jar"/>
    	<pathelement location="lib/choco-solver-3.3.1.jar"/>
    	<pathelement location="lib/slf4j-api-1.7.12.jar"/>
    	<pathelement location="lib/slf4j-simple-1.7.12.jar"/>
    	<pathelement location="lib/trove-3.1a1.jar"/>
        <pathelement location="lib/choco-solver-2.1.3.jar"/>
        <pathelement location="lib/libcvc3.jar"/>
        <pathelement location="lib/com.microsoft.z3.jar"/>
        <pathelement location="lib/jedis-2.0.0.jar"/>
    </path>
    <path id="green.srcpath">
    	<pathelement location="src"/>
    	<pathelement location="test"/>
    </path>
    <property name="green.srcpath" refid="green.srcpath"/>
    
<!--
    Initialization
-->

    <target name="init">
        <mkdir dir="${output.dir}"/>
        <copy file="build.properties" todir="${output.dir}"/>
        <copy includeemptydirs="false" todir="${output.dir}">
            <fileset dir="src">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="${output.dir}">
            <fileset dir="test">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>

<!--
    TARGET: clean
-->

    <target name="clean">
        <delete dir="${junit.dir}"/>
        <delete dir="${output.dir}"/>
        <delete file="${jar.file}"/>
    </target>

<!--
    TARGET: build
-->

    <target name="build" depends="init">
    	<!-- <echo message="${ant.project.name}: ${ant.file}"/> -->
        <javac debug="true" debuglevel="${debuglevel}" destdir="${output.dir}" sourcepath="${green.srcpath}" source="${source}" target="${target}" bootclasspath="${bootpath}" includeantruntime="false">
            <src path="src"/>
            <classpath refid="green.classpath"/>
        </javac>
        <javac debug="true" debuglevel="${debuglevel}" destdir="${output.dir}" sourcepath="${green.srcpath}" source="${source}" target="${target}" bootclasspath="${bootpath}" includeantruntime="false">
            <src path="test"/>
            <classpath refid="green.classpath"/>
        </javac>
    </target>

<!--
    TARGET: test
-->

    <target name="test">
    	<echo message="java.library.path = ${z3lib};${cvc3lib}"/>
        <mkdir dir="${junit.dir}"/>
        <junit fork="yes" printsummary="withOutAndErr" haltonfailure = "yes">
            <formatter type="xml" usefile="false"/>
            <test name="za.ac.sun.cs.green.EntireSuite" todir="${junit.dir}"/>
            <env key="DYLD_LIBRARY_PATH" value="lib"/>
            <env key="LD_LIBRARY_PATH" value="lib"/>
            <sysproperty key="java.library.path" value="${z3lib}:${cvc3lib}"/>
            <classpath refid="green.classpath"/>
        </junit>
        <junitreport todir="${junit.dir}">
            <fileset dir="${junit.dir}">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${junit.dir}"/>
        </junitreport>
    </target>

<!--
    TARGET: package
-->

    <target name="package">
        <jar destfile="${jar.file}">
            <fileset dir="${output.dir}">
                <exclude name="${junit.dir}"/>
            </fileset>
            <fileset dir="src"/>
            <fileset dir="test"/>
        </jar>
    </target>

</project>