<?xml version="1.0" encoding="UTF-8"?>
<!--
	Copyright (c) 2009 Chris Aniszczyk and others.
    All rights reserved. This program and the accompanying materials
    are made available under the terms of the Eclipse Public License v1.0
    which accompanies this distribution, and is available at
    http://www.eclipse.org/legal/epl-v10.html
    
    Contributors:
        Chris Aniszczyk - initial API and implementation
        Torkild U. Resheim - Adapted to build EPUB Ant support
-->
<project name="Build EPUB Ant Support Jar" default="build">

	<target name="build" description="Cleans, builds and refreshes" depends="clean, lib/epub-ant.jar" />

	<target name="init" depends="properties">
		<property name="temp.folder" location="${basedir}/temp.folder" />
		<property name="build.result.folder" location="${basedir}" />
		<property name="src.folder" location="${basedir}/src" />
	</target>

	<target name="properties" if="eclipse.running">
		<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />
	</target>

	<target name="lib/epub-ant.jar" description="Creates the lib/epub-ant.jar" depends="init">
		<property name="destdir" value="${temp.folder}/lib/epub-ant.bin" />
		<property name="target.platform.path" value="${eclipse.home}" />
		<delete dir="${destdir}" />
		<mkdir dir="${destdir}" />
		<mkdir dir="${build.result.folder}/lib" />
		<!-- compile the source code -->
		<javac target="1.5" source="1.5" destdir="${destdir}" failonerror="true" verbose="false" debug="on">
			<classpath>
				<dirset dir="${basedir}/../">
					<include name="org.eclipse.mylyn.docs.epub.core/bin" />
				</dirset>
			</classpath>
			<src path="${src.folder}" />
		</javac>
		<!-- copy the *.class files to the jar location -->
		<copy todir="${destdir}" failonerror="true" overwrite="false">
			<fileset dir="${src.folder}">
				<exclude name="**/*.java" />
				<exclude name="**/package.htm*" />
			</fileset>
		</copy>
		<jar destfile="${build.result.folder}/lib/epub-ant.jar" basedir="${destdir}" />
		<delete dir="${temp.folder}" />
	</target>

	<target name="clean" description="Deletes previous build remnants" depends="init">
		<delete file="${build.result.folder}/lib/epub-ant.jar" />
		<delete dir="${temp.folder}" />
	</target>
</project>
