<?xml version="1.0" standalone="yes" ?>
<project name="PROJECT" basedir="." default="build">
	<description>
		Build file for distribution of Olsrd Pud Plugin Wireformat Library Java Bindings
    </description>


	<!-- Properties -->
	<property name="fullname" value="Olsrd Pud Plugin Wireformat Library Java Bindings" />

	<property name="name" value="PROJECT" />
	<property name="version" value="PLUGIN_VER" />

	<property name="debug" value="DEBUG" />
	<property name="debug.flags" value="lines,vars,source" />
	<property name="source.version" value="JAVAVERSIONSRC" />
	<property name="target.version" value="JAVAVERSIONDST" />

	<property name="build.dir" location="${basedir}/BUILD_DIR/classes" />
	<property name="src.dir" location="${basedir}/JAVASRC" />
	<property name="lib.dir" location="${basedir}/LIBDIR_BUILD" />

	<property name="jar.file" value="${lib.dir}/${name}.jar" />

	<property name="javadoc.dir" location="${basedir}/doc/javadoc" />
	<property name="javac.bootclasspath" location="${basedir}/resources/ee.j2se/${source.version}/ee.j2se.jar" />

	<!--

	 Targets

	-->

	<target name="getgitcommit" description="Retrieve the Git Commit SHA1">
		<exec dir="${basedir}" executable="git" outputproperty="git.commit.descriptor" failonerror="false" error="/dev/null">
			<arg value="describe" />
			<arg value="--dirty" />
			<arg value="--always" />
		</exec>
		<exec dir="${basedir}" executable="git" outputproperty="git.commit.sha" failonerror="false" error="/dev/null">
			<arg value="rev-parse" />
			<arg value="HEAD" />
		</exec>
	</target>

	<target name="init" description="initialisation build environment for ${name}">
		<mkdir dir="${build.dir}" />
	</target>

	<target name="clean" description="clean build environment">
		<delete dir="${build.dir}" />
		<delete dir="${javadoc.dir}" />
	</target>

	<target name="build" description="Build plugin jar file" depends="clean,init,getgitcommit">
		<echo message="Compiling Plugin classes. (debug: ${debug})" />
		<javac bootclasspath="${javac.bootclasspath}" srcdir="${src.dir}" destdir="${build.dir}" source="${source.version}" target="${target.version}" debug="${debug}" debuglevel="${debug.flags}" includeantruntime="false" />

		<delete file="${jar.file}" />
		<jar destfile="${jar.file}">
			<fileset dir="${build.dir}">
				<include name="**/*.class" />
			</fileset>
			<manifest>
				<attribute name="Class-Path" value="." />
				<attribute name="Version" value="${version}" />
				<attribute name="Git-Descriptor" value="${git.commit.descriptor}" />
				<attribute name="Git-SHA" value="${git.commit.sha}" />
			</manifest>
		</jar>
	</target>

	<target name="src-zip" depends="init">
		<!-- make the zip file -->
		<zip zipfile="${lib.dir}/${name}-src.zip">
			<zipfileset dir="${src.dir}" />
		</zip>
	</target>

	<target name="release" description="Build plugin jar file" depends="clean, init, build, src-zip, javadoc-zip">
	</target>

	<!-- Generate JavaDoc -->
	<target name="javadoc">
		<delete dir="${javadoc.dir}" />
		<mkdir dir="${javadoc.dir}" />
		<javadoc bootclasspath="${javac.bootclasspath}" destdir="${javadoc.dir}" windowtitle="${fullname}" use="yes" linksource="yes" splitindex="yes" access="private" author="true" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" version="true" source="${source.version}" sourcepath="${src.dir}" maxmemory="256M">
			<packageset dir="${src.dir}" defaultexcludes="yes">
				<include name="org/olsr/**" />
			</packageset>
		</javadoc>
	</target>

	<!-- Create zip file containing the API HTML pages. -->
	<target name="javadoc-zip" depends="init,javadoc">
		<!-- make the zip file -->
		<zip zipfile="${lib.dir}/${name}-doc.zip">
			<zipfileset dir="${javadoc.dir}" />
		</zip>
	</target>

</project>
