<?xml version="1.0"?>

<project name="daruma" default="all">

	<property name="src.dir"      value="src"/>
	<property name="lib.dir"      value="lib"/>
	<property name="classes.dir"  value="classes"/>
	<property name="main.class"   value="daruma.server.DarumaDaemon"/>
	<property name="main.jar"     value="daruma.jar"/>
	<property name="test.jar"     value="daruma-test.jar"/>
	<property name="main.war"     value="daruma.war"/>
	<property name="main.wardir"  value="war"/>
	<property name="template.dir" value="war-template"/>

	<property name="property.file" value="daruma.properties"/>
	<property name="log.dir"     value="log"/>
	<!--
	<property name="encoding"    value="UTF-8"/>
	-->
	<property name="encoding"    value="EUC-JP"/>

	<property name="javac.debug" value="true"/>
	<property name="javac.optimize" value="true"/>
	<property name="javac.deprecation" value="true"/>
	<!--
	<property name="javac.source" value="1.5"/>
	<property name="javac.target" value="1.5"/>
	-->
	<property name="javadoc.dir"  value="doc/javadoc"/>



	<path id="classpath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar"/>
			<exclude name="**/junit-*.jar"/>
		</fileset>
		<pathelement path="${classes.dir}"/>
	</path>



	<path id="testclasspath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar"/>
		</fileset>
		<pathelement path="${classes.dir}"/>
	</path>



	<target name="all" depends="check,javadoc"/>



	<target name="compile">
		<mkdir dir="${classes.dir}"/>
		<javac srcdir="${src.dir}"
		       destdir="${classes.dir}"
		       classpathref="classpath"
		       optimize="${javac.optimize}"
		       debug="${javac.debug}"
		       deprecation="${javac.deprecation}">

			<!-- -Xlint option is Sun JDK only -->
			<compilerarg value="-Xlint"/>
			<compilerarg value="-Xlint:-path"/> <!-- Avoid error messages about class path abuse. This is required for "ant" for Debian GNU/Linux -->

			<include name="**/*.java"/>
			<exclude name="**/*Test.java"/>
		</javac>

		<jar jarfile="${main.jar}" basedir="${classes.dir}" index="yes">
		  <include name="**/*.class"/>
		  <exclude name="**/test/*Test.class"/>
		  <manifest>
		    <attribute name="Main-Class" value="daruma.server.DarumaDaemon"/>
		    <attribute name="Class-Path" value="lib/xerces-j-2.7.1/xml-apis.jar lib/xerces-j-2.7.1/xercesImpl.jar lib/xerces-j-2.7.1/resolver.jar lib/xalan-j-2.7.0/xalan.jar lib/xalan-j-2.7.0/serializer.jar lib/mysql-connector-java-5.0.5-bin.jar lib/jts-1.7.2.jar lib/servletapi-gump-27012008.jar lib/log4j-1.2.13.jar lib/junit-4.1.jar"/>
		  </manifest>
		  <indexjars>
		    <pathelement path="lib/xerces-j-2.7.1/xml-apis.jar:lib/xerces-j-2.7.1/xercesImpl.jar:lib/xerces-j-2.7.1/resolver.jar:lib/xalan-j-2.7.0/xalan.jar:lib/xalan-j-2.7.0/serializer.jar:lib/mysql-connector-java-5.0.5-bin.jar:lib/jts-1.7.2.jar:lib/servletapi-gump-27012008.jar:lib/log4j-1.2.13.jar:lib/junit-4.1.jar"/>
		  </indexjars>
		</jar>


		<copy todir="${main.wardir}">
		  <fileset dir="${template.dir}"/>
		</copy>
		<copy todir="${main.wardir}/WEB-INF/classes">
		  <fileset dir="${classes.dir}"/>
		</copy>
		<copy file="${property.file}"
		      todir="${main.wardir}/WEB-INF/classes"/>

		<copy file="${lib.dir}/xerces-j-2.7.1/xml-apis.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/xerces-j-2.7.1/xercesImpl.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/xerces-j-2.7.1/resolver.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/xalan-j-2.7.0/xalan.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/xalan-j-2.7.0/serializer.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/mysql-connector-java-5.0.5-bin.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/jts-1.7.2.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/servletapi-gump-27012008.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/log4j-1.2.13.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>
		<copy file="${lib.dir}/junit-4.1.jar"
		      todir="${main.wardir}/WEB-INF/lib"/>

		<jar jarfile="${main.war}" basedir="${main.wardir}">
		  <manifest/>
		</jar>

	</target>


	<target name="buildtest" depends="compile">
		<mkdir dir="${classes.dir}"/>
		<javac srcdir="${src.dir}"
		       destdir="${classes.dir}"
		       optimize="${javac.optimize}"
		       debug="${javac.debug}"
		       classpathref="classpath"
		       deprecation="${javac.deprecation}">

			<!-- -Xlint option is Sun JDK only -->
			<compilerarg value="-Xlint"/>
			<compilerarg value="-Xlint:-path"/> <!-- Avoid error messages about class path abuse. This is required for "ant" for Debian GNU/Linux -->

			<include name="**/*.java"/>
		</javac>
		<jar jarfile="${test.jar}" basedir="${classes.dir}">
		  <include name="**/test/*Test.class"/>
		</jar>
	</target>



	<target name="check" depends="buildtest,compile">
		<junit fork="yes"
		       haltonfailure="false"
		       showoutput="yes"
		       printsummary="yes">
			<formatter type="plain" usefile="false"/>
			<classpath refid="testclasspath"/>
			<batchtest>
				<fileSet dir="${src.dir}">
					<include name="**/*Test.java"/>
				</fileSet>
			</batchtest>
		</junit>
	</target>



	<target name="javadoc">
		<javadoc sourcepath="${src.dir}" destdir="${javadoc.dir}" classpathref="classpath">
			<arg value="-quiet"/>
			<fileset dir="${src.dir}">
				<include name="**/*.java"/>
				<exclude name="**/*Test.java"/>
			</fileset>
		</javadoc>
	</target>



	<target name="run" depends="compile">
		<java classname="${main.class}"
		      classpath="${classes.dir}:${lib.dir}"/>
	</target>



	<target name="clean">
		<delete dir="${log.dir}"/>
		<delete dir="${classes.dir}"/>
		<delete file="${main.jar}"/>
		<delete file="${main.war}"/>
		<delete dir="${main.wardir}"/>
		<delete file="${test.jar}"/>
		<delete dir="${javadoc.dir}"/>
	</target>


</project>
