<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="helloservice" basedir="." default="compile">

	<property file="build.properties"/>

	<description>
		This web service application provides simulated insurance hellos for
		a J2ME client application.
	</description>

	<property name="compile.debug"    value="true"/>

	<property name="src.dir"	value="${project-root}/src"/>
	<property name="gensrc.dir"	value="${project-root}/generated"/>
	<property name="web.dir"	value="${project-root}/WEB-INF"/>
	<property name="classes.dir"	value="${project-root}/WEB-INF/classes"/>
	
	<property name="tomcat.bin"	value="${tomcat-root}/bin"/>
	<property name="jaxrpc.bin"	value="${jaxrpc-root}/bin"/>
	

	<property name="tomcat.common.lib"	value="${tomcat-root}/common/lib"/>
	<property name="tomcat.shared.lib"	value="${tomcat-root}/jwsdp-shared/lib"/>
	<property name="j2ee.lib"	value="${j2ee-root}/lib"/>
	<property name="jaxrpc.lib"	value="${jaxrpc-root}/lib"/>
	<property name="saaj.lib"	value="${tomcat-root}/saaj/lib"/>
	
	<property name="war"		value="${ant.project.name}.war"/>
	<property name="tomcat.apps"	value="${tomcat-root}/webapps"/>
	


	<path id="compile.classpath">
		<pathelement	location="${classes.dir}"/>
		<pathelement	location="${j2ee.lib}/activation.jar"/>
		<pathelement	location="${j2ee.lib}/mail.jar"/>
		<pathelement	location="${jaxrpc.lib}/jaxrpc-api.jar"/>
		<pathelement	location="${jaxrpc.lib}/jaxrpc-spi.jar"/>
		<pathelement	location="${jaxrpc.lib}/jaxrpc-impl.jar"/>
		<pathelement	location="${tomcat.shared.lib}/jax-qname.jar"/>
		<pathelement	location="${tomcat.common.lib}/servlet-api.jar"/>
		<pathelement	location="${saaj.lib}/saaj-api.jar"/>
		<pathelement	location="${saaj.lib}/saaj-impl.jar"/>
	</path>
	

	<taskdef name="wscompile" classname="com.sun.xml.rpc.tools.ant.Wscompile">
		<classpath refid="compile.classpath"/>
	</taskdef>
	<taskdef name="wsdeploy" classname="com.sun.xml.rpc.tools.ant.Wsdeploy">
		<classpath refid="compile.classpath"/>
	</taskdef>
	
	<target name="clean" description="Remove .war, .class and any other generated files">
		<echo message="Cleaning...."/>
		<delete failonerror="false" includeEmptyDirs="true">
		    <fileset file="${war}"/>
		    <fileset dir="${web.dir}"/>
		    <fileset dir="${gensrc.dir}"/>
		</delete>
	</target>
	

	<target name="compile" description="Compile service">
		<echo message="Compiling the service...."/>
		<echo message="  ...mkdir for classes first...."/>
		<mkdir dir="${classes.dir}"/>		
		<echo message="  ...java classes next...."/>	
		<javac 
			srcdir="${src.dir}"
			destdir="${classes.dir}"
			debug="${compile.debug}"
			fork="true">
			<classpath refid="compile.classpath"/>			
		</javac>
		<echo message="  ...mkdir for generated code next...."/>
		<mkdir dir="${gensrc.dir}"/>		
		<echo message="	...generate stubs/skeletons next...."/>
		<wscompile
			server="true"
			keep="true"
			features="wsi,documentliteral"
			xPrintStackTrace="true"
			verbose="true"
			base="${classes.dir}"
			model="${web.dir}/model.gz"
			classpath="${web.dir}"
			config="${src.dir}/config.xml">
			<classpath>
			   <path refid="compile.classpath"/>
			</classpath>
		</wscompile>
		<move todir="${gensrc.dir}">
			<fileset dir="${classes.dir}">
				<include name="**/*.java"/>
			</fileset>
		</move>
	</target>

	<target name="clean-compile" description="Clean and Compile service" depends="clean,compile">
	</target>
	
	
	<target name="build" description="Build the service" depends="compile">
		<echo message="Warring the service...."/>
		<echo message="	...copying xml files...."/>
		<copy file="${src.dir}/web.xml" todir="${web.dir}"/>
		<copy file="${src.dir}/jaxrpc-ri.xml" todir="${web.dir}"/>
		<echo message="	...warring...."/>
		<war destfile="$tmp{war}"
		 	webxml="${web.dir}/web.xml">
			<webinf dir="${web.dir}"/>
		</war>
		<echo message="Building the service...."/>
		<wsdeploy
			keep="false"
			inWarFile="$tmp{war}"
			outWarFile="${war}"
			verbose="true">
			<classpath refid="compile.classpath"/>
		</wsdeploy>
		<delete failonerror="false" includeEmptyDirs="true">
		    <fileset file="$tmp{war}"/>
		</delete>
	</target>

	<target name="clean-build" description="Clean and then build the service" depends="clean,build">
	</target>


	<target name="deploy" description="Deploy and run the service" >
		<echo message="Deploying and run the service...."/>
		<copy file="${war}" todir="${tomcat.apps}"/>
		<antcall target="start"/>	
	</target>


	<target name="stop" description="Stop the server">
		<echo message="Stopping the server...."/>
		<exec dir="${tomcat.bin}" spawn="true" executable="catalina.bat">
		  <arg line="stop"/>
		</exec>				
	</target>
	
	<target name="start" description="Start the server">
		<echo message="Starting the server...."/>
		<exec dir="${tomcat.bin}" spawn="true" executable="catalina.bat">
		  <arg line="start"/>
		</exec>				
	</target>

	<target name="restart" description="Restart service" depends="stop,start">
	</target>

</project>
