<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : common.xml
    Created on : 15 March 2005, 00:12
    Author     : ivar
    Description:
	To create an abstract ant build script
-->

<project name="grid" default="usage" basedir=".">
	
	<import file="nbproject/build-impl.xml" optional="true" />

	<property file="${sys.dir}/common.properties"/>	

	<!-- import file="data.xml" optional="true"/ -->

	<path id="master-classpath">
		<fileset dir="${lib.dir}">
			<include name="*.jar"/>
		</fileset>
		<fileset dir="${tomcat.home}/common/lib">
			<include name="servlet*.jar"/>
		</fileset>
		<pathelement path="${web.dir}/WEB-INF/classes"/>
	</path>

	<target name="inits">
		<tstamp/>
		<mkdir dir="${build.dir}"/>
		<mkdir dir="${build.dir}/WEB-INF/classes"/>
		<mkdir dir="${build.dir}/WEB-INF/lib"/>
		<mkdir dir="${dist.dir}"/>
	</target>
	
	<target name="clean">
		<delete dir="${build.dir}"/>
		<delete file="${dist.dir}/$project.name}.war"/>
	</target>
	
	<target name="cleanall" depends="clean">
		<delete dir="${dist.dir}"/>
	</target>

	<target name="splash">
		<splash showduration="1000"/>
	</target>

	<target name="usage">
		<echo message=""/>
		<echo message="${project.name} build file"/>
		<echo message="-----------------------------------"/>
		<echo message=""/>
		<echo message="Available targets are:"/>
		<echo message=""/>
		<echo message="build     --> Build the application"/>
		<echo message="splash     --> "/>
		<echo message="dist     --> "/>
		<echo message="clean     --> "/>
		<echo message="source     --> "/>
		<echo message="all     --> "/>
		<echo message="redeploy     --> "/>
		<echo message="deploy    --> Deploy application as directory"/>
		<echo message="deploywar --> Deploy application as a WAR file"/>
		<echo message="install   --> Install application in Tomcat"/>
		<echo message="reload    --> Reload application in Tomcat"/>
		<echo message="start     --> Start Tomcat application"/>
		<echo message="stop      --> Stop Tomcat application"/>
		<echo message="list      --> List Tomcat applications"/>
		<echo message=""/>
	</target>

	<target name="source" depends="inits">
		<zip destfile="${dist.dir}/${project.name}-${DSTAMP}-source.zip">
			<fileset dir="${src.dir}"/>	
			<fileset dir="${web.dir}"/>	
			<fileset dir="${sql.dir}"/>	
			<fileset dir="${sys.dir}"/>	
		</zip>	
	</target>
	
	<target name="build" depends="inits" description="builds all from sources">
		<copy todir="${build.dir}" preservelastmodified="true">
			<fileset dir="${web.dir}">
				<include name="**/*.*"/>
         </fileset>
		</copy>
		<javac destdir="${build.dir}/WEB-INF/classes" target="1.4" debug="true"
			deprecation="false" optimize="false" failonerror="true">
			<src path="${src.dir}"/>
			<classpath refid="master-classpath"/>
		</javac>
		<copy todir="${build.dir}/WEB-INF/lib" preservelastmodified="true">
			<fileset dir="${lib.dir}">
				 <include name="**/*.*"/>
			</fileset>
		</copy>     
	</target>
   
	<target name="dist" depends="build,source">
		<war destfile="${dist.dir}/${project.name}.war" webxml="${build.dir}/WEB-INF/web.xml">
			<fileset dir="${build.dir}">
				 <include name="**/*.*"/>
			</fileset>
		</war>
	</target>
		
	<target name="deploy" depends="build">
		<copy todir="${tomcat.home}/webapps/${name}" preservelastmodified="true">
			<fileset dir="${build.dir}">
				<include name="**/*.*"/>
			</fileset>
		</copy>
	</target>
	
	<target name="deploy-war" depends="dist">
		<copy todir="${deploy.path}" preservelastmodified="true">
			<fileset dir="${dist.dir}">
				<include name="*.war"/>
			</fileset>
		</copy>
	</target>

	<target name="redeploy" depends="stop,clean,dist,deploy,start">
		<echo message="Redploying"/>
	</target>
	
	<target name="all" depends="splash,redeploy">
		<echo message="Doing it all"/>
	</target>
 

<!-- ============================================================== -->
<!-- Junit tasks ================================================= -->
<!-- ============================================================== -->
	<target name="test" depends="inits" description="">

	</target>

<!-- ============================================================== -->
<!-- Tomcat tasks ================================================= -->
<!-- ============================================================== -->

	<taskdef name="install" classname="org.apache.catalina.ant.InstallTask">
		<classpath>
			<path location="${tomcat.dir}/server/lib/catalina-ant.jar"/>
		</classpath>
	</taskdef>
	<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
		<classpath>
			<path location="${tomcat.dir}/server/lib/catalina-ant.jar"/>
		</classpath>
	</taskdef>
	<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
		<classpath>
			<path location="${tomcat.dir}/server/lib/catalina-ant.jar"/>
		</classpath>
	</taskdef>
	<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
		<classpath>
			<path location="${tomcat.dir}/server/lib/catalina-ant.jar"/>
		</classpath>
	</taskdef>
	<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
		<classpath>
			<path location="${tomcat.dir}/server/lib/catalina-ant.jar"/>
		</classpath>
	</taskdef>		

	<target name="install" description="Install application in Tomcat">
		<install url="${tomcat.manager.url}"
			username="${tomcat.manager.username}"
			password="${tomcat.manager.password}"
			path="/${name}"
			war="${name}"/>
	</target>

	<target name="reload" description="Reload application in Tomcat">
		<reload url="${tomcat.manager.url}"
			username="${tomcat.manager.username}"
			password="${tomcat.manager.password}"
			path="/${name}"/>
	</target>

	<target name="start" description="Start Tomcat application">
		<start url="${tomcat.manager.url}"
			username="${tomcat.manager.username}"
			password="${tomcat.manager.password}"
			path="/${name}"/>
		</target>

	<target name="stop" description="Stop Tomcat application">
		<stop url="${tomcat.manager.url}"
			username="${tomcat.manager.username}"
			password="${tomcat.manager.password}"
			path="/${name}"/>
	</target>

	<target name="list" description="List Tomcat applications">
		<list url="${tomcat.manager.url}"
			username="${tomcat.manager.username}"
			password="${tomcat.manager.password}"/>
	</target>
	
<!-- ============================================================== -->
<!-- Data tasks ================================================= -->
<!-- ============================================================== -->
	<target name="db.create">
	
	</target>
	<target name="db.dump">
	
	</target>
	<target name="db.load" >
	
	</target>
	<target name="db.delete">
	
	</target>


</project>
