<?xml version="1.0"?>
<project name="upload-dist-tasks">

<!-- can be run independent of maven as follows (but it's easier
	 to simply use "mvn antrun:run"):
   - classpath must be uncommented below. when run from maven,
   - the classpath is set up for you

ant -f src/ant/upload-dist.xml \
    -Ddist.id=spring-batch \
    -Ddist.name='Spring Batch' \
    -Ddist.key=BATCH \
    -Ddist.accessKey=<access key> \
    -Ddist.secretKey=<secret key> \
    -Ddist.bucketName=dist.springframework.org \
    -Ddist.fileName=spring-batch-1.0.0.M1.zip \
    -Ddist.filePath=target/spring-batch-1.0.0.M1.zip \
    -Ddist.version=1.0.0.M1 \
    upload-dist
-->

    <taskdef resource="org/springframework/build/aws/ant/antlib.xml">
        <!-- see comment above
        <classpath>
            <pathelement location="/Users/cbeams/Desktop/org.springframework.build.aws.ant-3.0.5.RELEASE.jar"/>
            <pathelement location="/Users/cbeams/.m2/repository/net/java/dev/jets3t/jets3t/0.7.2/jets3t-0.7.2.jar"/>
            <pathelement location="/Users/cbeams/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar"/>
            <pathelement location="/Users/cbeams/.m2/repository/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar"/>
            <pathelement location="/Users/cbeams/.m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar"/>
        </classpath>
        -->
    </taskdef>
	<target name="upload-dist" depends="upload-prep,upload-s3,upload-staging"/>
	<target name="upload-prep">
	  <condition property="dist.releaseType" value="snapshot">
		<contains string="${dist.version}" substring="snapshot" casesensitive="false"/>
	  </condition>
	  <condition property="dist.releaseType" value="release" else="milestone">
		<contains string="${dist.version}" substring="release" casesensitive="false"/>
	  </condition>
	</target>
    <target name="upload-s3" unless="dist.staging">
        <checksum file="${dist.filePath}" algorithm="sha1"/>
        <s3 accessKey="${dist.accessKey}" secretKey="${dist.secretKey}">
            <upload bucketName="${dist.bucketName}" file="${dist.filePath}"
                    toFile="${dist.releaseType}/${dist.key}/${dist.fileName}" publicRead="true">
                <metadata name="project.name" value="${dist.name}"/>
                <metadata name="release.type" value="${dist.releaseType}"/>
                <metadata name="bundle.version" value="${dist.version}"/>
                <metadata name="package.file.name" value="${dist.fileName}"/>
            </upload>
            <upload bucketName="${dist.bucketName}" file="${dist.filePath}.sha1"
                    toFile="${dist.releaseType}/${dist.key}/${dist.fileName}.sha1" publicRead="true">
            </upload>
        </s3>
    </target>
    <target name="upload-staging" if="dist.staging">
	    <echo>Copying dist .ZIP to ${dist.staging}</echo>
        <checksum file="${dist.filePath}" algorithm="sha1"/>
        <copy file="${dist.filePath}.sha1"
                    toFile="${dist.staging}/${dist.key}/${dist.fileName}.sha1"/>
        <copy file="${dist.filePath}"
                    toFile="${dist.staging}/${dist.key}/${dist.fileName}"/>
    </target>
</project>
