<project name="ant-template" default="dist">

	<!--
	Customize these properties
	-->
	<property name="PROJECT_NAME" value="tivonage" />
	<property name="VERSION" value="0.21" />
	<property name="JARFILE" value="${PROJECT_NAME}-${VERSION}.jar" />
	<property name="ZIPFILE" value="${PROJECT_NAME}-${VERSION}.zip" />
	<property name="SRCZIPFILE" value="${PROJECT_NAME}-${VERSION}-src.zip" />

	<!--
	Built-in paths and properties
	-->
	<property name="BUILD" value="build" />
	<property name="SRC" value="src" />
	<property name="DIST" value="dist" />
	<property name="DISTIMAGE_SHORT" value="${PROJECT_NAME}-${VERSION}"/>
	<property name="DISTIMAGE" value="${DIST}/${DISTIMAGE_SHORT}"/>
	
	<path id="LIB">
		<fileset dir="lib">
			<include name="**/*.jar" />
		</fileset>
	</path>

	<!--
	Blow away any previous build results
	-->
	<target name="clean">
		<delete dir="${BUILD}" />
		<delete dir="${DIST}" />
	</target>


	<!--
	Compile the source and unit tests
	-->
	<target name="compile">

		<!-- compile production source -->
		<mkdir dir="${BUILD}" />
		<javac srcdir="${SRC}" destdir="${BUILD}" source="1.4" target="1.4" debug="on">
			<classpath refid="LIB" />
		</javac>
		<!-- copy non-java files (images, etc.) -->
		<copy todir="${BUILD}">
			<fileset dir="${SRC}" excludes="**/*.java,**/*.properties"/>
		</copy>
		<copy todir="${BUILD}">
			<fileset dir="${SRC}" includes="**/*.properties"/>
			<filterset>
				<filter token="VERSION" value="${VERSION}"/>
			</filterset>
		</copy>
	</target>

	<target name="jar" depends="compile">
		<mkdir dir="${DIST}" />
		<jar destfile="${DIST}/${JARFILE}">
			<fileset dir="${BUILD}" />
		</jar>
		
		<mkdir dir="${DIST}/${PROJECT_NAME}-${VERSION}"/>
	</target>

	<!--
	Do it all
	-->
	<target name="dist" depends="clean,jar">
		<mkdir dir="${DISTIMAGE}"/>
		<copy todir="${DISTIMAGE}/lib">
			<fileset dir="lib"/>
		</copy>
		<copy file="${DIST}/${JARFILE}" todir="${DISTIMAGE}/lib"/>
		
		<copy todir="${DISTIMAGE}">
			<fileset dir="bin" includes="*.bat,*.sh"/>
			<filterset>
				<filter token="JARFILE" value="${JARFILE}"/>
			</filterset>
		</copy>
		<chmod dir="${DISTIMAGE}" includes="*.sh" perm="+x"/>
		<copy todir="${DISTIMAGE}">
			<fileset dir="bin" excludes="*.bat,*.sh"/>
		</copy>
		
		<zip destfile="${DIST}/${ZIPFILE}"
		       	basedir="${DIST}"
				includes="${DISTIMAGE_SHORT}/**"
		/>
		
		<zip destfile="${DIST}/${SRCZIPFILE}">
			<zipfileset  dir="." includes="src/**,bin/**,lib/**,build.xml" prefix="${PROJECT_NAME}-${VERSION}-src"/>
		</zip>
	</target>

</project>