<?xml version="1.0" encoding="UTF-8"?>
<project name="DMDirc" default="default" basedir=".">
    <description>Builds, tests, and runs the project DMDirc.</description>

    <import file="nbproject/build-impl.xml"/>
    <import file="build-installer.xml"/>
    <import file="build-paths.xml"/>
    <import file="build-plugins.xml"/>
    <import file="build-reports.xml"/>
    <import file="build-tests.xml"/>
    <import file="build-versioning.xml"/>
    <import file="build-properties.xml"/>
    <import file="build-ivy.xml"/>

    <target name="-init-lib-directory">
        <mkdir dir="lib"/>
    </target>

    <target name="init-private" depends="-init-lib-directory">
        <echo>Downloading private files, if this fails please pass username and</echo>
        <echo>password to ant using -Dusername=... -Dpassword=...</echo>

        <get src="http://www.dmdirc.com/private/clover.license" dest="etc/clover.license" username="${username}" password="${password}"/>

        <get dest="installer/signing/" username="${username}" password="${password}">
            <url url="http://www.dmdirc.com/private/DMDirc.cer"/>
            <url url="http://www.dmdirc.com/private/DMDirc.pvk"/>
            <url url="http://www.dmdirc.com/private/DMDirc.spc"/>
        </get>

	<get dest="addons.api.key" username="${username}" password="${password}" src="http://www.dmdirc.com/private/addons.api.key"/>

        <!-- Re-evaluate as the license is probably here now -->
        <condition property="clover.installed">
            <and>
                <available classname="com.cenqua.clover.CloverInstr"/>
                <available file="etc/clover.license"/>
            </and>
        </condition>
    </target>

    <target name="-post-clean">
        <delete dir="modules/plugins/build"/>
        <delete dir="modules/plugins/dist"/>
        <delete dir="modules/parser/build"/>
        <delete dir="modules/parser/dist"/>
        <delete dir="modules/util/build"/>
        <delete dir="modules/util/dist"/>
    </target>

    <target name="-bundle-slf4j">
        <jar destfile="${dist.jar}" update="true">
            <zipfileset src="lib/main/slf4j-api.jar" includes="org/slf4j/**/*"/>
        </jar>
    </target>

    <target name="-bundle-dagger">
        <jar destfile="${dist.jar}" update="true">
            <zipfileset src="lib/main/dagger.jar" includes="dagger/**"/>
            <zipfileset src="lib/main/javax.inject.jar" includes="javax/inject/*"/>
        </jar>
    </target>

    <target name="-init-submodule-dependencies">
        <subant buildpath="modules/plugins" target="init-dependencies"/>
    </target>

    <target name="-pre-init" depends="-init-dependencies,-init-submodule-dependencies,-init-private-properties"/>
    <target name="-post-compile" depends="-write-version, build-plugins"/>
    <target name="-post-test-run" depends="-do-test-reports"/>
    <target name="-post-jar" depends="-update-bundled-plugins,-bundle-slf4j,-bundle-dagger"/>

</project>
