<project name="czechaddress" default="dist" basedir=".">
    <property name="josm.base"              value="../../core"/>
    <property name="josm.jar"               value="${josm.base}/dist/josm-custom.jar"/>
    <property name="josm.doc.dir"           value="${josm.base}/doc"/>
    <property name="plugin.dist.dir"        value="../../dist"/>
    <property name="plugin.build.dir"       value="build"/>
    <property name="plugin.javadoc.dir"     value="doc"/>
    <property name="plugin.basepackage"     value="org.openstreetmap.josm.plugins.czechaddress"/>
    <property name="plugin.basepackage.dir" value="org/openstreetmap/josm/plugins/czechaddress"/>
    <property name="plugin.jar"             value="${plugin.dist.dir}/${ant.project.name}.jar"/>
    <property name="ant.build.javac.target" value="1.5"/>

    <target name="clean">
        <delete dir="${plugin.build.dir}"/> 
        <delete dir="${plugin.jar}"/> 
    </target>
    <target name="init">
        <mkdir dir="${plugin.build.dir}"/>
        <mkdir dir="${plugin.build.dir}"/>
    </target>

    <target name="compile"
            depends="init"
            description="Compile the plugin">
                
        <!-- compile the plugin -->
        <javac srcdir="src"
               classpath="${josm.jar}"
               destdir="${plugin.build.dir}"
               debug="true"/>

        <!-- create the manifest -->
        <manifest file="${plugin.build.dir}/${plugin.basepackage.dir}/MANIFEST.MF">
            <attribute name="Author" value="Radomír Černoch"/>
            <attribute name="Plugin-Description" value="Creating and handling address nodes and buildings within Czech Republic."/>
            <attribute name="Plugin-Mainversion" value="1607"/>
            <attribute name="Plugin-Version" value="0.2.0"/>
            <attribute name="Plugin-Class" value="${plugin.basepackage}.CzechAddressPlugin"/>
        </manifest>

        <!-- include the images -->
        <copy todir="${plugin.build.dir}/images">
            <fileset dir="images"/>
        </copy>
    </target>

    <target name="dist"
            depends="compile"
            description="Create the .jar file for distribution">
        <mkdir dir="${plugin.dist.dir}"/>
        <jar destfile="${plugin.jar}"
             basedir="${plugin.build.dir}"
             manifest="${plugin.build.dir}/${plugin.basepackage.dir}/MANIFEST.MF"/>
    </target>

    <target name="doc" description="Create Javadoc API documentation">
        <!--<ant antfile="build.xml" target="doc" dir="${josm.base}"/>-->
        <mkdir dir="${plugin.javadoc.dir}"/>
        <javadoc sourcepath="src"
                 packagenames="*"
                 destdir="${plugin.javadoc.dir}"
                 use="true"
                 charset="UTF-8">
            <doctitle><![CDATA[Czech Address JOSM plugin]]></doctitle>
            <bottom><![CDATA[<i>Licenced under GPLv3. Bugreports should be sent to
                    <a href='mailto:radomir.cernoch@gmail.com'>Radomír Černoch</a></i>]]>
            </bottom>
            <!--<tag name="todo" scope="all" description="To do:"/>-->
            <link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
            <link href="http://developer.java.sun.com/developer/products/xml/docs/api/"/>
            <!--<link href="file://${user.home}/devel/core/doc"/>-->
        </javadoc>
    </target>

    <target name="install" depends="dist">
        <property environment="env"/>
        <condition property="josm.plugins.dir"
                   value="${env.APPDATA}/JOSM/plugins"
                   else="${user.home}/.josm/plugins">
            <and><os family="windows"/></and>
        </condition>
        <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
    </target>

    <!-- Before running "run" target, please "ant dist" the JOSM. -->
    <target name="run" depends="compile">
        <java classname="JOSM" fork="true">
            <jvmarg value="-Xmx1024m"/>
            <jvmarg value="-Xdebug"/>
            <jvmarg value="-ea"/>
            <classpath>
                <pathelement location="${plugin.build.dir}"/>
                <pathelement path="${java.class.path}"/>
            </classpath>
            <classpath>
                <pathelement location="${josm.jar}"/>
                <pathelement path="${java.class.path}"/>
            </classpath>
        </java>
    </target>

</project>
