<project name="build.upload">
    <target name="upload.dist" description="Upload distributions" depends="properties, check.app.version">
        <fail message="Need property dist.upload.username, specify with -Ddist.upload.username">
            <condition>
                <not>
                    <isset property="dist.upload.username"/>
                </not>
            </condition>
        </fail>
        <fail message="Need property dist.upload.password, specify with -Ddist.upload.password">
            <condition>
                <not>
                    <isset property="dist.upload.password"/>
                </not>
            </condition>
        </fail>

        <property file="local.build.properties"/>
        <sshexec host="${dist.upload.hostname}"
                 port="${dist.upload.port}"
                 username="${dist.upload.username}"
                 password="${dist.upload.password}"
                 command="mkdir -p ${dist.upload.path}"/>

        <scp todir="${dist.upload.username}:${dist.upload.password}@${dist.upload.hostname}:${dist.upload.path}"
             verbose="true"
             port="${dist.upload.port}">
            <fileset dir="${dist.dir}">
                <include name="**/*"/>
            </fileset>
        </scp>

        <sshexec host="${dist.upload.hostname}"
                 port="${dist.upload.port}"
                 username="${dist.upload.username}"
                 password="${dist.upload.password}"
                 command="mkdir -p ${dist.upload.path}/javadoc/{full,user}"/>

        <sshexec host="${dist.upload.hostname}"
                 port="${dist.upload.port}"
                 username="${dist.upload.username}"
                 password="${dist.upload.password}"
                 command="tar xzf ${dist.upload.path}/javadoc-full.tar.gz --directory ${dist.upload.path}/javadoc/full "/>
        <sshexec host="${dist.upload.hostname}"
                 port="${dist.upload.port}"
                 username="${dist.upload.username}"
                 password="${dist.upload.password}"
                 command="tar xzf ${dist.upload.path}/javadoc-user.tar.gz --directory ${dist.upload.path}/javadoc/user"/>
    </target>
    <target name="upload.dist-demos" description="Upload demos" depends="properties, check.app.version">
        <fail message="Need property dist.upload.username, specify with -Ddist.upload.username">
            <condition>
                <not>
                    <isset property="dist.upload.username"/>
                </not>
            </condition>
        </fail>
        <fail message="Need property dist.upload.password, specify with -Ddist.upload.password">
            <condition>
                <not>
                    <isset property="dist.upload.password"/>
                </not>
            </condition>
        </fail>

        <property file="local.build.properties"/>
        <sshexec host="${dist.upload.hostname}"
                 port="${dist.upload.port}"
                 username="${dist.upload.username}"
                 password="${dist.upload.password}"
                 command="mkdir -p ${dist.upload.path}/${app.version}/demo; mkdir -p ${dist.upload.path}/demo_repo"/>

        <scp todir="${dist.upload.username}:${dist.upload.password}@${dist.upload.hostname}:${dist.upload.path}/${app.version}/demo"
             verbose="true"
             port="${dist.upload.port}">
            <fileset dir="${dist.dir}/${app.version}/demo">
                <include name="**/*"/>
            </fileset>
        </scp>
        <scp todir="${dist.upload.username}:${dist.upload.password}@${dist.upload.hostname}:${dist.upload.path}/demo_repo"
             verbose="true"
             port="${dist.upload.port}">
            <fileset dir="${dist.dir}/demo_repo">
                <include name="**/*"/>
            </fileset>
        </scp>
    </target>
</project>
