<project name="Fitnesse" default="build" basedir=".">
	<description>
		Fitnesse is a wiki wrapper for fit, an acceptance test framework.
	</description>

	<property name="src" location="src"/>
	<property name="classes" location="classes"/>
	<property name="lib" location="lib"/>
	<property name="fitnesseRoot" value="FitNesseRoot"/>
	<property name="fitnesseRootZip" value="FitNesseRoot.zip"/>
	<property name="zipDir" location="dist/fitnesse"/>

	<path id='classpath'>
		<pathelement path="${classes}"/>
		<fileset dir="lib">
			<include name="**/*.jar"/>
		</fileset>
	</path>

	<target name="build" depends="clean, compile" description="clean, then compile the source"/>

	<target name="build_distribution" depends="zip_src, zip_bin" description="The thing you do when distributing a new release."/>

	<target name="assemble_bin" depends="clean_dist, jar" description="create the binary distribution">
		<tstamp/>
		<copy todir="${zipDir}">
			<fileset dir="extra/release" includes="**"/>
			<fileset dir="dist" includes="fitnesse.jar"/>
			<fileset dir=".">
				<include name="${fitnesseRoot}/**"/>
				<exclude name="**/*.zip"/>
				<exclude name="**/.DS_Store"/>
				<exclude name="**/Thumbs.db"/>
			</fileset>
		</copy>
		<mkdir dir="${zipDir}/dotnet"/>
		<copy todir="${zipDir}/dotnet">
			<fileset dir="dotnet">
				<include name="*.exe"/>
        <include name="*.dll"/>
			</fileset>
		</copy>
			
	</target>

	<target name="zip_bin" depends="assemble_bin" description="zip up the binary distribution">
		<zip zipfile="fitnesse${DSTAMP}.zip" basedir="dist" includes="fitnesse/**" excludes="**/Thumbs.db"/>
	</target>

	<target name="zip_src" depends="clean_dist" description="Packages all the source into a .zip file">
		<tstamp/>
		<zip zipfile="fitnesse_src${DSTAMP}.zip">
			<fileset dir=".">
				<include name="src/**"/>
				<include name="lib/**"/>
				<include name="extra/**"/>
				<include name="build.xml"/>
				<include name="dotnet/**"/>
				<include name="BUILD_README.txt"/>
				<exclude name="**/fitnesse*.zip"/>
			</fileset>
		</zip>
	</target>

	<target name="jar" depends="build" description="generate the jar file" >
		<mkdir dir="dist"/>
		<delete file="dist/fitnesse.jar"/>

		<delete dir="${classes}/files"/>
		<mkdir dir="${classes}/files"/>
		<copy todir="${classes}/files">
			<fileset dir="extra">
				<include name="images/*.gif"/>
				<include name="images/*.jpg"/>
				<include name="css/*.css"/>
				<include name="javascript/*.js"/>
				<exclude name="juUnitTestLink.js"/>
			</fileset>
		</copy>

		<jar jarfile="dist/fitnesse.jar" basedir="${classes}">
			<include name="**/*.class"/>
			<exclude name="**/*Test.class"/>
			<exclude name="**/*TestSuite.class"/>
			<include name="files/**"/>
			<manifest>
				<attribute name="Built-By" value="Robert C. Martin and Micah D. Martin"/>
			</manifest>
		</jar>
	</target>

	<target name="jar_classes" depends="build" description="generate the jar file with all the classes and only the classes" >
		<mkdir dir="dist"/>
		<delete file="dist/fitnesse_classes.jar"/>
		<jar jarfile="dist/fitnesse_classes.jar" basedir="${classes}">
			<include name="**/*.class"/>
			<manifest>
				<attribute name="Built-By" value="Robert C. Martin and Micah D. Martin"/>
			</manifest>
		</jar>
	</target>

	<target name="http_jar" depends="compile" description="create a jar of the http stuff">
		<copy todir="${classes}">
			<fileset dir="${src}" includes="**/*.java"/>
		</copy>
		
		<jar jarfile="fitnesse_http.jar" basedir="${classes}">
			<include name="fitnesse/http/**/*.class"/>
			<include name="fitnesse/socketservice/**/*.class"/>
			<include name="fitnesse/http/**/*.java"/>
			<include name="fitnesse/socketservice/**/*.java"/>
			<exclude name="**/*Test.*"/>
			<exclude name="**/*TestSuite.*"/>
		</jar>
		
		<delete>
			<fileset dir="${classes}" includes="**/*.java"/>
		</delete>
	</target>

	<target name="compile" depends="init" description="compile the source (make)">
		<javac srcdir="${src}" destdir="${classes}" classpathref="classpath"/>
	</target>

	<target name="clean" description="delete everything in the classes directory" >
		<mkdir dir="${classes}"/>
		<delete includeemptydirs="yes">
			<fileset dir="${classes}" includes="**/*"/>
		</delete>
	</target>

	<target name="test" depends="compile" description="run the unit tests">
		<junit fork='true' haltonfailure='true'>
			<classpath refid='classpath'/>
			<formatter type="brief" usefile="false"/>
			<test name='fitnesse.AllTestSuite'/>
		</junit>
	</target>

	<target name="clean_dist" description="clean out the distribution folder">
		<delete>
			<fileset dir="dist">
				<include name="fitnesse*.zip"/>
				<include name="fitnesse.jar"/>
				<exclude name="${fitnesseRoot}"/>
			</fileset>
		</delete>
		<delete dir="${zipDir}"/>
	</target>

	<target name="add_headers" description="Add standard comment header to each java file">
		<java classname="HeaderManager">
			<arg value="${src}"/>
			<arg value="extra/util/header.txt"/>
			<arg value=".java"/>
			<classpath path="extra/util"/>
		</java>
		<java classname="HeaderManager">
			<arg value="dotnet"/>
			<arg value="extra/util/header.txt"/>
			<arg value=".cs"/>
			<classpath path="extra/util"/>
		</java>
	</target>

	<target name="remove_headers" description="Remove standard comment header to each java file">
		<java classname="HeaderManager">
			<arg value="${src}"/>
			<arg value="extra/util/header.txt"/>
			<arg value=".java"/>
			<arg value="remove"/>
			<classpath path="extra/util"/>
		</java>
				<java classname="HeaderManager">
			<arg value="dotnet"/>
			<arg value="extra/util/header.txt"/>
			<arg value=".cs"/>
			<arg value="remove"/>
			<classpath path="extra/util"/>
		</java>
	</target>

	<target name="init">
		<tstamp/>
		<mkdir dir="${classes}"/>
	</target>

</project>

