<?xml version="1.0"?>

<project name="azkaban-testjob" basedir="." default="all">
	<property name="base.dir" value="${basedir}/.." />
	<property name="dist.jar.dir" value="${base.dir}/dist/unit/jars" />
	<property name="dist.classes.dir" value="${base.dir}/dist/unit/classes" />
	<property name="dist.packages.dir" value="${base.dir}/dist/unit/packages" />
	
	<property name="java.src.dir" value="${base.dir}/unit/java" />
	<property name="job.conf.dir" value="${base.dir}/unit/executions" />
  <property name="build.ivy.lib.dir" location="../build/ivy/lib" />
		
	<property environment="env" />

	<path id="main.classpath">
    <fileset dir="${build.ivy.lib.dir}">
			<include name="*.jar" />
		</fileset>

		<pathelement path="${dist.classes.dir}" />
	</path>
	
	<!-- set the build number based on environment variable, otherwise blank -->
	<property environment="env" description="System environment variables (including those set by Hudson)" />

	<target name="all" depends="clean, package" description="Builds and packages" />

	<target name="clean" description="Delete generated files.">
		<echo message="Deleting generated files in dist" />
		<delete dir="${dist.jar.dir}" />
		<delete dir="${dist.classes.dir}" />
		<delete dir="${dist.packages.dir}" />
	</target>

	<target name="build" description="Compile main source tree java files">
		<delete dir="${dist.classes.dir}" />
		<mkdir dir="${dist.classes.dir}" />
		<mkdir dir="${dist.packages.dir}" />
		
		<javac fork="true" destdir="${dist.classes.dir}"
			target="1.6" debug="true" deprecation="false" failonerror="true" srcdir="${java.src.dir}/azkaban/test/executor" includes="SleepJavaJob.java">
			<classpath refid="main.classpath" />
		</javac>
	</target>
	
	<target name="jars" depends="build" description="Create azkaban jar">
		<delete dir="${dist.jar.dir}" />
		<mkdir dir="${dist.jar.dir}" />
		<jar destfile="${dist.jar.dir}/test.jar">
			<fileset dir="${dist.classes.dir}">
				<include name="**/*.*" />
			</fileset>
		</jar>
	</target>
	
	<target name="package-exectest1" depends="jars" description="Creates a test zip">
		<!-- Tarball it -->
		<zip destfile="${dist.packages.dir}/exectest1.zip">
			<zipfileset dir="${dist.jar.dir}" />
      <zipfileset dir="${job.conf.dir}/exectest1" />
		</zip>
	</target>

	<target name="package-exectest2" depends="jars" description="Creates a test zip">
		<!-- Tarball it -->
		<zip destfile="${dist.packages.dir}/exectest2.zip">
			<zipfileset dir="${dist.jar.dir}" />
      <zipfileset dir="${job.conf.dir}/exectest2" />
		</zip>
	</target>
	
	<target name="package-animal" depends="jars" description="Creates a test zip">
		<!-- Tarball it -->
		<zip destfile="${dist.packages.dir}/animal.zip">
			<zipfileset dir="${dist.jar.dir}" />
      <zipfileset dir="${job.conf.dir}/animal" />
		</zip>
	</target>
	
	<target name="package-embedded" depends="jars" description="Creates a test zip">
		<!-- Tarball it -->
		<zip destfile="${dist.packages.dir}/embedded.zip">
			<zipfileset dir="${dist.jar.dir}" />
      <zipfileset dir="${job.conf.dir}/embedded" />
		</zip>
	</target>

	<target name="package-embedded2" depends="jars" description="Creates a test zip">
		<!-- Tarball it -->
		<zip destfile="${dist.packages.dir}/embedded2.zip">
			<zipfileset dir="${dist.jar.dir}" />
      <zipfileset dir="${job.conf.dir}/embedded2" />
		</zip>
  </target>	
  
  <target name="package-embedded3" depends="jars" description="Creates a test zip">
		<!-- Tarball it -->
		<zip destfile="${dist.packages.dir}/embedded3.zip">
			<zipfileset dir="${dist.jar.dir}" />
      <zipfileset dir="${job.conf.dir}/embedded3" />
		</zip>
  </target>	
  
  <target name="package-embeddedBad" depends="jars" description="Creates a test zip">
		<!-- Tarball it -->
		<zip destfile="${dist.packages.dir}/embeddedBad.zip">
			<zipfileset dir="${dist.jar.dir}" />
      <zipfileset dir="${job.conf.dir}/embeddedBad" />
		</zip>
  </target>	
  
  <target name="package" depends="package-exectest1, package-exectest2, package-animal, package-embedded, package-embedded2, package-embedded3, package-embeddedBad" description="Creates all packages">
  </target>
</project>
