<project default="jar">
    <property name="jar_file" value="../java_console_binary/rusefi_console.jar"/>

    <target name="clean">
        <delete dir="build"/>
    </target>

    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac debug="yes" destdir="build/classes"
               classpath="lib/jcip-annotations-1.0.jar:lib/jlatexmath-1.0.3.jar:lib/swing-layout-1.0.jar:lib/jep.jar:lib/log4j.jar:lib/junit.jar:lib/jssc.jar:lib/SteelSeries-3.9.30.jar:lib/annotations.jar:lib/miglayout-4.0.jar:lib/surfaceplotter-2.0.1.jar">
            <src path="autotest/src"/>
            <src path="io/src"/>
            <src path="models/src"/>
            <src path="ui/src"/>
            <src path="romraider/src"/>
            <src path="logging/src"/>
		<!-- not really used at the moment but let's compile for the sake of Eclipse users -->
            <src path="tools/src"/>
        </javac>

        <junit fork="no"
               maxmemory="512m"
               printsummary="yes"
               haltonfailure="yes">

            <jvmarg value="-ea"/>
            <jvmarg value="-XX:+HeapDumpOnOutOfMemoryError"/>
            <formatter type="brief"/>
            <classpath path="lib/jssc.jar:build/classes:lib/junit.jar:lib/SteelSeries-3.9.30.jar"/>
            <batchtest todir="build">
                <fileset dir="autotest/src" includes="**/test/**/*Test.java"/>
                <fileset dir="io/src" includes="**/test/**/*Test.java"/>
                <fileset dir="models/src" includes="**/test/**/*Test.java"/>
                <fileset dir="ui/src" includes="**/test/**/*Test.java"/>
                <fileset dir="romraider/src" includes="**/test/**/*Test.java"/>
                <fileset dir="logging/src" includes="**/test/**/*Test.java"/>
            </batchtest>
        </junit>

    </target>

    <target name="jar" depends="compile">
        <mkdir dir="build/jar"/>
        <delete file="${jar_file}"/>
        <echo message="Building ${jar_file}"/>

        <copy todir="build/classes">
            <fileset dir="ui/resources" includes="**/*.gif"/>
            <fileset dir="ui/resources" includes="**/*.png"/>
            <fileset dir="ui/resources" includes="**/*.jpg"/>
            <fileset dir="romraider/resources" includes="**/*.*"/>
        </copy>

        <tstamp>
            <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
        </tstamp>

        <jar destfile="${jar_file}" basedir="build/classes">
            <manifest>
                <attribute name="Main-Class" value="com.rusefi.Launcher"/>
                <attribute name="Built-Date" value="${TODAY}"/>
                <attribute name="Signature-Vendor" value="rusEfi LLC"/>
            </manifest>
            <zipfileset src="lib/SteelSeries-3.9.30.jar" includes="**/*.class"/>
            <zipfileset src="lib/trident-6.2.jar" includes="**/*.class"/>
            <zipfileset src="lib/swing-layout-1.0.jar" includes="**/*.class"/>
            <zipfileset src="lib/log4j.jar" includes="**/*.class"/>
            <zipfileset src="lib/jep.jar" includes="**/*.class"/>
            <zipfileset src="lib/jssc.jar" includes="**/*.class **/*.so **/*.dll **/*.jnilib"/>
            <zipfileset src="lib/annotations.jar" includes="**/*.class"/>
            <zipfileset src="lib/miglayout-4.0.jar" includes="**/*.class"/>
            <zipfileset src="lib/surfaceplotter-2.0.1.jar" includes="**/*.class **/*.properties"/>
            <zipfileset src="lib/batik/batik-svggen.jar" includes="**/*.class"/>
            <zipfileset src="lib/batik/batik-awt-util.jar" includes="**/*.class"/>
            <zipfileset src="lib/batik/batik-util.jar" includes="**/*.class"/>
            <zipfileset src="lib/jlatexmath-1.0.3.jar" includes="**/*.class **/*.xml **/*.ttf"/>
        </jar>
    </target>

    <target name="run" depends="jar">
        <java jar="${jar_file}" fork="true"/>
    </target>

    <target name="autotest" depends="jar">
        <java classpath="${jar_file}" classname="com.rusefi.AutoTest" failonerror="true">
        </java>

    </target>

    <!--todo: rename this task to something more specific like RunRealHardwareTestSuite & sync Jenkin instances-->
    <target name="realtest" depends="jar">
        <java classpath="${jar_file}" classname="com.rusefi.RealHwTest" failonerror="true">
        </java>
    </target>

    <target name="before_IDEA_Build">
        <copy todir=".">
            <fileset dir="../firmware/tunerstudio" includes="rusefi.ini"/>
        </copy>

    </target>
</project>