<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="templateApp" default="build">
	<property file="build.properties"/>
	<property name="build.dir"	value="${basedir}/build"/>
	<property name="build.classes.dir"	value="${build.dir}/classes"/>
	<property name="src.dir"	value="${basedir}/src"/>
	<property name="dist.dir"	value="${basedir}/dist"/>
	<property name="conf.dir"	value="${basedir}/etc"/>
	<property name="conf.hibernate.dir"	value="${conf.dir}/hibernate"/>
	<property name="doc.dir"	value="${build.dir}/doc"/>
	<property name="test.reports.dir"	value="${build.dir}/reports/"/>

	<property name="data.dir" value="${basedir}/data"/>
	<property name="db.file"	value="${data.dir}/POSdb"/>
	<property name="db.alias"	value="POS"/>
	<property name="db.url"	value="jdbc:hsqldb:hsql://localhost/POS"/>

	<property name="lib.dir" value="${basedir}/lib"/>
	<property name="lib.hibernate.dir" value="${lib.dir}/hibernate"/>

	<path id="compile.classpath">
		<fileset dir="${lib.dir}">
			<include name="*.jar"/>
		</fileset>

		<fileset dir="${lib.hibernate.dir}">
			<include name="*.jar"/>
		</fileset>
	</path>

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

		<fileset dir="${lib.hibernate.dir}">
			<include name="*.jar"/>
		</fileset>
	</path>
	
	<target name="run" depends="dist" description="Run the template application">
		<java
			classname="ee.ut.math.tvt2008.salessystem.SalesSystem"
			classpathref="test.classpath"
			fork="yes"
		/>
	</target>

	<target name="runc" depends="dist" description="Run the template application (console)">
			<java
				classname="ee.ut.math.tvt2008.salessystem.SalesSystem"
				classpathref="test.classpath"
				fork="yes">
				<arg value="console" />
			</java>
		</target>

	<target name="build" description="Build the system">
		<mkdir dir="${build.dir}"/>
		<mkdir dir="${build.classes.dir}"/>
		<javac
			srcdir="${src.dir}"
			destdir="${build.classes.dir}"
			debug="true"
			debuglevel="lines,vars,source"
			encoding="utf-8"
			compiler="modern"
			target="1.5"
			source="1.5"
		>
		<classpath refid="compile.classpath"/>
			<compilerarg value="-Xlint:unchecked" />
			<compilerarg value="-Xlint:deprecation" />
		</javac>
	</target>

	<target name="dist" depends="build" description="Build distribution unit"> 
		<mkdir dir="${dist.dir}"/>

		<!-- lets copy the xml conf files -->
		<copy todir="${build.classes.dir}" flatten="yes">
			<fileset dir="${conf.dir}">
				<include name="**/*xml"/>
			</fileset>
		</copy>
		
		<!-- lets copy the .properties conf files -->
		<copy todir="${build.classes.dir}" flatten="yes">
			<fileset dir="${conf.dir}">
				<include name="**/*properties"/>
			</fileset>
		</copy>

		<jar destfile="${dist.dir}/${ant.project.name}.jar">
			<fileset dir="${build.classes.dir}"/>
		</jar>
	</target>

	<!-- Build internal documentation -->
	<target name="javadoc" description="Build internal documentation">
		<mkdir dir="${doc.dir}"/>
		<javadoc destdir="${doc.dir}"
				classpathref="compile.classpath"
			>
			<fileset dir="${src.dir}" includes="**/*.java"/>
		</javadoc>
	</target>

	<!-- Clean up build system results -->
	<target name="clean" description="Clean up build system results">
			<delete dir="${build.dir}"/>
			<delete dir="${dist.dir}"/>
	</target>

	<!-- Show the db manager -->
	<target name="dbmanager" description="Start the HSQLDB manager">
		<java
			classname="org.hsqldb.util.DatabaseManagerSwing"
			classpathref="test.classpath"
			fork="yes"
		>
			<arg line="--user sa --url ${db.url}" />
		</java>
	</target>

	<target name="startdb" description="Start the HSQLDB with the default params">
		<java
			classname="org.hsqldb.Server"
			classpathref="test.classpath"
			fork="yes"
		>
			<arg line="-database.0 '${db.file}' -dbname.0 '${db.alias}'" /> 
		</java>
	</target>

</project>

