<?xml version="1.0" encoding="UTF-8"?>
<!--
Setup:
	For Uploading to s3 you need s3cmd as commandline tool

	For SVN you need svnant.jar in your java-library
	Project: http://subclipse.tigris.org/svnant.html
	Download: http://subclipse.tigris.org/files/documents/906/32898/svnant-1.0.0.zip
	Version: 1.0.0

	In Linux
	- Copy the File lib/svnant.jar to /usr/share/java/

	In Windows
	- ...

-->


<project name="ZIP Library" basedir="." default="upload">

	<description>Create the ZIP-File for ShopgateLibrary</description>

	<property file="build.number"/>
	<property file="build.properties"/>
	
	<property name="project-root" location="./" />
	<property name="ant-folder" location="./ant/" />

	<property name="build-folder" location="${ant-folder}/build/" />
	<property name="output-folder" location="${build-folder}/shopgate_library" />
	<property name="release-folder" location="${ant-folder}/releases" />

	<echo>
		########################################################
		## BUILD Library
		########################################################
	</echo>

	<!--
		Build the ZIP-File
	-->
	<target name="build">
		<echo message="Build ZIP-Archive" />

		<delete dir="${ant-folder}" />
		<mkdir dir="${release-folder}" />
		<mkdir dir="${output-folder}" />

		<copy todir="${output-folder}">
			<fileset dir="${project-root}" followsymlinks="false">
				<include name="assets/" />
				<include name="classes/" />
				<include name="temp/" />
				<include name="vendors/" />
				<include name=".htaccess" />
				<include name="shopgate.php" />
				<include name="changelog.txt" />
				<exclude name="temp/*.*"/>
			</fileset>
		</copy>
		
		<mkdir dir="${output-folder}/config" />
		<zip zipfile="${project-root}/${plugin.zip-filename}" basedir="${build-folder}" update="false" />
		<delete dir="${ant-folder}" />
	</target>

	<!--
		Upload the the new Version to S3

		Depends on Prepare, create_tag, build
	-->
	<target name="upload" depends="build">
		<s3cmd command="put" file="${project-root}/shopgate_library.zip" key="${plugin.s3-key}">
			<args>
				<arg value="--acl-public" />
			</args>
		</s3cmd>

		<echo message="Public-URL: ${plugin.s3-key}" />
	</target>

	<!-- BEGIN MACROS -->
	<macrodef name = "s3cmd">
	    <attribute name = "command" />
	    <attribute name = "file" default = "" />
	    <attribute name = "key" default = "" />
	    <element name = "args" optional = "true" />

	    <sequential>
	        <echo message = "Upload @{file} to @{key}" />
	        <exec executable = "${cmd.python}">
	            <arg value = "${cmd.s3cmd}" />
	            <arg value = "@{command}" />
	            <args />
	            <arg value = "@{file}" />
	            <arg value = "@{key}" />
	        </exec>
	    </sequential>
	</macrodef>
	<!-- END MACROS -->
</project>