<?xml version="1.0" ?>

<project name="EditorConfigJava" default="all" basedir=".">

  <property name="tmp.dir" value="${basedir}/tmp" />
  <property name="editorconfig.py.dir" value="./.." />
  <property name="build.dir" value="./build" />

  <path id="jython.path">
    <pathelement location="${tmp.dir}/jython.jar" />
  </path>

  <!-- Build EditorConfig Java wrapper -->
  <target name="build-java-wrapper">
    <mkdir dir="./classes" />
    <javac srcdir="./src" destdir="./classes">
      <classpath refid="jython.path" />
    </javac>
  </target>

  <!-- Download jython installer -->
  <property name="jython.url" value="http://downloads.sourceforge.net/project/jython/jython/2.2.1/jython_installer-2.2.1.jar?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fjython%2Ffiles%2Fjython%2F2.2.1%2F&amp;ts=1338203268" />
  <target name="download-jython">
    <mkdir dir="${tmp.dir}" />
    <get src="${jython.url}" dest="${tmp.dir}/jython_installer.jar" usetimestamp="true" verbose="true" />
  </target>

  <!-- unpack jython installer -->
  <target name="unpack-jython" depends="download-jython">
    <java jar="${tmp.dir}/jython_installer.jar" fork="true">
      <arg value="-s" />
      <arg value="-v" />
      <arg value="-d" />
      <arg value="${tmp.dir}/install" />
      <arg value="-t" />
      <arg value="standalone" />
    </java>
    <move file="${tmp.dir}/install/jython.jar" todir="${tmp.dir}" />
  </target>

  <!-- pack jython EditorConfig -->
  <target name="pack-jython-editorconfig" depends="unpack-jython,build-java-wrapper">
    <mkdir dir="${build.dir}" />
    <jar destfile="${build.dir}/editorconfig.jar">
      <fileset dir="./classes">
        <include name="**/*.class" />
      </fileset>
      <zipfileset src="${tmp.dir}/jython.jar" />
      <zipfileset dir="${editorconfig.py.dir}" prefix="Lib/">
        <include name="editorconfig/**.py" />
      </zipfileset>
      <fileset file="./README.md" />
      <fileset file="./LICENSE.txt" />
    </jar>
  </target>

  <target name="doc" depends="unpack-jython">
    <mkdir dir="./doc" />
    <javadoc sourcepath="./src" destdir="./doc" locale="en_US"
      windowtitle="EditorConfig Java Library API Documentation"
      linksource="true" nodeprecatedlist="true">
      <classpath>
        <fileset file="${tmp.dir}/jython.jar" />
      </classpath>

      <link href="http://docs.oracle.com/javase/6/docs/api/" />
    </javadoc>
  </target>

  <target name="clean">
    <delete dir="build" />
    <delete dir="classes" />
    <delete dir="tmp" />
  </target>

  <target name="all" depends="pack-jython-editorconfig">
  </target>
</project>
