<project name="gwt">

  <property name="gwt.version" value="1.6.1" />
  <property name="gwt.baseurl"
      value="http://google-web-toolkit.googlecode.com/files" />

  <!-- GWT requires either windows, linux, or mac -->
  <condition property="gwt.platform" value="windows">
    <os family="windows" />
  </condition>
  <condition property="gwt.platform" value="mac">
    <and>
      <os family="unix" />
      <contains string="${os.name}" substring="mac" casesensitive="false" />
    </and>
  </condition>
  <!-- If we're not on windows or mac, assume it's linux since that will
       generally work for most unix platforms. -->
  <property name="gwt.platform" value="linux" />

  <!-- Determine the archive type for GWT -->
  <condition property="gwt.usezip">
    <equals arg1="${gwt.platform}" arg2="windows" />
  </condition>
  <condition property="gwt.usetgz">
    <equals arg1="${gwt.platform}" arg2="mac" />
  </condition>
  <condition property="gwt.usetbz2">
    <equals arg1="${gwt.platform}" arg2="linux" />
  </condition>

  <!-- Determine the right suffix for the file download of GWT. -->
  <condition property="gwt.suffix" value=".zip">
    <isset property="gwt.usezip" />
  </condition>
  <condition property="gwt.suffix" value=".tar.gz">
    <isset property="gwt.usetgz" />
  </condition>
  <property name="gwt.suffix" value=".tar.bz2" />

  <property name="gwt.destdir" value=".."/>

  <property name="gwt.filename"
      value="gwt-${gwt.platform}-${gwt.version}${gwt.suffix}" />
  <property name="gwt.url"
      value="${gwt.baseurl}/${gwt.filename}" />

  <property name="gwt.sdk.dir" location="${gwt.destdir}/gwt-${gwt.platform}-${gwt.version}" />

  <macrodef name="compile.gwtc">
    <attribute name="module" />
    <attribute name="srcdir" default="src" />
    <attribute name="wardir" />
    <attribute name="classpathref" />
    <sequential>
      <java dir="@{srcdir}"
          classname="com.google.gwt.dev.Compiler"
          classpathref="@{classpathref}"
          fork="yes"
          failonerror="true">
        <jvmarg value="-Xmx512M"/>
        <arg value="-war" />
        <arg file="@{wardir}" />
        <arg value="@{module}" />
      </java>
    </sequential>
  </macrodef>

  <target name="gwt.checkdistro">
    <available file="${gwt.sdk.dir}/gwt-user.jar"
        property="gwt.isavailable" />
    <fail unless="gwt.isavailable"
      message="You need to download GWT ${gwt.version}, run: ant get-gwt or see README" />
  </target>

  <target name="gwt.unzip" if="gwt.usezip">
    <unzip src="${gwt.filename}" dest="${gwt.destdir}" />
  </target>

  <target name="gwt.untgz" if="gwt.usetgz">
    <untar src="${gwt.filename}" dest="${gwt.destdir}" compression="gzip" />
  </target>

  <target name="gwt.untbz2" if="gwt.usetbz2">
    <untar src="${gwt.filename}" dest="${gwt.destdir}" compression="bzip2" />
  </target>

  <target name="get-gwt">
    <get src="${gwt.url}" dest="${gwt.filename}" />
    <antcall target="gwt.unzip" />
    <antcall target="gwt.untgz" />
    <antcall target="gwt.untbz2" />
  </target>

</project>
