<?xml version="1.0" encoding="utf-8" ?>
<project name="Install" default="install">
    <property name="install.basedir" value="." overwrite="false" />
    <property name="backup.basedir" value="${install.basedir}/_bak" overwrite="false" />
    <property name="log.basedir" value="${install.basedir}/logs" overwrite="false" />
    <property name="component.name" value="eDocument.Server.Administrator" overwrite="false" />
		<property name="folder.name" value="${component.name}" overwrite="false" />
    <property name="version" value="1.0.0.0" overwrite="false" />
    <property name="install.dir" value="${install.basedir}/${folder.name}"/>

    <!-- *************************************************************************************** -->
    <!-- install                                                                                 -->
    <!-- *************************************************************************************** -->
    <target
       name="install"
       depends="backup, clean, put, configure"/>

    <!-- *************************************************************************************** -->
    <!-- backup                                                                                  -->
    <!-- *************************************************************************************** -->
    <target name="backup" description="Backup the current installation. Creates a backup directory and a subfolder with todays date. Then places a zip with the current installation in that directory. E.g. C:\eDocument\_bak\2008-05-21\Tjenestetorget.zip.">
        <!-- if bakcup directory does not exist -->
        <if test="${not directory::exists(backup.basedir)}">
            <!-- ensure that the backup directory exists -->
            <mkdir dir="${backup.basedir}" />
        </if>

        <!-- if there is something to bakcup -->
        <if test="${directory::exists(install.dir)}">
            <!-- create a subdirectory in bakcup.basedir with today's date -->
            <property name="backup.dir" value="${backup.basedir}/${datetime::get-year(datetime::now())}-${datetime::get-month(datetime::now())}-${datetime::get-day(datetime::now())}"/>
            <mkdir dir="${backup.dir}" />

            <!-- zip everything into the bakcup dir -->
            <zip zipfile="${backup.dir}/${component.name}-${datetime::get-hour(datetime::now())}-${datetime::get-minute(datetime::now())}-${datetime::get-second(datetime::now())}.zip">
                <fileset basedir="${install.dir}">
                    <!-- TODO: make it possible to specify full bakcup or config only -->
                    <include name="**/**"/>
                </fileset>
            </zip>
        </if>
    </target>

    <!-- *************************************************************************************** -->
    <!-- clean                                                                                   -->
    <!-- *************************************************************************************** -->
    <target name="clean" description="Remove existing install, except for config and ini files.">
        <!-- remove everything from the backup dir, except things ending with .config or .ini -->
        <delete>
            <fileset basedir="${install.dir}" defaultexcludes="false">
                <include name="**/**" />
                <exclude name="**/*.config" />
                <exclude name="**/*.ini" />
            </fileset>
        </delete>
    </target>

    <!-- *************************************************************************************** -->
    <!-- put                                                                                     -->
    <!-- *************************************************************************************** -->
    <target name="put" description="Unzip the component and put it into the install dir.">
        <unzip zipfile="${component.name}-${version}.zip" todir="${install.dir}" />
    </target>

    <!-- *************************************************************************************** -->
    <!-- configure                                                                               -->
    <!-- *************************************************************************************** -->
    <target name="configure" description="Configure the component by modifying/creating config files">
        <!-- TODO create/modify log.config -->
        <!-- TODO create/modify web.config -->
    </target>

    <!-- *************************************************************************************** -->
    <!-- help                                                                                    -->
    <!-- *************************************************************************************** -->
    <target name="help" description="Prints help for this buildfile.">
        <echo message="To install, put this buildfile and the zipfile to install from in the same directory. Then invoke the nant script." />
        <echo message="Example use: " />
        <echo message="nant -buildfile:install.nant -D:version=2.1.1 -D:install.basedir=c:\eDocument install" />
        <echo message="======================================================================================" />
        <echo message="Available targets (i.e. this is what you can do with this buildfile)" />
        <echo message="The main target install is designed to execute the following targets in turn:"/>
        <echo message="     backup, clean, put, configure"/>
        <echo message="======================================================================================" />
        <echo message="Overriding properties." />
        <echo message="The following properties can be overridden." />
        <echo message="     offline - specify true if you do not have access to the online svn repository, but wish to test the buildfile anyway. The default value is false. This will cause the get target to perform nothing and the version target to set the revision number to '0000'. Example: -D:offline=true" />
        <echo message="     component.description - required - specify the description of the component to build. Example: -D:component.name=eDocument.Core" />
        <echo message="     offline - optional - specify true if you do not have access to the online svn repository, but wish to test the buildfile anyway. The default value is false (online). This will cause the get target to perform nothing and the version target to set the revision number to '0000'. Example: -D:offline=true" />
        <echo message="     debug - optional - specify true if you want msbuild to be executed with configuration debug. The default value is false (release). Example: -D:debug=true" />
    </target>

</project>
