<?xml version="1.0" encoding="UTF-8"?>
<project name="DMDirc-installer" default="default" basedir=".">
    <description>Tasks to build the DMDirc installer.</description>

    <target name="-init-installer" depends="init">
        <taskdef name="nsis" classname="com.danielreese.nsisant.Task">
            <classpath>
                <fileset dir="lib/build" includes="*nsis*.jar"/>
            </classpath>
        </taskdef>

        <taskdef name="git-describe" classname="org.mdonoughe.JGitDescribeTask">
            <classpath>
                <fileset dir="lib/build" includes="*jgit*.jar"/>
           </classpath>
        </taskdef>
    </target>

    <target name="installer" depends="-init-installer"
            description="Build the installer.">
        <exec executable="bash" dir="modules/installer" resultproperty="installer.result">
            <arg value="makeAll.sh"/>
        </exec>

        <condition property="installer.success">
            <equals arg1="${installer.result}" arg2="0" />
        </condition>

        <echo message="Installer build finished."/>
        <echo message="Completed build files can be found in:"/>
        <echo message="    ./modules/installer/output"/>
        <echo message=""/>
    </target>

    <target name="installer-stable" depends="-init-installer"
            description="Build the installer for a stable release.">
        <exec executable="bash" dir="modules/installer" resultproperty="installer.result">
            <arg value="makeAll.sh"/>
            <arg value="-c"/>
            <arg value="STABLE"/>
            <arg value="--upload"/>
        </exec>

        <condition property="installer.success">
            <equals arg1="${installer.result}" arg2="0" />
        </condition>

        <echo message="Installer build finished."/>
        <echo message="Completed build files can be found in:"/>
        <echo message="    ${installer.output.dir}"/>
        <echo message=""/>
    </target>

    <target name="installer-unstable" depends="-init-installer"
            description="Build the installer for an unstable release.">
        <exec executable="bash" dir="modules/installer" resultproperty="installer.result">
            <arg value="makeAll.sh"/>
            <arg value="-c"/>
            <arg value="UNSTABLE"/>
        </exec>

        <condition property="installer.success">
            <equals arg1="${installer.result}" arg2="0" />
        </condition>

        <echo message="Installer build finished."/>
        <echo message="Completed build files can be found in:"/>
        <echo message="    ./modules/installer/output"/>
        <echo message=""/>
    </target>

    <target name="installer-nsis" description="Builds the Windows installer"
        depends="-init-installer,jar">
       <git-describe dir="modules/installer/.git" property="version.git.nsis" subdir="windows" />

        <mkdir dir="modules\installer\windows\files\" />
        <mkdir dir="modules\installer\output\" />
        <delete>
            <fileset dir="modules\installer\windows\files\" includes="*.*"/>
        </delete>
        <copy file="src/com/dmdirc/res/icon.ico"
            tofile="modules\installer\windows\files\icon.ico"
            overwrite="true" />
        <copy file="dist/DMDirc.jar"
            tofile="modules\installer\windows\files\DMDirc.jar"
            overwrite="true" />
        <nsis script="modules\installer\windows\updater.nsi" verbosity="1">
            <define name="VERSION" value="${version.git.nsis}"/>
        </nsis>
        <nsis script="modules\installer\windows\launcher.nsi" verbosity="1">
            <define name="VERSION" value="${version.git.nsis}"/>
        </nsis>
        <nsis script="modules\installer\windows\installer.nsi" verbosity="1">
            <define name="VERSION" value="${version.git.nsis}"/>
        </nsis>
        <delete dir="modules\installer\windows\files" />
    </target>

</project>
