<?xml version="1.0" encoding="utf-8"?>
<project name="ajaxComments" default="build" basedir=".">
    <php expression="include('vendor/autoload.php')"/>
    <loadfile property = "version" file = "VERSION">
        <filterchain>
            <striplinebreaks/>
        </filterchain>
    </loadfile>
    <target name="bumpversion">
        <echo>Bumping version to ${version}</echo>
        <reflexive>
            <fileset dir=".">
                <include name="index.php"/>
                <include name="authLdap.php"/>
            </fileset>
            <filterchain>
                <replaceregexp>
                    <regexp pattern="Version:.*" replace="Version: ${version}"/>
                </replaceregexp>
            </filterchain>
        </reflexive>
    </target>
    <target name="build" depends="bumpversion,deploy.git,deploy.svn"/>
    <target name="sync.svn">
        <filesync
                rsyncPath="rsync"
                destinationDir="${project.basedir}/svn/trunk"
                sourceDir="${project.basedir}/"
                verbose="true"
                excludeFile="${project.basedir}/.rsyncIgnore"
        />
    </target>
    <target name="deploy.svn" depends="sync.svn">
        <property override="true" file="${project.basedir}/.svnAccess" prefix="svnaccess" />
        <foreach param="dirname" target="svn.addFile">
            <fileset dir="${project.basedir}/svn/trunk">
                <include name="**/*"/>
            </fileset>
        </foreach>
        <echo message="${svnaccess.username}"/>
        <exec outputProperty="committedrevision" executable="svn" dir="${project.basedir}/svn/trunk">
            <arg value="commit"/>
            <arg value="--username"/>
            <arg value="${svnaccess.username}"/>
            <arg value="--password"/>
            <arg value="${svnaccess.password}"/>
            <arg value="--message"/>
            <arg value="Bumps version to ${version}"/>
            <arg value="--no-auth-cache"/>
            <arg value="--quiet"/>
        </exec>
        <!--svncommit
            username="${svnaccess.username}"
            password="${svnaccess.password}"
            workingcopy="${project.basedir}/svn"
            message="Bumps version to ${version}"
            nocache="true"
            /-->
        <echo message="Committed revision: ${committedrevision}"/>
    </target>

    <target name="svn.addFile">
        <trycatch>
            <try>
                <svninfo workingcopy="${project.basedir}/svn/trunk/${dirname}"/>
            </try>
            <catch>
                <exec command="svn add ${project.basedir}/svn/trunk/${dirname}"/>
                <echo>${dirname}</echo>
            </catch>
            <finally>

            </finally>
        </trycatch>
        <echo>${svn.info}</echo>
    </target>
    <target name="deploy.git">
        <exec executable="git" dir=".">
            <arg value="-m"/>
            <arg value="Bumps version to ${version}"/>
        </exec>
        <exec executable="git" dir=".">
            <arg value="tag"/>
            <arg value="-s"/>
            <arg value="-m"/>
            <arg value="Version ${version}"/>
            <arg value="${version}"/>
        </exec>
        <exec executable="git" dir=".">
            <arg value="push"/>
            <arg value="--tags"/>
            <arg value="origin"/>
        </exec>
    </target>
</project>