<project name="Simplex" default="dist" basedir=".">

	<description>
		An implementation of the Simplex algorithm in Java.
	</description>

	<!-- set global properties for this build -->
	<property file="build.properties" />

	<path id="compile.classpath">
		<!-- Include all elements that Tomcat exposes to applications -->
		<fileset dir="${catalina.home}/bin">
			<include name="*.jar" />
		</fileset>
		<pathelement location="${catalina.home}/lib" />
		<fileset dir="${catalina.home}/lib">
			<include name="*.jar" />
		</fileset>
	</path>

	<taskdef resource="org/apache/catalina/ant/catalina.tasks" classpathref="compile.classpath"/>
	
	<target name="init" description="create needed directories">
		<!-- Create the time stamp -->
		<tstamp />
		<!-- Create the build directory structure used by compile -->
		<mkdir dir="${bin.home}" />
		<mkdir dir="${build.home}" />
		<mkdir dir="${build.home}/WEB-INF" />
		<mkdir dir="${build.home}/WEB-INF/classes" />
		<mkdir dir="${dist.home}" />
		<mkdir dir="${docs.home}" />
		<mkdir dir="${release.home}" />

		<!-- Copy static content of this web application -->
		<copy todir="${build.home}">
			<fileset dir="${web.home}"/>
		</copy>
		
		<!-- Copy external dependencies as required -->
		<mkdir dir="${build.home}/WEB-INF/lib" />
		<!--
		<copy todir="${build.home}/WEB-INF/lib" file="${foo.jar}"/>
		-->
	</target>

	<target name="compile" depends="init" description="compile the source">
		<!-- Compile the java code from ${src.home} into ${bin.home} -->
		<javac srcdir="${src.home}" destdir="${bin.home}"/>
		<!-- Compile the java code for web archive -->
		<javac 
			srcdir="${src.home}" 
			destdir="${build.home}/WEB-INF/classes">
			<classpath refid="compile.classpath" />
		</javac>
		<!-- Copy application resources -->
		<copy todir="${bin.home}">
			<fileset dir="${src.home}" excludes="**/*.java" />
		</copy>
		<copy file="Simplex.bat" tofile="${bin.home}/Simplex.bat" />
 		<copy todir="${build.home}/WEB-INF/classes">
			<fileset dir="${src.home}" excludes="**/*.java"/>
		</copy>
	</target>

	<target name="dist" depends="compile,javadoc" description="generate the binary distribution">
		<!-- Copy documentation subdirectories -->
		<mkdir dir="${dist.home}/docs" />
		<copy todir="${dist.home}/docs">
			<fileset dir="${docs.home}" />
		</copy>
		
		<!-- Create application WAR file -->
		<jar jarfile="${dist.home}/${app.name}-${app.version}.war" basedir="${build.home}" />

		<!-- Create application JAR file -->
		<jar jarfile="${dist.home}/${app.name}-${app.version}.jar" basedir="${bin.home}" />
	</target>

	<target name="install" depends="compile" description="Install application to servlet container">
		<deploy 
			url="${manager.url}" 
			username="${manager.username}"
			password="${manager.password}"
			path="${app.path}"
			war="file:///${dist.home}/${app.name}-${app.version}.war" />
	</target>

	<target name="release" depends="dist" description="generate the release">
	</target>

	<target name="clean" description="clean up">
		<!-- Delete the directory trees -->
		<delete dir="${build.home}"/>
		<delete dir="${bin.home}"/>
		<delete dir="${dist.home}"/>
		<delete dir="${release.home}"/>
	</target>

	<target name="javadoc" depends="compile" description="Create Javadoc API documentation">
		<javadoc sourcepath="${src.home}" destdir="${docs.home}" packagenames="*">
			<classpath refid="compile.classpath"/>
		</javadoc>
	</target>

	<target name="all" depends="clean,dist" description="clean dist directories, then create dist" />
	
	<target name="reinstall" depends="remove,dist,install" description="Removes the application from the server and installs it again" />

	<target name="list" description="List installed applications on servlet container">
		<list url="${manager.url}" username="${manager.username}" password="${manager.password}" />
	</target>
	
	<target name="reload" depends="compile" description="Reload application on servlet container">
		<reload url="${manager.url}"
			username="${manager.username}"
			password="${manager.password}"
			path="${app.path}"/>
	</target>

	<target name="remove" description="Remove application on servlet container">
		<undeploy url="${manager.url}"
			username="${manager.username}"
			password="${manager.password}"
			path="${app.path}"/>
	</target>

</project>
