<?xml version="1.0" encoding="UTF-8"?>
<project name="TinyMCE" default="release" basedir=".">
	<property description="Export directory" name="export_dir" value="export" />
	<property description="Package directory" name="package_dir" value="export" />

	<!-- Allow any user specific values to override the defaults -->
	<property file="${user.home}/tinymce_spellchecker_php_build.properties" />

	<!-- Setup classpath for js-build-tools ant tasks -->
	<path id="tasks.classpath">
		<pathelement location="."/>

		<fileset dir="../../tinymce/trunk/tools/ant">
			<include name="**/*.jar"/>
		</fileset>
	</path>

	<!-- Register new js-build-tools ant tasks -->
	<typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" /> 
	<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />

	<!-- Cleanup the build -->
	<target name="clean" depends="" description="Cleans up the project from temporary files">
		<delete dir="${export_dir}" quiet="true" />
	</target>

	<target name="release" depends="" description="Compresses the exported SVN trunks">
		<delete dir="${export_dir}" quiet="true" />

		<svn javahl="${javahl}">
			<export srcUrl="https://tinymce.svn.sourceforge.net/svnroot/tinymce/spellchecker_php/trunk" destPath="${export_dir}/spellchecker_php" />
			<export srcUrl="https://tinymce.svn.sourceforge.net/svnroot/tinymce/tinymce/trunk/jscripts/tiny_mce/plugins/spellchecker" destPath="${export_dir}/spellchecker" />
		</svn>

		<!-- Parse minor version, major version and release date from changelog -->
		<loadfile property="changelog" srcFile="${export_dir}/spellchecker_php/changelog.txt" />
		<propertyregex property="version" input="${changelog}" regexp="^Version ([0-9xabrc.]+)" select="\1" />
		<propertyregex property="release_date" input="${changelog}" regexp="^Version [^\(]+\(([^\)]+)\)" select="\1" />
		<propertyregex property="file_version" input="${version}" regexp="\." replace="_" />

		<!-- Replace backend with php -->
		<replaceregexp match="\&quot;\{backend\}\&quot;" replace="this.url+'/rpc.php'" flags="g" byline="true">
			<fileset dir="${export_dir}">
				<include name="**/*.js*" />
			</fileset>
		</replaceregexp>

		<!-- Compress development package -->
		<delete file="${package_dir}/tinymce_spellchecker_php_${file_version}.zip" quiet="true" />
		<zip destfile="${package_dir}/tinymce_spellchecker_php_${file_version}.zip">
			<zipfileset dir="${export_dir}/spellchecker_php" prefix="spellchecker" />
			<zipfileset dir="${export_dir}/spellchecker" prefix="spellchecker" />
		</zip>
	</target>
</project>
