<?xml version="1.0" encoding="utf-8" ?>
<project name="etch-transport-http-json" basedir="." default="help">
    <description>An HTTP-based, JSON-encoded transport for Etch</description>
    <property name="Etch.basedir" location="${basedir}/../.." />
    <import file="${Etch.basedir}/build-support/etch.includes.xml" />

    <taskdef resource="org/apache/ant/dotnet/antlib.xml" classpath="${Etch.dependency.ant-dotnet-1.0.jar}" />

    <!-- Static properties of the sub-project -->
    <property name="proj"                 location="${Etch.basedir}/transport-http-json/transport" />
    <property name="target"               location="${proj}/target" />
    <property name="src"                  location="${proj}/src" />
    <property name="rawNUnitResults"      location="${target}/nunit-results" />
    <property name="testResultsDirectory" location="${target}/test-results"  />

    <!-- TODO better computation of etch.home, etch.version -->
    <property environment="env" />
    
    <!-- compute ETCH_HOME -->
    <property name="build.ETCH_HOME" location="${Etch.basedir}/target/Installers/dist" />
    <condition property="etch.home" value="${env.ETCH_HOME}">
        <isset property="${env.ETCH_HOME}" />
    </condition>
    <condition property="etch.home" value="${build.ETCH_HOME}" >
        <not><isset property="etch.home" /></not>
    </condition>
    
    <!-- compute etch.version -->
    <condition property="etch.version" value="1.0.1" >
        <not><isset property="etch.version" /></not>
    </condition>


    <!-- import etch task -->
    <taskdef
        name="etch"
        onerror="report"
        classname="etch.tools.ant.EtchCompileTask"
	classpath="${etch.home}/lib/etch-ant-plugin-${etch.version}.jar" />


    <!-- INIT TARGET -->
    <!-- Modify this target to define project specific properties that can only be set at runtime -->
    <target name="do-init">
        <delete dir="${target}" failonerror="false" quiet="true" />

        <mkdir dir="${target}" />
        <mkdir dir="${testResultsDirectory}" />
    </target>

    <!-- CLEAN TARGET -->
    <target name="do-clean">
     	<delete dir="${target}" />
	<delete dir="${src}/main/csharp/BrowserTransport/bin" />
	<delete dir="${src}/main/csharp/BrowserTransport/obj" />
	<delete dir="${src}/main/csharp/ComplexDataTest/bin" />
	<delete dir="${src}/main/csharp/ComplexDataTest/obj" />
	<delete dir="${src}/main/csharp/TrivialHttpServer/bin" />
	<delete dir="${src}/main/csharp/TrivialHttpServer/obj" />
   </target>

    <!-- BUILD TARGET -->
    <target name="generate-sources" >
        <!-- Generate version info -->
	<update-tokens filename="${src}/main/csharp/BrowserTransport/Properties/AssemblyInfo.cs" />
    </target>

    <target name="build-main-with-mono" if="USE.mono" >
        <echo message="TODO: build w/ mono" />
	<mdtool dir="${src}/main/csharp/BrowserTransport/" project="BrowserTransport.csproj" />
	<mdtool dir="${src}/main/csharp/TrivialHttpServer/" project="TrivialHttpServer.csproj" />
	<mdtool dir="${src}/main/csharp/ComplexDataTest/" project="ComplexDataTest.csproj" />
    </target>

    <target name="build-main-with-dotnet" if="USE.dotnet" >
        <!-- Build Transport library-->
	<msbuild buildfile="${src}/main/csharp/BrowserTransport/BrowserTransport.csproj">
            <property name="Configuration" value="${Etch.build.target}" />
    	</msbuild>

    	<!-- Build TrivialHttpServer (embeddable, test-quality Http server and proxy) -->
    	<msbuild buildfile="${src}/main/csharp/TrivialHttpServer/TrivialHttpServer.csproj">
            <property name="Configuration" value="${Etch.build.target}" />
    	</msbuild>

    	<!-- Build ComplexDataTest (manual test suite) -->
    	<msbuild buildfile="${src}/main/csharp/ComplexDataTest/ComplexDataTest.csproj">
            <property name="Configuration" value="${Etch.build.target}" />
        </msbuild>
    </target>

    <target name="build-main-csharp" depends="build-main-with-mono,build-main-with-dotnet" />

    <target name="do-build" depends="generate-sources,build-main-csharp" if="BUILD.csharp" >

	    <!-- for this project, build operations occur in msbuild and the msbuild post-build event -->
    </target>

    <!-- TEST TARGET -->
     <target name="build-test-with-mono" if="USE.mono" >
        <echo message="TODO: build w/ mono" />
	<!--<mdtool dir="${src}/main/csharp/BrowserTransport/" project="BrowserTransport.csproj" />
	<mdtool dir="${src}/main/csharp/ComplexDataTest/" project="ComplexDataTest.csproj" />-->
</target>

	<target name="build-test-with-dotnet" if="USE.dotnet" >
	<echo message="TODO: integrate tests" />
	<!--  <msbuild buildfile="${src}/test/csharp/EtchTestProj.csproj" >
            <property name="Configuration" value="${Etch.build.target}" />
    </msbuild>-->
	</target>

    <target name="build-test-csharp" depends="build-test-with-mono,build-test-with-dotnet" />

    <target name="do-test" depends="build-test-csharp" if="USE.dotnet" >

	 <mkdir dir="${rawNUnitResults}" />
	 <!--
        <nunit xmlout="${rawNUnitResults}/NUnitResults.xml">
            <testassembly name="${src}/test/csharp/bin/${Etch.build.target}/EtchTest.dll" />
        </nunit>

        <xslt style="${Etch.buildSupportDirectory}/NUnitToJUnit.xsl"
                in="${rawNUnitResults}/NUnitResults.xml" out="${testResultsDirectory}/TEST-NUnitResults.xml" />
	-->
    </target>

    <!-- POSTBUILD TARGET -->
    <target name="do-postbuild">
    </target>

    <target name="do-publish" if="build.tests.fail">
        <!-- Set flag file if any tests failed -->
        <touch file="${Etch.runtime.tests.fail}"/>
    </target>

</project>

