<?xml version="1.0" encoding="UTF-8"?>
<project name="Hal" default="" >
	
	<!-- ________________________ PROPERTIES AND SETTINGS ________________________ -->
	
	<!--common properties-->
	<property name="gitRoot" value="." />
	<property name="srcDir" value="${gitRoot}/src" />
	<property name="testDir" value="${gitRoot}/test" />
	<property name="libDir" value="${gitRoot}/lib" />
	<property name="buildDir" value="${gitRoot}/build" />
	
	<!--define standard arduments for javac-->
	<presetdef name="javac">
		<javac includeantruntime="false" />
	</presetdef>
	
	<!-- ________________________ CLASSPATHS ________________________ -->
	
	<!--classpath included when building-->
	<path id="classpath.build">
		<pathelement location="${libDir}/*" />
	</path>
	
	<!-- ________________________ PUBLIC TARGETS ________________________ -->
	
	<target name="run-remote-sensor" depends="">
		<java fork="true" failonerror="true" classname="se.hal.plugin.tellstick.TelstickSerialCommTest">
			<classpath>
				<pathelement path="${buildDir}/hal.jar"/>	<!--wildcard may not be platform independent, ok?-->
				<pathelement path="${libDir}/*"/>	<!--wildcard may not be platform independent, ok?-->
			</classpath>
		</java>
	</target>
	
	<target name="run-main-server" depends="">
		<java fork="true" failonerror="true" classname="se.hal.HalServer">
			<classpath>
				<pathelement path="${buildDir}/hal.jar"/>	<!--wildcard may not be platform independent, ok?-->
				<pathelement path="${libDir}/*"/>	<!--wildcard may not be platform independent, ok?-->
			</classpath>
		</java>
	</target>

	<target name="clear-aggr-data-from-db" depends="">
		<exec executable="sqlite3">
			<arg line="hal.db 'DELETE FROM sensor_data_aggr'" />
		</exec>
		
		<!-- update all internal sensors aggregation version to indicate for peers that they need to re-sync all data -->
		<exec executable="sqlite3">
			<arg line="hal.db 'UPDATE sensor SET aggr_version = aggr_version+1) WHERE id = (SELECT sensor.id FROM user, sensor WHERE user.external == 0 AND sensor.user_id = user.id)'" />
		</exec>
		
	</target>
	
	<!--clean all build paths-->
	<target name="clean">
		<delete includeemptydirs="true" failonerror="false">
			<fileset dir="${buildDir}" includes="**/*"/>
		</delete>
	</target>
	
	<!--build product code-->
	<target name="build" depends="build-dependencies">
		<mkdir dir="${buildDir}" />
		<javac srcdir="${srcDir}" destdir="${buildDir}" debug="yes" fork="yes">
			<include name="**/*.java" />
			<exclude name="se/hal/tts/GoogleTTSClient.java" />
			<classpath refid="classpath.build" />
		</javac>
		<javac srcdir="${testDir}" destdir="${buildDir}" debug="yes" fork="yes">
			<include name="**/*.java" />
			<exclude name="se/hal/test/JarvisSyntersizerTest.java" />
			<classpath refid="classpath.build" />
		</javac>
		<jar destfile="${buildDir}/hal.jar" basedir="${buildDir}" excludes="hal.jar" />
	</target>
	
	<target name="build-dependencies">
		<mkdir dir="${buildDir}" />
		<get src="http://repo.koc.se/zutil-java.git/blob/master/Zutil.jar" dest="${libDir}" verbose="true" usetimestamp="true"/>
	</target>
		
</project>
