<?xml version="1.0" encoding="ISO-8859-1"?>

<project name="TWikiDrawPlugin" default="build" basedir=".">

    <property name="repository.home" value="repository"/>
    <property name="build.home" value="build"/>

    <!-- 
        For offline build you can specify local repository path using "file:" protocol instead of "http:".
        To avoid download of plugin components make sure what all distribution archives and patches 
        are situated in the ${repository.home} directory.
    -->
    <!-- The primary plugin's source repository URL -->
    <property name="TWikiDrawPlugin.loc" 
        value="http://twiki.org/p/pub/Plugins/TWikiDrawPlugin/"/>

    <!-- MoinMoin patches repository URL -->
    <property name="TWikiDrawPlugin.patched.loc" 
        value="http://moinmoin.wikiwikiweb.de/OliverGraf/TWikiDrawPlugin?action=AttachFile&amp;do=get&amp;target="/>

    <!-- MoinMoin patch filename -->
    <property name="TWikiDrawPlugin.patch.name"
        value="twikidraw-1.103-full.diff"/>

    <target name="-init">
        <mkdir dir="${repository.home}"/>
        <mkdir dir="${build.home}/classes"/>
    </target>

    <target name="-checkfile">
        <echo message="Checking ${file}"/>
        <available file="${repository.home}/${file}" property="havefile"/>
    </target>

    <target name="getfile" unless="havefile" depends="-checkfile">
        <get src="${url}${file}" dest="${repository.home}/${file}" />
    </target>

    <!--
        If you already have source code prepared to be compiled in ${build.home}/current directory 
        specify "source.code.is.ready" property to avoid extraction and patching of distribution archives.
    -->
    <target name="prepare-source-code" depends="-init" unless="source.code.is.ready">

        <antcall target="getfile">
            <param name="url" value="${TWikiDrawPlugin.loc}"/>
            <param name="file" value="TWikiDrawPlugin.zip"/>
        </antcall>
        <antcall target="getfile">
            <param name="url" value="${TWikiDrawPlugin.patched.loc}"/>
            <param name="file" value="${TWikiDrawPlugin.patch.name}"/>
        </antcall>
        <antcall target="getfile">
            <param name="url" value="${TWikiDrawPlugin.patched.loc}"/>
            <param name="file" value="twikidraw-png.zip"/>
        </antcall>

        <unzip src="${repository.home}/TWikiDrawPlugin.zip" dest="${build.home}">
            <patternset>
                <include name="lib/**/source.zip"/>
            </patternset>
        </unzip>
        <unzip dest="${build.home}/current">
            <fileset dir="${build.home}">
                <include name="lib/**/source.zip"/>
            </fileset>
        </unzip>
        <unzip dest="${build.home}/current"
            src="${repository.home}/twikidraw-png.zip"/>

        <patch patchfile="${repository.home}/${TWikiDrawPlugin.patch.name}" 
            strip="1" dir="${build.home}/current"/>
    </target>

    <target name="build" depends="-init, prepare-source-code"
            description="Build TWikiDrawPlugin JAR">
        <javac destdir="${build.home}/classes" 
                source="1.3" target="1.1">
            <src path="${build.home}/current/src"/>
            <src path="${build.home}/current/packages"/>
        </javac>

        <jar destfile="${build.home}/twikidraw.jar">
            <fileset dir="${build.home}/classes"/>
        </jar>
    </target>

    <target name="clean"
            description="Remove generated files">
        <delete dir="${build.home}"/>
    </target>

    <target name="clean-all" depends="clean"
            description="Remove ALL intermediate files">
        <delete dir="${repository.home}"/>
    </target>

</project> 
