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

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

  <path id="project.class.path">
    <pathelement location="war/WEB-INF/classes"/>
    <pathelement location="${gwt.sdk}/gwt-user.jar"/>
    <pathelement location="${gwt.sdk}/gwt-dev.jar"/>
    <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar"/>
    <pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar"/>
    <fileset dir="war/WEB-INF/lib" includes="**/*.jar"/>
    <!-- Add any additional non-server libs (such as JUnit) here -->
  </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 -->
  </target>

  <target name="javac" depends="libs" description="Compile java source to bytecode">
    <mkdir dir="war/WEB-INF/classes"/>
    <javac srcdir="src" includes="**" encoding="utf-8"
        destdir="war/WEB-INF/classes"
        source="1.7" target="1.7" nowarn="true"
        debug="true" debuglevel="lines,vars,source">
      <classpath refid="project.class.path"/>
    </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" maxmemory="256m">
      <classpath>
        <pathelement location="src"/>
        <path refid="project.class.path"/>
      </classpath>
      <arg line="-war"/>
      <arg value="war"/>
      <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
      <arg line="${gwt.args}"/>
      <arg value="com.google.gwt.sample.hello.Hello"/>
    </java>
  </target>

  <target name="devmode" depends="javac" description="Run development mode (pass -Dgwt.args=-nosuperDevMode to fallback to classic DevMode)">
    <java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode" maxmemory="1g">
      <classpath>
        <pathelement location="src"/>
        <path refid="project.class.path"/>
        <pathelement location="${gwt.sdk}/gwt-codeserver.jar"/>
      </classpath>
      <arg value="-startupUrl"/>
      <arg value="Hello.html"/>
      <arg line="-war"/>
      <arg value="war"/>
      <!-- Additional arguments like -style PRETTY, -logLevel DEBUG or -nosuperDevMode -->
      <arg line="${gwt.args}"/>
      <arg value="com.google.gwt.sample.hello.Hello"/>
      <arg value="com.google.gwt.sample.hello.Hello"/>
    </java>
  </target>

  <target name="eclipse.generate" depends="libs" description="Generate eclipse project">
    <java failonerror="true" fork="true" classname="com.google.gwt.user.tools.WebAppCreator">
      <classpath>
        <path refid="project.class.path"/>
      </classpath>
      <arg value="-XonlyEclipse"/>
      <arg value="-ignore"/>
      <arg value="com.google.gwt.sample.hello.Hello"/>
    </java>
  </target>

<!--
Test targets suppressed because -junit argument was not specified when running webAppCreator.

  <target name="javac.tests" depends="javac" description="Compiles test code">
    <javac srcdir="test" includes="**" encoding="utf-8"
      source="1.7" target="1.7" nowarn="true"
      destdir="war/WEB-INF/classes"
      debug="true" debuglevel="lines,vars,source">
      <classpath location="path_to_the_junit_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" maxmemory="256m">
      <sysproperty key="gwt.args" value="-logLevel WARN -war www-test" />
      <sysproperty key="java.awt.headless" value="true" />
      <classpath>
        <pathelement location="src" />
        <pathelement location="test" />
        <path refid="project.class.path" />
        <pathelement location="../../validation-api-1.0.0.GA.jar" />
        <pathelement location="../../validation-api-1.0.0.GA-sources.jar" />
        <pathelement location="path_to_the_junit_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" maxmemory="256m">
      <sysproperty key="gwt.args" value="-prod -logLevel WARN -war www-test" />
      <sysproperty key="java.awt.headless" value="true" />
      <classpath>
        <pathelement location="src" />
        <pathelement location="test" />
        <path refid="project.class.path" />
        <pathelement location="../../validation-api-1.0.0.GA.jar" />
        <pathelement location="../../validation-api-1.0.0.GA-sources.jar" />
        <pathelement location="path_to_the_junit_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="build" depends="gwtc" description="Build this project" />

  <target name="war" depends="build" description="Create a war file">
    <zip destfile="Hello.war" basedir="war"/>
  </target>

  <target name="clean" description="Cleans this project">
    <delete dir="war/WEB-INF/classes" failonerror="false" />
    <delete dir="war/hello" failonerror="false" />
  </target>

</project>
