<?xml version="1.0" encoding="utf-8" ?>
<project name="UI" default="build" basedir=".">
  <!-- Arguments to gwtc and devmode targets -->
  <property name="gwt.args" value="" />

  <!-- Arguments to gwtc and devmode targets -->
    <property name="out.war.path" value="war" />
    <property name="out.base.path" value="war/WEB-INF" />
    <property name="out.classes.path" value="${out.base.path}/classes" />
    <property name="out.lib.path" value="${out.base.path}/lib" />

  <!-- Configure path to GWT SDK -->
  <property name="gwt.sdk" location="/opt/gwt-2.6.1" />

  <path id="project.class.path">
    <pathelement location="${out.classes.path}"/>
    <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="${out.lib.path}" includes="**/*.jar"/>
    <fileset dir="lib" includes="**/*.jar"/>
  </path>

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

  <target name="javac" depends="libs" description="Compile java source to bytecode">
    <mkdir dir="${out.classes.path}"/>
    <javac srcdir="src" includes="**" encoding="utf-8"
        destdir="${out.classes.path}"
        source="1.5" target="1.5" nowarn="true"
        debug="true" debuglevel="lines,vars,source">
      <classpath refid="project.class.path"/>
    </javac>
    <copy todir="${out.classes.path}">
      <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="project.class.path"/>
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA.jar" />
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar" />
      </classpath>
      <!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
      <jvmarg value="-Xmx256M"/>
      <arg line="-war"/>
      <arg value="${out.war.path}"/>
      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
      <arg line="${gwt.args}"/>
      <arg value="com.dldinternet.aws.cfn.stacker.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="project.class.path"/>
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA.jar" />
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar" />
      </classpath>
      <jvmarg value="-Xmx256M"/>
      <arg value="-startupUrl"/>
      <arg value="UI.html"/>
      <arg line="-war"/>
      <arg value="${out.war.path}"/>
      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
      <arg line="${gwt.args}"/>
      <arg value="com.dldinternet.aws.cfn.stacker.UI"/>
    </java>
  </target>

  <target name="superdevmode" depends="javac" description="Run Super Dev Mode">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.codeserver.CodeServer">
      <classpath>
        <pathelement location="src"/>
        <pathelement location="/opt/gwt-2.6.1/gwt-codeserver.jar" />
        <path refid="project.class.path"/>
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA.jar" />
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar" />
      </classpath>
      <jvmarg value="-Xmx256M"/>
      <arg value="com.dldinternet.aws.cfn.stacker.UI"/>
    </java>
  </target>

  <target name="javac.tests" depends="javac" description="Compiles test code">
    <javac srcdir="test" includes="**" encoding="utf-8"
      source="1.5" target="1.5" nowarn="true"
      destdir="${out.classes.path}"
      debug="true" debuglevel="lines,vars,source">
      <classpath location="test/junit-4.11.jar"/>
      <classpath refid="project.class.path"/>
    </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="yes">
      <jvmarg line="-Xmx256m" />
      <sysproperty key="gwt.args" value="-standardsMode -logLevel WARN" />
      <sysproperty key="java.awt.headless" value="true" />
      <classpath>
        <pathelement location="src" />
        <pathelement location="test" />
        <path refid="project.class.path" />
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA.jar" />
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar" />
        <pathelement location="test/junit-4.11.jar" />
      </classpath>
      <batchtest todir="reports/htmlunit.dev" >
        <fileset dir="test" >
          <include name="**/*Test.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="yes">
      <jvmarg line="-Xmx256m" />
      <sysproperty key="gwt.args" value="-prod -standardsMode -logLevel WARN -standardsMode -war www-test" />
      <sysproperty key="java.awt.headless" value="true" />
      <classpath>
        <pathelement location="src" />
        <pathelement location="test" />
        <path refid="project.class.path" />
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA.jar" />
        <pathelement location="/opt/gwt-2.6.1/validation-api-1.0.0.GA-sources.jar" />
        <pathelement location="test/junit-4.11.jar" />
      </classpath>
      <batchtest todir="reports/htmlunit.prod" >
        <fileset dir="test" >
          <include name="**/*Test.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>

  <target name="hosted" depends="devmode" description="Run development mode (NOTE: the 'hosted' target is deprecated)" />

  <target name="build" depends="gwtc" description="Build this project" />

  <target name="war" depends="build" description="Create a war file">
    <zip destfile="UI.war" basedir="${out.war.path}"/>
  </target>

  <target name="clean" description="Cleans this project">
    <delete dir="${out.classes.path}" failonerror="false" />
    <delete dir="war/ui" failonerror="false" />
    <delete dir="war/UI" failonerror="false" />
  </target>

</project>