<project name="EnumerationProblem" default="all">
	<target name="all" depends="init,cleanAll,compileWsdl,compile,jar,package,war" />

	<target name="setprops.init">
		<property environment="env" />

		<!-- the name of the global property file to include. -->
		<property name="global.file" value="../build.properties/global.properties" />
		<available file="${global.file}" property="global.file.exists" />

		<!-- check to see if BUILD.ENV is even set -->
		<condition property="build.env.exists" value="true">
			<isset property="BUILD.ENV" />
		</condition>
	</target>

	<!-- main target to include personal and global properties -->
	<target name="setprops" depends="setprops.init,setprops.includePersonal,setprops.includeGlobal">
		<description>
			This target should be called to initialize the build environment.  If BUILD.ENV is defined,
			it will include ${BUILD.ENV}.properties before including global.properties.
		</description>

	</target>

	<!-- this will include the global file if it existed -->
	<target name="setprops.includeGlobal" if="global.file.exists">
		<echo message="Including global property file, ${global.file}." />
		<property file="${global.file}" />
	</target>

	<!-- this will only include personal properties if the personal file existed -->
	<target name="setprops.includePersonal" if="build.env.exists">
		<echo message="Building property set.  Attempting to include personal property file, ${BUILD.ENV}.properties." />
		<property file="../build.properties/${BUILD.ENV}.properties" />
	</target>

	<target name="init" depends="setprops">
		<property name="src" value="src" />
		<property name="build" value="build" />
		<property name="dist" value="dist" />
		<property name="lib" value="lib" />
		<property name="etc" value="etc" />
		<property name="generated" value="generated" />
		<path id="xfire.classpath">
			<fileset dir="${lib}/xfire">
				<include name="**/*.jar" />
			</fileset>
		</path>

		<taskdef name="wsgen" classname="org.codehaus.xfire.gen.WsGenTask" 
		     classpathref="xfire.classpath"/>

		<path id="project.classpath">
			<fileset dir="${lib}">
				<include name="*.jar" />
			</fileset>
			<path refid="xfire.classpath" />
		</path>
	</target>

	<target name="clean" depends="init">
		<delete dir="${build}" />
		<delete dir="${generated}" />
	</target>

	<target name="cleanAll" depends="clean">
		<delete dir="${dist}" />
	</target>

	<target name="compileWsdl" depends="init">
		<mkdir dir="${generated}/src" />
		<wsgen outputDirectory="${generated}/src"
			package="com.bt.capabilities.enumeration.service"
		  wsdl="${etc}/Enumeration.wsdl" overwrite="true"/>		

		<!-- delete the generated implementations -->
		<delete dir="${generated}/src/com/bt">
			<include name="**/*ServiceImpl.java"/>
		</delete>
	</target>
	
	<target name="compile" depends="init">
		<mkdir dir="${build}" />
		<javac includes="**/*.java" debug="${build.debug}" destdir="${build}">
			<src path="${src}" />
			<src path="${generated}/src" />
			<classpath refid="project.classpath" />
		</javac>
	</target>

	<target name="jar" depends="compile">
		<jar destfile="${build}/${ant.project.name}.jar" basedir="${build}" includes="com/**, org/**" excludes="**/tests/*.class" />
	</target>

	<target name="package" depends="jar">
		<mkdir dir="${build}/war/WEB-INF/lib" />
		<mkdir dir="${build}/war/META-INF/xfire" />
		<mkdir dir="${build}/war/WEB-INF/classes" />
		<copy todir="${build}/war/WEB-INF/lib">
			<fileset dir="${lib}/xfire">
				<exclude name="servlet-api-2.3.jar" />
			</fileset>
		</copy>
		<copy todir="${build}/war/WEB-INF/lib" file="${build}/${ant.project.name}.jar" />
		<copy todir="${build}/war/WEB-INF" file="${etc}/web.xml" />
		<copy todir="${build}/war/META-INF/xfire" file="${etc}/services.xml" />
	</target>

	<target name="war" depends="package">
		<mkdir dir="${dist}" />
		<jar basedir="${build}/war" includes="**" destfile="${dist}/${ant.project.name}.war" />
	</target>

	<target name="deploy" depends="war">
		<copy file="${dist}/${ant.project.name}.war" todir="${jboss.home}/server/default/deploy" overwrite="true"/>
	</target>

	<target name="undeploy" depends="init">
		<delete file="${jboss.home}/server/default/deploy/${ant.project.name}.war"/>
	</target>
	
	<target name="client" depends="init">
		<java fork="yes" classname="com.bt.capabilities.enumeration.service.Client">
			<classpath>
				<path location="${build}"/>
				<path refid="project.classpath"/>
			</classpath>
		</java>
	</target>
</project>
