<?xml version="1.0" encoding="utf-8"?>
<project name="turnrestrictions" default="dist" basedir=".">
    <!-- enter the SVN commit message -->
    <property name="commit.message" value="Adapt to JOSM core change (DefaultNameFormatter)"/>
    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    <property name="plugin.main.version" value="6340"/>

    <property name="test.build.dir" value="test/build"/>
    <property name="eclipse.plugin.dir" value="C:\software\eclipse-3.6.1\plugins"/>

    <!--
    **********************************************************
    ** include targets that all plugins have in common
    **********************************************************
    -->
    <import file="../build-common.xml"/>
  
    <!--
    **********************************************************
    ** init - initializes the build
    **********************************************************
    -->
    <target name="init">
        <mkdir dir="${plugin.build.dir}"/>
        <mkdir dir="${test.build.dir}"/>
    </target>

    <!--
    **********************************************************
    ** clean - clean up the build environment
    **********************************************************
    -->
    <target name="clean">
        <delete dir="${plugin.build.dir}"/>
        <delete dir="${test.build.dir}"/>
        <delete file="${plugin.jar}"/>
    </target>

    <!--
    **********************************************************
    ** dist - creates the plugin jar
    **********************************************************
    -->
    <target name="dist" depends="compile,revision">
        <echo message="creating ${ant.project.name}.jar ... "/>
        <copy todir="${plugin.build.dir}/resources">
            <fileset dir="resources"/>
        </copy>
        <copy todir="${plugin.build.dir}/images">
            <fileset dir="images"/>
        </copy>
        <copy todir="${plugin.build.dir}/data">
            <fileset dir="data"/>
        </copy>
        <copy todir="${plugin.build.dir}">
            <fileset dir=".">
                <include name="README"/>
                <include name="LICENSE"/>
            </fileset>
        </copy>
        <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}">
        <!--
        ************************************************
        ** configure these properties. Most of them will be copied to the plugins
        ** manifest file. Property values will also show up in the list available
        ** plugins: http://josm.openstreetmap.de/wiki/Plugins.
        **
        ************************************************
        -->
            <manifest>
                <attribute name="Author" value="Karl Guggisberg"/>
                <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.turnrestrictions.TurnRestrictionsPlugin"/>
                <attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
                <attribute name="Plugin-Description" value="The turnrestrictions plugin allows to enter maintain information about turn restrictions in the OpenStreetMap database."/>
                <attribute name="Plugin-Icon" value="images/preferences/turnrestrictions.png"/>
                <attribute name="Plugin-Link" value="http://josm.openstreetmap.de/wiki/Help/Plugin/TurnRestrictions"/>
                <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
                <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
            </manifest>
        </jar>
    </target>

    <!-- ************************************************************************************ -->
    <!-- * Targets for compiling and running tests                                            -->
    <!-- ************************************************************************************ -->
    <path id="groovy.path">
        <pathelement location="${eclipse.plugin.dir}/org.codehaus.groovy_1.7.5.xx-20100926-2000-e36-RC1\lib\groovy-all-1.7.5.jar"/>
    </path>
    <path id="junit.path">
        <pathelement location="${eclipse.plugin.dir}/org.junit_4.8.1.v4_8_1_v20100427-1100\junit.jar"/>
    </path>
    <path id="fest.library.path">
        <fileset dir="test/lib">
            <include name="fest-*.jar"/>
            <include name="jcp-*.jar"/>
        </fileset>
    </path>
    <path id="test.class.path">
        <pathelement location="${josm}"/>
        <pathelement location="${plugin.build.dir}"/>
        <path refid="groovy.path"/>
        <path refid="junit.path"/>
        <path refid="fest.library.path"/>
    </path>
    <path id="groovyc.path">
        <path refid="junit.path"/>
        <path refid="groovy.path"/>
        <path refid="fest.library.path"/>
        <pathelement location="${josm}"/>
        <pathelement location="${test.build.dir}"/>
        <pathelement location="${plugin.build.dir}"/>
        <!-- if we didn't explicitly put hamcrest on the class path, groovyc would
             abort and report it is missing a hamcrest class -->
        <pathelement location="test/lib/hamcrest-all-1.2.jar"/>
    </path>
    <target name="test-clean">
        <delete dir="${test.build.dir}"/>
        <mkdir dir="${test.build.dir}"/>
    </target>
    <target name="test-compile" depends="compile,test-clean" description="Compiles the test files">
        <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc" classpathref="groovy.path"/>
        <echo message="compiling test infrastructor for ${plugin.jar} ... "/>
        <javac srcdir="test/src" classpathref="test.class.path" debug="true" destdir="${test.build.dir}" includes="org/openstreetmap/josm/plugins/turnrestrictions/fixtures/**/*">
            <compilerarg value="-Xlint:deprecation"/>
            <compilerarg value="-Xlint:unchecked"/>
        </javac>
        <echo message="compiling groovy test cases for ${plugin.jar} ... "/>
        <groovyc srcdir="test/src" destdir="${test.build.dir}" classpathref="groovyc.path">
        </groovyc>
        <echo message="compiling java test cases for ${plugin.jar} ... "/>
        <javac srcdir="test/src" classpathref="test.class.path" debug="true" destdir="${test.build.dir}">
            <compilerarg value="-Xlint:deprecation"/>
            <compilerarg value="-Xlint:unchecked"/>
        </javac>
    </target>
    <target name="test-run" depends="test-compile" description="Runs the junit tests">
        <delete dir="test/output"/>
        <mkdir dir="test/output"/>
        <junit printsummary="true" failureproperty="junit.failure">
            <classpath>
                <path refid="groovyc.path"/>
                <pathelement location="test/config"/>
                <!-- required for test config file -->
                <pathelement location="."/>
                <!-- required to load images from subdir 'images/' -->
            </classpath>
            <test todir="test/output" name="org.openstreetmap.josm.plugins.turnrestrictions.AllUnitTests">
                <formatter type="xml"/>
            </test>
        </junit>
    </target>
</project>
