<project name="libtiled-java" default="jar">

  <description>
    A small Java library to load Tiled maps.
  </description>

  <property name="src" location="src"/>
  <property name="test" location="test"/>
  <property name="lib" location="lib"/>
  <property name="build" location="build/java"/>
  <property name="build.test" location="build/test"/>
  <property name="javadoc" location="javadoc"/>

  <path id="classpath"></path>
  <path id="classpath.test">
    <path refid="classpath" />
    <path location="${build.test}"/>
    <fileset dir="${lib}" includes="**/*.jar" />
  </path>

  <presetdef name="javac">
    <!-- Get rid of some warnings when running javac -->
    <javac includeantruntime="false" encoding="utf-8" />
  </presetdef>

  <target name="init">
    <tstamp/>
    <mkdir dir="${build}"/>
    <mkdir dir="${build.test}"/>
  </target>

  <target name="test" depends="init" description="Run all unit-tests">
    <javac destdir="${build.test}" debug="true" source="1.5" target="1.5">
      <src path="${src}" />
      <src path="${test}" />
      <classpath refid="classpath.test"/>
    </javac>
    <copy todir="${build.test}/tiled/io/resources">
      <fileset dir="${test}/tiled/io/resources" />
    </copy>
    <junit printsummary="yes" haltonfailure="yes" showoutput="yes" fork="yes">
      <classpath refid="classpath.test"/>
      <formatter type="brief" usefile="false"/>
      <batchtest>
        <fileset dir="${test}">
          <include name="**/*Test.java" />
        </fileset>
      </batchtest>
    </junit>
  </target>

  <target name="jar" depends="init" description="Build libtiled.jar">
    <javac destdir="${build}" source="1.5" target="1.5">
      <src path="${src}" />
      <classpath refid="classpath"/>
    </javac>
    <copy todir="${build}/tiled/io/resources">
      <fileset dir="${src}/tiled/io/resources">
        <include name="map.dtd" />
      </fileset>
    </copy>
    <jar jarfile="libtiled.jar" basedir="${build}"/>
  </target>

  <target name="clean" description="Clean up the build directory">
    <delete dir="${build}"/>
    <delete dir="${build.test}"/>
  </target>

  <target name="javadoc" description="Generate Javadoc">
    <!-- Clean up previous Javadoc files -->
    <delete dir="${javadoc}"/>

    <!-- Generate Javadoc -->
    <javadoc
      packagenames="tiled.*"
      sourcepath="${src}"
      destdir="${javadoc}"
      windowtitle="libtiled"
      />
  </target>

</project>
