<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="build" name="Tiamat">
    <!--
    *****************************************
    * build script for Tiamat RPG Framework *
    * using Apache ANT 1.6.1                *
    ***************************************** -->    
    
    <!--    
    ****************************************
    * init:                                *
    * -set properties                      *
    *  -source paths                       *
    *  -output paths                       *
    *  -package name                       *
    *  -jar name                           *
    **************************************** -->    
    <target name="init">
        <!-- version -->
        <property name="majorVersion" value="0.1"/>
        <property name="minorVersion" value="20051001"/>
        <property name="version" value="${majorVersion}.${minorVersion}"/>
        <!-- source paths -->
        <property name="sourcePath" value="./com/huguesjohnson/"/>
        <property name="docSourcePath" value="./docs/Tiamat/"/>
        <property name="libSourcePath" value="./lib/"/>
        <!-- output paths -->
        <property name="outputPath" value="../Releases/Tiamat/Version 0.1 - Development/"/>
        <property name="docOutputPath" value="${outputPath}/"/>
        <property name="javaOutputPath" value="${outputPath}/Java/"/>
        <property name="xstreamLibPath" value="/lib/xstream/xstream-1.0.2.jar"/>
        <!-- name of the packages to create -->
        <property name="packageName" value="Tiamat_${version}.zip"/>
        <property name="frameworkPackageName" value="Tiamat_${version}.jar"/>
        <property name="toolsPackageName" value="Tools_${version}.jar"/>
        <property name="demosPackageName" value="Demos_${version}.jar"/>
    </target>
	
    <!--    
    ****************************************
    * clean:                               *
    * -clean the previous build:           *
    **************************************** -->
    <target name="clean" depends="init">
        <!-- delete everything in the output path -->
        <delete dir="${outputPath}"/>
        <!-- recreate the output directories -->
        <mkdir dir="${outputPath}"/>
        <mkdir dir="${docOutputPath}"/>
        <mkdir dir="${javaOutputPath}"/>
    </target>

    <!--    
    ****************************************
    * copy_source:                         *
    * -copy the source code to compile     *
    **************************************** -->
    <target name="copy_source" depends="clean">
        <!-- copy everything in the tiamat package -->
        <copy todir="${javaOutputPath}/Source/com/huguesjohnson/tiamat/">
            <fileset dir="${sourcePath}/tiamat/">
                <include name="**/*.java"/>
                <include name="**/*.form"/>
                <include name="**/*.gif"/>
                <include name="**/*.xml"/>
                <exclude name="demos/**/*"/>
            </fileset>
        </copy>
        
        <!-- copy source code for demos -->
        <copy todir="${javaOutputPath}/Source/com/huguesjohnson/tiamat/demos/">
            <fileset dir="${sourcePath}/tiamat/demos">
                <include name="**/*.java"/>
                <include name="*.gif"/>
                <include name="Camineet/images/ui/*.gif"/>
            </fileset>
        </copy>
        
        <!-- copy items from other packages -->
        <copy todir="${javaOutputPath}/Source/com/huguesjohnson/">
            <fileset dir="${sourcePath}">
                <include name="ImageLoader.java"/>
                <include name="LaunchBrowser.java"/>
                <include name="PathResolver.java"/>
                <include name="FileCopy.java"/>
                <include name="FileDelete.java"/>
            </fileset>
        </copy>
        <copy todir="${javaOutputPath}/Source/com/huguesjohnson/fileFilter/">
            <fileset dir="${sourcePath}/fileFilter/">
                <include name="DirectoryFileFilter.java"/>
                <include name="ImageFileFilter.java"/>
                <include name="MultiExtensionFileFilter.java"/>
                <include name="XmlFileFilter.java"/>
            </fileset>
        </copy>
        <copy todir="${javaOutputPath}/Source/com/huguesjohnson/ui/">
            <fileset dir="${sourcePath}/ui/">
                <include name="FileBrowsePanel.java"/>
                <include name="FileBrowsePanel.form"/>
                <include name="ImageBrowsePanel.java"/>
                <include name="ImageBrowsePanel.form"/>
                <include name="ListPanel.java"/>
                <include name="ListPanel.form"/>
            </fileset>
        </copy>
        <copy todir="${javaOutputPath}/Source/com/huguesjohnson/serialization/">
            <fileset dir="${sourcePath}/serialization/">
                <include name="Storable.java"/>
                <include name="StorageException.java"/>
                <include name="Formatter.java"/>
                <include name="XmlFormatter.java"/>
            </fileset>
        </copy>
        <copy todir="${javaOutputPath}/Source/com/huguesjohnson/test/">
            <fileset dir="${sourcePath}/test/">
                <include name="MapExperiment*.java"/>
                <include name="FileCopy_Test.java"/>
                <include name="FileDelete_Test.java"/>
                <include name="PathResolver_Test.java"/>
                <include name="ScriptTable_Prototype.java"/>
                <include name="ScriptTable_Test.java"/>
            </fileset>
        </copy>
        
        <!-- copy over data for demos -->
        <copy todir="${outputPath}/Demos/">
            <fileset dir="${sourcePath}/tiamat/demos/">
                <include name="PS3/**/*.gif"/>
                <include name="PS3/**/*.xml"/>
                <include name="PS3/**/*.mid"/>
                <include name="Camineet/**/*.gif"/>
                <include name="Camineet/**/*.xml"/>
                <include name="Camineet/**/*.mid"/>
                <include name="Camineet/**/*.ttf"/>
                <include name="Camineet/Design.pdf"/>
                <include name="Camineet/scratchpad.txt"/>
                <include name="Readme.html"/>
            </fileset>
        </copy>
                
        <!-- copy over data for samples -->
        <copy todir="${outputPath}/Samples/">
            <fileset dir="${sourcePath}/tiamat/demos/samples/">
                <include name="**/*.gif"/>
                <include name="**/*.xml"/>            
                <include name="Readme.html"/>
            </fileset>
        </copy>
        
        <!-- copy over external libraries -->
        <copy todir="${javaOutputPath}/lib/xstream">
            <fileset dir="${libSourcePath}/xstream/">
                <include name="*"/>
            </fileset>
        </copy>
        
        <!-- copy over the build file -->
        <copy todir="${javaOutputPath}/Source/">
            <fileset dir="./">
                <include name="Tiamat ${majorVersion}.xml"/>
            </fileset>
        </copy>                    
    </target>
    
    <!--    
    ****************************************
    * compile:                             *
    * -javac all files                     *
    **************************************** -->
    <target name="compile" depends="copy_source">

        <!-- compile Java Framework code -->
        <javac destdir="${javaOutputPath}/Source/" srcdir="${javaOutputPath}/Source/" debug="off" optimize="on" deprecation="on">
            <classpath>
                <pathelement path="${javaOutputPath}/Source/"/>
                <pathelement path="${javaOutputPath}${xstreamLibPath}"/>
            </classpath>
            <include name="**/*.java"/>
            <exclude name="com/huguesjohnson/test/**"/>
        </javac>
        
        <!-- build the framework jar file -->
        <jar destfile="${javaOutputPath}/${frameworkPackageName}">
            <fileset dir="${javaOutputPath}/Source/">
                <include name="**/*.class"/>
                <include name="**/*.xml"/>
                <include name="com/huguesjohnson/tiamat/*.gif"/>
                <exclude name="**/*.java"/>
                <exclude name="**/*.form"/>
                <exclude name="com/huguesjohnson/tiamat/demos/**"/>
                <exclude name="com/huguesjohnson/tiamat/tools/**"/>
                <exclude name="com/huguesjohnson/fileFilter/**"/>
                <exclude name="com/huguesjohnson/ui/**"/>
                <exclude name="com/huguesjohnson/test/**"/>
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="com/huguesjohnson/tiamat/AboutSplash"/>
                <attribute name="Class-Path" value=".${xstreamLibPath}"/>
            </manifest>
        </jar>

        <!-- build the tools jar file -->
        <jar destfile="${javaOutputPath}/${toolsPackageName}">
            <fileset dir="${javaOutputPath}/Source/">
                <exclude name="**/*.java"/>
                <exclude name="**/*.form"/>
                <exclude name="com/huguesjohnson/tiamat/demos/**"/>
                <exclude name="com/huguesjohnson/test/**"/>
                <include name="com/huguesjohnson/tiamat/tools/**"/>
                <include name="com/huguesjohnson/*"/>
                <include name="com/huguesjohnson/fileFilter/**"/>
                <include name="com/huguesjohnson/ui/**"/>
            </fileset>
            <manifest>
                <attribute name="Class-Path" value="${frameworkPackageName}"/>
                <attribute name="Main-Class" value="com/huguesjohnson/tiamat/tools/Quicklaunch"/>
            </manifest>
        </jar>
        
        <!-- build the demo jar files -->
        <jar destfile="${javaOutputPath}/${demosPackageName}">
            <fileset dir="${javaOutputPath}/Source/">
                <exclude name="com/huguesjohnson/test/**"/>
                <include name="com/huguesjohnson/fileFilter/**"/>
                <include name="com/huguesjohnson/tiamat/demos/**/*.class"/>
                <include name="com/huguesjohnson/tiamat/demos/*.gif"/>
                <include name="com/huguesjohnson/tiamat/demos/Camineet/images/ui/*.gif"/>
                <include name="com/huguesjohnson/ui/**"/>
            </fileset>
            <manifest>
                <attribute name="Class-Path" value="Tiamat_${version}.jar"/>
                <attribute name="Main-Class" value="com/huguesjohnson/tiamat/demos/Quicklaunch"/>
            </manifest>
        </jar>
                        
        <!-- remove the .class files -->
        <delete>
            <fileset dir="${javaOutputPath}/Source/">
                <include name="**/*.class"/>
            </fileset>
        </delete>
    </target>
	
    <!--    
    ****************************************
    * build_docs:                          *
    * -copy the help files                 *
    * -build javadocs                      *
    **************************************** -->
    <target name="build_docs" depends="copy_source">
        <!-- build javadocs -->
        <mkdir dir="${javaOutputPath}/Javadoc/"/>
        <javadoc destdir="${javaOutputPath}/Javadoc/">
            <fileset dir="${javaOutputPath}/Source/">
                <exclude name="com/huguesjohnson/test/**"/>
                <include name="**/*.java"/>
            </fileset>
        </javadoc>
        
        <!-- copy over help files -->
        <copy todir="${outputPath}">
            <fileset dir="${docSourcePath}">
                <include name="ReleaseNotes ${version}.html"/>
                <include name="Tiamat Framework Specifications ${version}.pdf"/>
                <include name="Readme.html"/>
            </fileset>
        </copy>
    </target>
	 
    <!--    
    ****************************************
    * package the application:             *
    * -copy the source code                *
    * -put everything into a zip file      *
    **************************************** -->
    <target name="package" depends="build_docs">
        <!-- put everything into a zip file -->
        <zip destfile="${outputPath}/${packageName}" basedir="${outputPath}"/>
    </target>
    
    <!--    
    ****************************************
    * build:                               *
    * -just call everything in order       *
    **************************************** -->
    <target name="build" depends="init,clean,copy_source,compile,build_docs,package"/>
</project>