<project name="scripts" default="release" basedir=".">
    <description>
Simple build file.
You will need ant.jar and junit.jar in your classpath in order to use this file.
	
Target directory structure:
* bin/ - common binaries, scripts (place on path)
* src/ - source goes in under this tree in a heirarchy which matches the package names
* doc/ - Hand crafted documentation
* doc/javadoc/ - generated javadoc code (which your docs can link to)
* lib/ - imported Java libraries go in to this directory
* target/classes/ - This is the tree for building; Ant creates it and can empty it in the 'clean' project.
* target/tests/ - junit test cases are compiled in separate subdirectory
* target/logs - logs for cruisecontrol go here
* target/resutls - xml test results for cruisecontrol go here
* target/dist/ - Distribution outputs go in here; the directory is created in Ant and clean empties it out
* target/dist/lib/ - required runtime jars go here, including generated timestamped jar	
* dist/ - zipped distribution archives go here
* build.xml - this file
    </description>
    
	<!-- GLOBAL PROPERTIES -->
	<property name="build.compiler.emacs" value="true"/>
	<property name="svn.repository" value="http://svn.geotools.org/geotools/trunk/" /> 
    <property name="svn.package"    value="scripts" /> 

	<!-- project directories -->
	<property name="src"        location="src"/>
	<property name="target"  location="target"/>
	<property name="build"      location="${target}/classes"/>
	<property name="testbuild"  location="${target}/junit"/>  
	<property name="distbuild"  location="${target}/dist"/>  	
	<property name="dist"       location="dist"/>
	<property name="lib"        location="lib"/>
	<property name="test"       location="test"/>
	<property name="doc"        location="doc"/>
	<property name="javadoc"    location="${doc}/javadoc"/>
	<property name="bin"        location="bin"/>
	<property name="results"    location="${target}/results"/>	
	<property name="logs"       location="${target}/logs"/>
	
	<!-- paths -->
	<path id="buildpath" >
		<fileset dir="lib">
			<include name="*.jar"/>
		</fileset>
	</path>	
	<path id="distpath" >
		<fileset dir="lib">
        	<include name="*.jar"/>
	        <exclude name="junit*.jar"/>
	        <exclude name="ant*.jar"/>        
		</fileset>
	</path>
	<path id="testpath" >	
		<pathelement location="${build}" />
		<pathelement location="${testbuild}" />
		<fileset dir="lib">
			<include name="*.jar"/>
		</fileset>                
	</path> 
	  
	<!-- TARGETS -->
	<target name="init">
		<tstamp/>
		<!-- Create the build directory structure used by build -->
		<mkdir dir="${target}"/>
		<mkdir dir="${build}"/>
		<mkdir dir="${distbuild}"/>
		<mkdir dir="${logs}"/>		
		<mkdir dir="${dist}"/>		
	</target>

	<target name="clean"
			description="clean out the output directories" >
		<!-- Delete the ${target} and ${dist} directory trees -->
		<delete dir="${target}"/>
		<delete dir="${dist}"/>
		<delete dir="${javadoc}"/>
		<delete file="${release}.zip"/>
	</target>

	<target name="compile" depends="init"
			description="compile application without cleaning">
	    <javac srcdir="${src}"
	           destdir="${build}"
		   	   classpathref="buildpath"
	   		   deprecation="on"
	           debug="on"
	           target="1.4"
	           source="1.4"
	           nowarn="off"/>
		<copy todir="${build}">
			<fileset dir="${src}">
				<!-- don't copy java or javadoc support files -->
				<exclude name="**/doc-files/*"/>
				<exclude name="**/package.html"/>
				<exclude name="**/*.java"/>							
			</fileset>
		</copy>	           
	</target>	
	<target name="docs" depends="compile"
	        description="generate javadocs" >
		<mkdir dir="${javadoc}"/>
		<javadoc destdir="${javadoc}"
		        author="true"
			classpathref="buildpath"
			version="true"
			source="1.4"
			use="true"
			windowtitle="${ant.project.name} API">
			<fileset dir="src" defaultexcludes="yes"/>
			<doctitle><![CDATA[<h1>${ant.project.name} API</h1>]]></doctitle>
			<bottom><![CDATA[<i>Copyright &#169; 2003 Refractions Research. All Rights Reserved.</i>]]></bottom>
			<tag name="todo" scope="all" description="To do:" />
			<tag name="hack" scope="all" description="Hack:" />
			<tag name="bug" scope="all"  description="Bug:" />
			<link href="http://java.sun.com/products/jdk/1.2/docs/api/"/>
           <!--- CWB project links
	                <link href="http://www/build/javadoc/jump/"/>
			<link href="http://www/build/javadoc/jcs/"/>
			<link href="http://www/build/javadoc/jts/"/>
	   -->
	        </javadoc>
       </target> 

	<target name="test.init">
		<mkdir dir="${testbuild}"/>		
		<mkdir dir="${results}"/>				
	</target>

	<target name="test.compile" depends="compile, test.init">        
	    <javac srcdir="${test}"
	           destdir="${testbuild}"
		   	   classpathref="testpath"
	   		   deprecation="on"
	           debug="on"
	           nowarn="off">
	    </javac>
	</target>
	
	<target name="test" depends="test.compile"
			description="run the junit tests">			
	    <junit 	printsummary="no"
	    		showoutput="no"
	    		filtertrace="on"
				haltonfailure="yes">				
			<classpath>
				<pathelement location="${build}" />
				<pathelement location="${testbuild}" />
				<fileset dir="lib">
					<include name="*.jar"/>
				</fileset> 			    
			</classpath>
					
			<formatter type="brief" usefile="false"/>
			<formatter type="xml"/>			
			<batchtest fork="yes" todir="${results}">
				<fileset dir="${test}">
				  <include name="**/*Test*.java"/>
				  <exclude name="**/AllTests.java"/>
				</fileset>
			</batchtest>
		</junit>		
	</target>

	<target name="release-init">
		<mkdir dir="${dist}"/>
		<mkdir dir="${distbuild}"/>		
		<mkdir dir="${distbuild}/lib"/>
	</target>
	
	<target name="jar" depends="compile,test,release-init">
		<jar jarfile="${distbuild}/lib/${ant.project.name}.jar"
			basedir="${build}"/>
	    <jar jarfile="${distbuild}/lib/src-${DSTAMP}.jar"
			basedir="${src}"/>
	</target>
    
    <!-- Can probably optimize most of the release directory away -->
	<target name="release" depends="release-init, jar, docs"
    	    description="Generate the distribution" >    
    	<copy todir="${distbuild}/doc">
     		<fileset dir="${doc}"/>
	    </copy>
    	<copy todir="${distbuild}/bin">
	    	<fileset dir="${bin}"/>
	    </copy>
	    <copy todir="${distbuild}/lib">
	    	<fileset dir="${lib}">
	    		<exclude name="ant*.jar"/>
	    		<exclude name="junit*.jar"/>    		
	    	</fileset>
	    </copy>
	    <zip destfile="${dist}/${ant.project.name}-${DSTAMP}.zip" basedir="${distbuild}" />
	</target>

	<target name="all" depends="clean,init,compile,test,jar"
		    description="Build application" />
		      	  
</project>
