<?xml version="1.0" encoding="UTF-8"?>
<project name="jnacontrib.x11" default="jar" basedir=".">
    <description>Builds, tests, and runs the project jnacontrib.x11.</description>
    <!-- Locations -->
    <property name="src"                location="src"/>
    <property name="build"              location="build"/>
    <property name="jna-src"            location="../../src"/>
    <property name="jna-dist"           location="../../dist"/>
    <property name="classes"       location="${build}/classes"/>
    <property name="jar"           location="${build}/demo-x11.jar"/>
    <property name="file.reference.jna.jar" location="../../build/jna.jar"/>

    <path id="classpath">
        <fileset file="${file.reference.jna.jar}"/>
        <fileset dir="../platform/dist" includes="jna-platform.jar"/>
    </path>

    <!-- Run XDesktopDemo. -->
    <target name="runXDesktopDemo" depends="compile">
        <java classname="jnacontrib.x11.demos.XDesktopDemo" fork="true">
            <classpath>
                <pathelement location="${classes}" />
                <path refid="classpath"/>
            </classpath>
        </java>
    </target>

    <!-- Run XTestDemo. -->
    <target name="runXTestDemo" depends="compile">
        <java classname="jnacontrib.x11.demos.XTestDemo" fork="true">
            <classpath>
                <pathelement location="${classes}" />
                <path refid="classpath"/>
            </classpath>
        </java>
    </target>

    <!-- Delete class and jar files. -->
    <target name="clean">
        <delete dir="${classes}"/>
        <delete file="${jar}"/>
        <delete dir="${build}"/>
    </target>

    <!-- Compile all classes. -->
    <target name="compile">
        <mkdir dir="${classes}"/>
        <!-- Compile the project. -->
        <javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5"
               encoding="UTF-8" debug="on" includeantruntime="false">
            <classpath>
                <path refid="classpath"/>
            </classpath>
        </javac>
    </target>

    <!-- Create jar-file. -->
    <target name="jar" depends="compile">

        <!-- Copy all non-java files to classes. -->
        <copy todir="${classes}">
            <fileset dir="${src}">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>

        <jar jarfile="${jar}" basedir="${classes}">
            <manifest>
                <attribute name="Main-Class" value="jnacontrib.x11.demos.XDesktopDemo"/>
            </manifest>
            <!-- platform -->
            <fileset dir="../platform/build/classes"/>
            <!-- jna -->
            <zipfileset src="${file.reference.jna.jar}"/>
        </jar>
    </target>
</project>
