<project name="BuildXML" default="build" >
	<!--
		Build the resource directory for a given implementation.
	-->

	<import file="build-import.xml" />
	<property name="resource.rootdir" location="${common.src.rootdir}/resource" />
	<property name="impl.resource.rootdir" location="${impl.src.main.dir}/resource" />

	<target name="init" depends="clean">
	</target>

	<!--
		The copy of resources is done in two steps so that we can run a filter chain on text-like files and
		not on binary-like files.
	-->
	<target name="build" depends="init, getTimezoneData" description="Builds resources">
		<copy todir="${resource.build.target.dir}" overwrite="true" flatten="true">
			<fileset dir="${resource.rootdir}" includes="*.xml, *.rdf, *.html, *.txt, *.svg" />
			<filterchain>
				<expandproperties />
				<deletecharacters chars="\t" />
				<trim />
				<ignoreblank />
				<striplinebreaks />
			</filterchain>
		</copy>
		<copy todir="${resource.build.target.dir}" overwrite="true" flatten="true">
			<fileset dir="${impl.resource.rootdir}" includes="*.xml, *.rdf, *.html, *.txt, *.svg" erroronmissingdir="false"/>
			<filterchain>
				<expandproperties />
				<deletecharacters chars="\t" />
				<trim />
				<ignoreblank />
				<striplinebreaks />
			</filterchain>
		</copy>

		<copy todir="${resource.build.target.dir}" overwrite="true" flatten="true">
			<fileset dir="${resource.rootdir}">
				<include name="*" />
				<exclude name="*.xml" />
				<exclude name="*.rdf" />
				<exclude name="*.html" />
				<exclude name="*.txt" />
				<exclude name="*.svg" />
			</fileset>
		</copy>
		<copy todir="${resource.build.target.dir}" overwrite="true" flatten="true">
			<fileset dir="${impl.resource.rootdir}" excludes="*.xml, *.rdf, *.html, *.txt, *.svg" erroronmissingdir="false">
				<include name="*" />
			</fileset>
		</copy>
		<echo message="Done building xml" />
	</target>

	<!--
		This target makes the IANA timezone database available to code which may need it.

		For example this may be used to determine the local time in a particular political
		region at a specific point in time.
	-->
	<target name="getTimezoneData">
		<property name="timezone.dir" location="${build.rootdir}/timezone"/>
		<mkdir dir="${resource.build.target.dir}/timezone"/>
		<!--
		<gunzip src="${timezone.dir}/tzdata-latest.tar.gz" dest="${timezone.dir}"/>
		<untar src="${timezone.dir}/tzdata-latest.tar" dest="${timezone.dir}/unzipped/">
			 Add .txt because of this: https://github.com/BorderTech/wcomponents/issues/540
			<regexpmapper from="^([^\.]+)$" to="\1.txt"/>
		</untar>
		-->
		<copy todir="${resource.build.target.dir}/timezone" overwrite="true">
			<fileset dir="${timezone.dir}" includes="*"/>
			<filterchain>
				<striplinecomments>
					<comment value="#"/>
				</striplinecomments>
				<tokenfilter>
					<ignoreblank/>
				</tokenfilter>
			</filterchain>
		</copy>
	</target>

	<target name="clean" description="Cleans up all artifacts produced by this build">
		<delete dir="${resource.build.target.dir}" />
		<echo message="Clean from ${ant.file}" />
	</target>
</project>
