<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="all" name="systray">
    <target name="all" depends="clean, build" />
    <target name="build" depends="builddep, jar" />
    <target name="builddep">
        <!-- run from top level build.xml to get dependencies built -->
    </target>
    <condition property="depend.available">
        <typefound name="depend" />
    </condition>
    <target name="depend" if="depend.available">
        <depend
            cache="../../../build"
            srcdir="./src:./test/junit"
            destdir="./build/obj" >
            <!-- Depend on classes instead of jars where available -->
            <classpath>
                <pathelement location="../../../core/java/build/obj" />
            </classpath>
        </depend>
    </target>

    <!-- only used if not set by a higher build.xml -->
    <property name="javac.compilerargs" value="" />
    <property name="javac.version" value="1.8" />
    <property name="javac.release" value="8" />
    <property name="manifest.classpath.name" value="Class-Path" />

    <target name="compile" depends="depend">
        <mkdir dir="./build" />
        <mkdir dir="./build/obj" />
        <javac
            srcdir="./src"
            debug="true"
            deprecation="on"
            source="${javac.version}"
            target="${javac.version}"
            release="${javac.release}"
            destdir="./build/obj"
            includeAntRuntime="false"
            encoding="UTF-8"
            includes="**/*.java"
            classpath="../../../core/java/build/i2p.jar" >
            <compilerarg line="${javac.compilerargs}" />
        </javac>
    </target>

    <target name="listChangedFiles" depends="jarUpToDate" if="shouldListChanges" >
        <exec executable="git" outputproperty="workspace.changes" errorproperty="mtn.error2" failifexecutionfails="false" >
            <arg value="status" />
            <arg value="-s" />
            <arg value="--porcelain" />
            <arg value="-uno" />
            <arg value="." />
        </exec>
        <!-- trim flags -->
        <exec executable="sed" inputstring="${workspace.changes}" outputproperty="workspace.changes.sed" errorproperty="mtn.error2" failifexecutionfails="false" >
            <arg value="-e" />
            <arg value="s/^[MTADRCU ]*//" />
        </exec>
        <!-- \n in an attribute value generates an invalid manifest -->
        <exec executable="tr" inputstring="${workspace.changes.sed}" outputproperty="workspace.changes.tr" errorproperty="mtn.error2" failifexecutionfails="false" >
            <arg value="-s" />
            <arg value="[:space:]" />
            <arg value="," />
        </exec>
    </target>

    <target name="jar" depends="compile, jarUpToDate, listChangedFiles" unless="jar.uptodate">
        <!-- set if unset -->
        <property name="workspace.changes.tr" value="" />
        <jar destfile="./build/systray.jar" basedir="./build/obj" includes="**/*.class">
            <manifest>
                <attribute name="${manifest.classpath.name}" value="i2p.jar" />
                <attribute name="Implementation-Version" value="${full.version}" />
                <attribute name="Built-By" value="${build.built-by}" />
                <attribute name="Build-Date" value="${build.timestamp}" />
                <attribute name="Base-Revision" value="${workspace.version}" />
                <attribute name="Workspace-Changes" value="${workspace.changes.tr}" />
                <attribute name="X-Compile-Source-JDK" value="${javac.version}" />
                <attribute name="X-Compile-Target-JDK" value="${javac.version}" />
            </manifest>
        </jar>
    </target>

    <target name="jarUpToDate">
        <uptodate property="jar.uptodate" targetfile="./build/systray.jar">
            <srcfiles dir= "build/obj" includes="**/*.class" />
        </uptodate>
        <condition property="shouldListChanges" >
            <and>
                <not>
                    <isset property="jar.uptodate" />
                </not>
                <isset property="git.available" />
            </and>
        </condition>
    </target>

    <target name="javadoc">
        <mkdir dir="./build" />
        <mkdir dir="./build/javadoc" />
        <javadoc
            sourcepath="./src"
            classpath="./src"
            destdir="./build/javadoc"
            packagenames="*"
            use="true"
            access="package"
            splitindex="true" />
    </target>
    <target name="clean">
        <delete dir="./build" />
    </target>
    <target name="cleandep" depends="clean">
    </target>
    <target name="distclean" depends="clean">
    </target>
</project>
