<project name="thmmPlugin" default="all" basedir=".">
    <description> Example of a substitution model plugin for BEAST</description>
    <property file="beast_sdk.properties"/>
    <property file="${user.home}/.ant-global.properties"/>
    <fail message="The beast.root property must be set. This is usually done by copying the beast_sdk.properties.in to beast_sdk.properties and modifying it to so that beast.root refers to the appropriate path.">
     <condition>
       <not>
         <isset property="beast.root"/>
       </not>
     </condition>
   </fail>


    <!-- set global properties for this build -->
    <property name="src" location="src"/>
    <property name="build" location="build"/>
    <property name="lib" location="${beast.root}/build/dist"/>
    <property name="dist" location="dist"/>
    
    <!-- the following 2 properties will be changed for every plugin that you write -->
      <!-- the plugin-class is the class that implements dr.app.plugin.Plugin -->
    <property name="plugin-class" value="@PLUGIN_CLASS@"/>
      <!-- the plugin-package is the package that contains your plugin-class -->
    <property name="plugin-package" value="@PLUGIN_PACKAGE@"/>
      <!-- plugin-jar name should list the fully qualified name to your plugin class -->
    <property name="plugin-jar" value="@PLUGIN_PACKAGE@@PLUGIN_SUBPACKAGES@@PLUGIN_CLASS@.jar"/>

    <property environment="env"/>

    <target name="init">
        <!-- Create the time stamp -->
        <tstamp/>
        <mkdir dir="${build}"/>
        <mkdir dir="${dist}"/>
    </target>

    <target name="all"
            depends="compile-all"
            description="Build all run-time stuff">
    </target>

    <target name="build"
            depends="compile-all"
            description="alias to compile-all">
    </target>

    <target name="compile-all"
            depends="compile-basic">
    </target>
    
    <target name="compile-basic"
            depends="init">
        <!-- Compile the java code from ${src} into ${build} -->
        <javac source="1.5" srcdir="${src}" destdir="${build}"
               classpath="${lib}/beast.jar">
            @PLUGIN_SRC_PATH@
        </javac>
    </target>

    <target name="dist"
            depends="compile-all"
            description="create the plugin jar and any other resources needed for the distribution">
        <!-- Create the distribution directory -->
        <mkdir dir="${dist}"/>
        <!-- Put everything in ${build} into the treestat.jar file -->
        <jar jarfile="${dist}/${plugin-jar}">
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
            </manifest>
            <fileset dir="${build}">
                @PLUGIN_CLASS_FILE_PATH@
            </fileset>
        </jar>
    </target>
    
    <target name="install"
            depends="dist" 
            description="Install the plugin into BEAST's plugins directory">
        <mkdir dir="${beast.root}/plugins" />
        <copy file="${dist}/${plugin-jar}" todir="${beast.root}/plugins" />
    </target>

    <target name="uninstall"
            description="Remove the plugin from BEAST's plugins directory">
        <delete file="${beast.root}/plugins/${plugin-jar}" verbose="true"/>
    </target>

    <target name="clean"
            description="Removes build products, but does not uninstall">
        <delete dir="${build}" verbose="true"/>
        <delete dir="${dist}" verbose="true"/>
    </target>

    <target name="test-install"
            depends="install"
            description="Runs integration tests of the plugin">
        <mkdir dir="scratch" />
        <!-- run the example xml file -->
        <java jar="${lib}/beast.jar"
           fork="true"
           failonerror="false"
           resultproperty="example.exitcode"
           dir="scratch"
           >
         <sysproperty key="beast.plugins.dir" value="${beast.root}/plugins" />
         <arg value="${basedir}/example/@EXAMPLE_XML_FILE@"/>
         <classpath>
           <pathelement location="${lib}/beast.jar"/>
         </classpath>
       </java>
    <fail message="The example example/@EXAMPLE_XML_FILE@ failed">
     <condition>
         <not> <equals arg1="${example.exitcode}" arg2="0"/></not>
     </condition>
   </fail>
    </target>
</project>
