<?xml version="1.0" encoding="UTF-8"?>
<project name="google" default="jar" basedir=".">
	<description>Google Tag Library</description>
	<!-- Load the properties -->
	<property file="build.properties"/>
	<!-- Build Locations -->
	<property name="build.library" value="${build.dir}/${project.name}"/>
	<property name="build.ex" value="${build.dir}/${ex.dir}"/>
	<property name="build.unit" value="${build.dir}/${unit.dir}"/>
	<property name="build.release" value="${build.dir}/${release.name}"/>
	<!-- Jar excludes directories and files -->
	<patternset id="jar.excludes">
		<exclude name="**/*.java"/>
		<exclude name="**/*.xml"/>
		<exclude name="**/*.html"/>
		<exclude name="**/.dependency-info/**"/>
	</patternset>
	<!-- Classpath -->
	<path id="classpath">
		<pathelement location="."/>
		<fileset dir="${lib.dir}">
			<include name="**/*.jar"/>
			<include name="**/*.zip"/>
		</fileset>
	</path>
	<!-- Prepare target -->
	<target name="prepare">
		<mkdir dir="${build.dir}"/>
		<mkdir dir="${dist.dir}"/>
		<mkdir dir="${javadoc.dir}"/>
		<mkdir dir="${tlddoc.dir}"/>
	</target>
	<!-- Compile target -->
	<target name="compile" depends="prepare" description="Compiles sources">
		<mkdir dir="${build.library}"/>
		<javac srcdir="${src.dir}" destdir="${build.library}" target="1.1">
			<classpath refid="classpath"/>
		</javac>
	</target>
	<!-- JAR target -->
	<target name="jar" depends="compile" description="Builds the JAR">
		<!-- Create the JAR -->
		<jar jarfile="${dist.dir}/${project.name}.jar">
			<fileset dir="${build.library}">
				<patternset refid="jar.excludes"/>
			</fileset>
		</jar>
	</target>
	<!-- TLDs target -->
	<target name="tlds" description="Builds the TLDs">
		<!-- Copy the TLDs -->
		<filter token="version" value="${version}"/>
		<copy file="${tlds.dir}/${project.name}.tld" todir="${dist.dir}" filtering="true"/>
		<copy file="${tlds.dir}/${project.name}-1.2.tld" todir="${dist.dir}" filtering="true"/>
	</target>
	<!-- Examples target -->
	<target name="examples" depends="jar,tlds" description="Builds the Examples WAR">
		<!-- Copy the WAR dir -->
		<copy todir="${build.ex}">
			<fileset dir="${ex.dir}"/>
		</copy>
		<!-- Copy the TLD -->
		<copy file="${dist.dir}/${project.name}.tld" todir="${build.ex}/WEB-INF"/>
		<!-- Copy the license -->
		<copy file="${licenses.dir}/${doc.license}" todir="${build.ex}"/>
		<!-- Copy the JAR -->
		<copy file="${dist.dir}/${project.name}.jar" todir="${build.ex}/WEB-INF/lib/"/>
		<!-- Freeze the mod dates -->
		<touch>
			<fileset dir="${build.ex}"/>
		</touch>
		<!-- Create the web archive -->
		<jar jarfile="${dist.dir}/${ex.dir}-${version}.war" basedir="${build.ex}"/>
	</target>
	<!-- TagUnit target -->
	<target name="tagunit" depends="jar,tlds" description="Builds the TagUnit WAR">
		<!-- Copy the WAR dir -->
		<copy todir="${build.unit}">
			<fileset dir="${unit.dir}"/>
		</copy>
		<!-- Copy the TLD -->
		<copy file="${dist.dir}/${project.name}.tld" todir="${build.unit}/WEB-INF"/>
		<!-- Copy the license -->
		<copy file="${licenses.dir}/${doc.license}" todir="${build.unit}"/>
		<!-- Copy the JAR -->
		<copy file="${dist.dir}/${project.name}.jar" todir="${build.unit}/WEB-INF/lib/"/>
		<!-- Copy the TagUnit lib -->
		<copy file="${lib.dir}/${unit.lib}" todir="${build.unit}/WEB-INF/lib/"/>
		<!-- Freeze the mod dates -->
		<touch>
			<fileset dir="${build.unit}"/>
		</touch>
		<!-- Create the web archive -->
		<jar jarfile="${dist.dir}/${unit.dir}-${version}.war" basedir="${build.unit}"/>
	</target>
	<!-- Release target -->
	<target name="release" depends="jar,tlds" description="Builds the release archives">
		<mkdir dir="${build.release}"/>
		<!-- Copy the TLD -->
		<filter token="version" value="${version}"/>
		<copy file="${tlds.dir}/${project.name}.tld" todir="${build.release}" filtering="true"/>
		<!-- Copy the license -->
		<copy file="${licenses.dir}/${doc.license}" todir="${build.release}"/>
		<!-- Copy the readme -->
		<copy file="${doc.readme}" todir="${build.release}"/>
		<!-- Copy the JAR -->
		<copy file="${dist.dir}/${project.name}.jar" todir="${build.release}"/>
		<!-- Freeze the mod dates -->
		<touch>
			<fileset dir="${build.release}"/>
		</touch>
		<!-- Create the ZIP archive -->
		<zip destfile="${dist.dir}/${release.name}.zip" basedir="${build.release}"/>
		<!-- Create the TAR archive -->
		<tar tarfile="${dist.dir}/${release.name}.tar.gz" compression="gzip">
			<tarfileset dir="${build.release}" prefix="${release.name}" mode="644"/>
		</tar>
	</target>
	<!-- Src target -->
	<target name="src" description="Builds the source archive">
		<!-- Create the TAR archive -->
		<tar tarfile="${dist.dir}/${release.name}-src.tar.gz" compression="gzip">
			<tarfileset dir="${basedir}" prefix="${release.name}">
				<include name="${src.dir}/**"/>
				<include name="${tlds.dir}/**"/>
				<include name="${lib.dir}/**"/>
				<include name="${licenses.dir}/**"/>
				<include name="${ex.dir}/**"/>
				<include name="${unit.dir}/**"/>
				<include name="${doc.readme}"/>
				<include name="${doc.dir}/**"/>
				<include name="${doc.src}"/>
				<include name="build.*"/>
				<exclude name="${src.excludes}"/>
			</tarfileset>
		</tar>
	</target>
	<!-- Javadoc target -->
	<target name="javadoc" depends="prepare" description="Builds the Javadoc">
		<delete quiet="true" includeEmptyDirs="true">
			<fileset dir="${javadoc.dir}" includes="*,*/**"/>
		</delete>
		<javadoc sourcepath="${src.dir}" destdir="${javadoc.dir}" packagenames="${javadoc.packages}" windowtitle="${javadoc.title}" verbose="false" failonerror="true" additionalparam="-breakiterator -tag created:Xt:&quot;Created:&quot;">
			<classpath refid="classpath"/>
		</javadoc>
	</target>
	<!-- TLDDoc target -->
	<target name="tlddoc" depends="prepare,tlds" description="Builds the TLD documentation">
		<delete quiet="true" includeEmptyDirs="true">
			<fileset dir="${tlddoc.dir}" includes="*,*/**"/>
		</delete>
		<java jar="${lib.dir}/tlddoc.jar" failonerror="true" fork="true">
			<arg line="-windowtitle &quot;${javadoc.title}&quot; -doctitle &quot;${javadoc.title}&quot; -d ${tlddoc.dir} ${dist.dir}/${project.name}-1.2.tld"/>
		</java>
	</target>
	<!-- DocCheck target -->
	<target name="doccheck" depends="prepare" description="Checks the Javadoc">
		<delete quiet="true" includeEmptyDirs="true">
			<fileset dir="${javadoc.dir}" includes="*,*/**"/>
		</delete>
		<javadoc sourcepath="${src.dir}" packagenames="${javadoc.packages}" destdir="${javadoc.dir}" verbose="false" failonerror="true" doclet="com.sun.tools.doclets.doccheck.DocCheck" docletpath="${lib.dir}/doccheck.jar">
			<classpath refid="classpath"/>
		</javadoc>
	</target>
	<!-- Clean Build target -->
	<target name="clean-build" description="Cleans the build directory">
		<delete quiet="true" includeEmptyDirs="true">
			<fileset dir="${build.dir}" includes="*,*/**"/>
		</delete>
		<mkdir dir="${build.library}"/>
	</target>
	<!-- Clean target -->
	<target name="clean" depends="clean-build" description="Cleans the build and dist directories">
		<delete quiet="true" includeEmptyDirs="true">
			<fileset dir="${dist.dir}" includes="*,*/**"/>
		</delete>
	</target>
</project>
