<?xml version="1.0" encoding="UTF-8"?>

<!-- Build file for Juggling Lab. -->
<!-- For use with the Apache Ant Java build tool (http://ant.apache.org) -->

<project name="JugglingLab" default="jar" basedir=".">

    <property name="src" value="source" />
    <property name="build" value="build" />
    <property name="bin" value="bin" />
    <property name="debug" value="off" />
    <property name="deprecation" value="on" />

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

    <target name="compile" depends="init">
        <javac debug="${debug}" srcdir="${src}/." destdir="${build}/." target="1.5" source="1.5" deprecation="${deprecation}" includeAntRuntime="false" includes="**" excludes="jugglinglab/MacOS/PlatformSpecificMacOS.java,resources/*,resources_osx/*,dox.conf,jugglinglab/notation/*.jj">
        </javac>
    </target>

    <!-- This target is the main Juggling Lab jar file -->
    <target name="jar" depends="compile">
        <jar index="yes" destfile="${bin}/JugglingLab.jar">
            <manifest>
                <attribute name="Main-Class" value="JugglingLab" />
            </manifest>
            <fileset dir="${build}" excludes="Organizer*,jugglinglab/MacOS/*,jugglinglab/MacOS" />
            <fileset dir="${src}/resources" includes="GUIStrings*" />
            <fileset dir="${src}/resources" includes="ErrorStrings*" />
            <fileset dir="${src}" includes="resources/*.au" />
            <fileset dir="${src}" includes="resources/*.gif" />
            <fileset dir="${src}" includes="resources/*.png" />
        </jar>
    </target>
    
    <!-- This target executes only if invoked with something like 'ant signjar -Dkeystore=keystorepath -Dstorepass=password' -->
    <target name="signjar" if="storepass,keystore" depends="jar">
        <signjar jar="${bin}/JugglingLab.jar" signedjar="${bin}/SignedJugglingLab.jar" alias="jlkey" keystore="${keystore}" storepass="${storepass}" />
    </target>

    <!-- Run the application -->
    <target name="run" depends="jar" description="Run the application">
        <java jar="${bin}/JugglingLab.jar" fork="true" />
    </target>

    <!-- Clean up -->
    <target name="clean" description="Remove build directory">
        <delete dir="${build}" />
        <delete file="${bin}/JugglingLab.jar" />
    </target>


    <!-- Build the Windows executables using launch4j -->
    <property name="launch4j.dir" location="../launch4j" />

    <target name="exe" depends="jar" description="Make Windows executables">
        <taskdef name="launch4j" classname="net.sf.launch4j.ant.Launch4jTask" classpath="${launch4j.dir}/launch4j.jar
        :${launch4j.dir}/lib/xstream.jar" />
        <launch4j configFile="./source/resources_win/Juggling Lab.xml" />
        <launch4j configFile="./source/resources_win/j2.xml" />
    </target>


    <!-- This target builds the Mac OS X application -->
    <!-- It won't work on non-Mac machines because the Apple stub executable below is missing -->
    <property name="resources_macosx" location="${src}/resources_osx" />
    <property name="apple.appstub" location="/System/Library/Frameworks/JavaVM.framework/Resources/MacOS/JavaApplicationStub" />
    <property name="application" location="./Juggling Lab.app" />
    <property name="application.macos" location="${application}/Contents/MacOS" />
    <property name="application.macos.stub" location="${application}/Contents/MacOS/Juggling Lab" />
    <property name="application.resources" location="${application}/Contents/Resources" />
    <property name="application.resources.java" location="${application}/Contents/Resources/Java" />

    <target name="osx" depends="compile" description="Make a double-clickable Mac OS X application">
        <javac debug="${debug}" srcdir="${src}/." destdir="${build}/." target="1.5" source="1.5"
        deprecation="yes" includeAntRuntime="false" includes="jugglinglab/MacOS/*.java" />

        <mkdir dir="${application.resources.java}" />
        <mkdir dir="${application.macos}" />
        <!-- put jar into application -->
        <jar index="yes" destfile="${application.resources.java}/JugglingLab.jar">
            <manifest>
                <attribute name="Main-Class" value="JugglingLab" />
            </manifest>
            <fileset dir="${build}" excludes="Organizer*" />
            <fileset dir="${src}/resources" includes="GUIStrings*" />
            <fileset dir="${src}/resources" includes="ErrorStrings*" />
            <fileset dir="${src}" includes="resources/*.au" />
            <fileset dir="${src}" includes="resources/*.gif" />
            <fileset dir="${src}" includes="resources/*.png" />
        </jar>
        <!-- copy application stub -->
        <copy file="${apple.appstub}" toFile="${application.macos}/Juggling Lab" />
        <!-- fix stub permissions -->
        <exec executable="/bin/chmod">
            <arg line="755 '${application.macos.stub}'" />
        </exec>		
        <!-- copy Info.plist -->
        <copy file="${resources_macosx}/Info.plist" toFile="${application}/Contents/Info.plist" />
        <!-- copy PkgInfo -->
        <copy file="${resources_macosx}/PkgInfo" toFile="${application}/Contents/PkgInfo" />
        <!-- copy icons -->
        <copy toDir="${application.resources}">
            <fileset dir="${resources_macosx}">
                <include name="*.icns" />
            </fileset>			
        </copy>
    </target>

</project>
