<project name="gizmoball" basedir="." default="usage">
	
	<!-- set the classpath for the project        -->
	<!-- this includes your generated class files -->
	<!-- and every jar in the 6.170 lib directory -->
	<path id="classpath.path">
		<pathelement location="obj" />
		<fileset dir="lib">
			<include name="*.jar" />
		</fileset>
	</path>

	<!-- for shell scripts that need to know the classpath -->
	<target name="classpath" depends="init">
		<echo>@CLASSPATH@${classpath}</echo>
	</target>

	<!-- define some variables for the script -->
	<target name="init">
	  <echo>initialize variables for this build file</echo>
		<property name="src" value="${basedir}/src" />
		<!-- Don't pollute the source tree! -->
<!--		<property name="classes" value="${src}" /> -->
		<property name="classes" value="${basedir}/obj" />
		<property name="lib" value="${basedir}/lib" />
		<property name="doc" value="${basedir}/doc" />
		<property name="api" value="${doc}/api" />
		<property name="java.api"
      value="http://web.mit.edu/6.170/www/javadoc/j2sdk1.4.1-docs-api" />
		<property name="build.compiler" value="jikes" />
		<property name="build.compiler.emacs" value="true" />
		<property name="classpath" refid="classpath.path" />
	</target>

	<!-- delete generated files -->
	<target name="clean" depends="init">
	  <echo>clean generated files</echo>
		<delete>
		  <fileset dir="${classes}" includes="**/*.class" />
		</delete>
		<delete dir="${api}" />
	</target>

	<!-- compile the source code -->
	<target name="compile" depends="init">
	  <echo>compile source code</echo>
		<mkdir dir="${classes}" />
		<javac srcdir="${src}"
		       destdir="${classes}"
		       excludes="CVS,*/package.html"
		       debug="true">
			<classpath refid ="classpath.path"/>
		</javac>
          <echo>copy XML schema</echo>
		<copy file="${src}/gizmoball/xml/gb_level.xsd"
		      todir="${classes}" />
	</target>

	<!-- run the javadoc tool on the source code -->
	<target name="javadoc" depends="init">
	  <echo>generate javadoc</echo>
		<mkdir dir="${api}" />
		<javadoc sourcepath="${src}"
		         packagenames="${ant.project.name}.*"
		         destdir="${api}"
		         windowtitle="Gizmoball"
		         Package="true"
			 additionalparam="-tagletpath ${lib}/javadoc6170.jar
                              -taglet javadoc6170.RequiresTaglet
                              -taglet javadoc6170.EffectsTaglet
                              -taglet javadoc6170.ModifiesTaglet
                              -taglet javadoc6170.ReturnsTaglet
                              -taglet javadoc6170.SpecfieldTaglet
                              -taglet javadoc6170.DerivedfieldTaglet
                              -quiet"
			 stylesheetfile="${doc}/6170-javadoc.css">
			<classpath refid="classpath.path" />
			<link href="${java.api}" />
		</javadoc>
	</target>
	
	<!-- export the project as a jar -->
	<target name="build" depends="compile">
	  <echo>package the .class files as a .jar file</echo>
		<jar destfile="${basedir}/${ant.project.name}.jar" update="true"> 
			<fileset dir="${classes}" />
		</jar>
	</target>

  <!-- use JUnit to run tests -->
   <target name="test" depends="compile">
      <junit printsummary="yes">
        <classpath refid="classpath.path" />
        <formatter type="brief" />
        <batchtest>
           <fileset dir="${src}">
              <include name="**/*Test.java" />
           </fileset>
        </batchtest>
      </junit>
   </target>


	<!-- a user of your script can see the available targets -->
	<target name="usage" depends="init">
	  <echo>list the available tasks in this ant script</echo>
		<echo>
clean:   remove the generated class files and javadoc
compile: compile the code to class files
test:    runs JUnit test suite
build:   exports the project as a jar
javadoc: generate javadoc for the source code
usage:   display this message
		</echo>
	</target>

</project>

