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

<project basedir="." default="build" name="calculator_ui">
  <!-- Provide access to all environmental variables, prefixed with 'env.' -->
  <property environment="env"/>
  <property name="debuglevel" value="source,lines,vars"/>
  <property name="target" value="1.8"/>
  <property name="source" value="1.8"/>

  <!-- Arguments to gwtc and devmode targets -->
  <property name="gwt.args" value="" />

  <!-- Configure path to GWT SDK -->
  <property name="gwt.sdk" location="${env.GWT_PATH}" />
  <property name="gxt.sdk" location="${env.GXT_PATH}" />
  <property name="junit" location="${env.JUNIT_PATH}" />

  <path id="edu.nrao.dss">
    <pathelement location="war/WEB-INF/classes"/>
    <pathelement location="${gwt.sdk}/gwt-user.jar"/>
    <fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
    <!-- Add any additional non-server libs (such as JUnit) -->
    <fileset dir="war/WEB-INF/lib" includes="**/*.jar"/>
    <pathelement location="${gxt.sdk}/gxt-2.2.4-gwt22.jar"/>
    <pathelement location="${junit}/junit-4.5.jar"/>
  </path>

  <target name="libs" description="Copy libs to WEB-INF/lib">
    <mkdir dir="war/WEB-INF/lib" />
    <copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
    <copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet-deps.jar" />
    <!-- Add any additional server libs that need to be copied -->
    <!-- <copy todir="war/WEB-INF/lib" file="${gxt.sdk}/gxt-2.2.4-gwt22.jar"/> -->
  </target>

  <target name="clean">
    <delete dir="war/WEB-INF/classes"/>
  </target>

  <target depends="clean" name="cleanall"/>

  <target name="javac" depends="libs" description="Compile java source to bytecode">
    <echo message="${ant.project.name}: ${ant.file}"/>
    <mkdir dir="war/WEB-INF/classes"/>
    <javac
      srcdir="src"
      includes="**"
      encoding="utf-8"
      destdir="war/WEB-INF/classes"
      source="${source}"
      target="${target}"
      nowarn="true"
      debug="true"
      debuglevel="${debuglevel}"
      includeantruntime="false"
    >
      <src path="src"/>
      <src path="test"/>
      <classpath refid="edu.nrao.dss"/>
    </javac>
    <copy todir="war/WEB-INF/classes">
      <fileset dir="src" excludes="**/*.java"/>
    </copy>
  </target>

  <target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
      <classpath>
      <pathelement location="src"/>
      <path refid="edu.nrao.dss"/>
      <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar" />
      <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar" />
      </classpath>
      <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
      <jvmarg value="-Xmx1024M"/>
      <arg line="-war"/>
      <arg value="war"/>
      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
      <arg line="${gwt.args}"/>
      <arg value="edu.nrao.dss.Calculator_ui"/>
    </java>
  </target>

  <target name="devmode" depends="javac" description="Run development mode">
  <java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
    <classpath>
    <pathelement location="src"/>
    <path refid="edu.nrao.dss"/>
    <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar" />
    <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar" />
    </classpath>
    <jvmarg value="-Xmx1024M"/>
    <arg value="-startupUrl"/>
    <arg value="Calculator_ui.html"/>
    <arg line="-war"/>
    <arg value="war"/>
    <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
    <arg line="${gwt.args}"/>
    <arg value="-logLevel"/>
    <arg value="DEBUG"/>
    <arg value="-port"/>
    <arg value="${env.NUBBLES_PORT}"/>
    <arg value="-bindAddress"/>
    <arg value="0.0.0.0"/>

    <arg value="edu.nrao.dss.Calculator_ui"/>
  </java>
  </target>

   <target name="javac.tests" depends="javac" description="Compiles test code">
    <javac
      srcdir="test"
      includes="**"
      encoding="utf-8"
      source="${source}"
      target="${target}"
      nowarn="true"
      destdir="war/WEB-INF/classes"
      debug="true"
      debuglevel="${debuglevel}"
      includeantruntime="false"
    >
      <classpath location="${junit}/"/>
      <classpath refid="edu.nrao.dss"/>
    </javac>
  </target>
  
  <target name="test.dev" depends="javac.tests" description="Run development mode tests">
    <mkdir dir="reports/htmlunit.dev" />
    <junit fork="yes" printsummary="yes" haltonfailure="no">
      <jvmarg line="-Xmx1024m" />
      <sysproperty key="gwt.args" value="-standardsMode -logLevel DEBUG" />
      <sysproperty key="java.awt.headless" value="true" />
      <classpath>
        <pathelement location="src" />
        <pathelement location="test" />
        <path refid="edu.nrao.dss" />
        <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar" />
        <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar" />
        <!-- <pathelement location="${junit}/junit-4.5.jar" /> -->
      </classpath>
      <batchtest todir="reports/htmlunit.dev" >
        <fileset dir="test" >
          <include name="**/Test*.java" />
          <exclude name="**/TestGeneralForm.java" />
        </fileset>
      </batchtest>
      <formatter type="plain" />
      <formatter type="xml" />
    </junit>
  </target>

  <target name="test.prod" depends="javac.tests" description="Run production mode tests">
    <mkdir dir="reports/htmlunit.prod" />
    <junit fork="yes" printsummary="yes" haltonfailure="no">
      <jvmarg line="-Xmx1024m" />
      <sysproperty key="gwt.args" value="-prod -standardsMode -logLevel DEBUG -standardsMode -out www-test" />
      <sysproperty key="java.awt.headless" value="true" />
      <classpath>
        <pathelement location="src" />
        <pathelement location="test" />
        <path refid="edu.nrao.dss" />
        <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar" />
        <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar" />
        <!-- <pathelement location="${junit}/junit-4.5.jar" /> -->
      </classpath>
      <batchtest todir="reports/htmlunit.prod" >
        <fileset dir="test" >
          <include name="**/Test*.java" />
          <exclude name="**/TestGeneralForm.java" />
        </fileset>
      </batchtest>
      <formatter type="plain" />
      <formatter type="xml" />
    </junit>
  </target>

  <target name="test" description="Run development and production mode tests">
    <antcall target="test.dev" />
    <antcall target="test.prod" />
  </target>
</project>
