<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" />
                <property name="unjartemp" value="${basedir}/temporary-unjar"/>
	</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}" />
          <echo>copy frobber images</echo>
		<copy todir ="${classes}">
			<fileset file ="${src}/gizmoball/ui/frobber/*.PNG"/>
		</copy>
          <echo>copy ui icons</echo>
  		<copy todir ="${classes}">
			<fileset file ="${src}/gizmoball/ui/icons/*.PNG"/>
		</copy>

	</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="${lib}/${ant.project.name}.jar" update="true"> 
			<fileset dir="${classes}" />
		</jar>
	</target>

       <!-- Unjar all the jars from the lib subdirectory except the jars that 
            contain the files for this project -->
       <target name="unjar" depends="build">
           <echo>extracts content from jar files in lib directory</echo>
           <mkdir dir="${unjartemp}"/>
           <unjar dest="${unjartemp}">
               <fileset dir="${lib}"
                        excludes="**/*${ant.project.name}*,**/javadoc*"/>
           </unjar>
       </target>

       <!--  Now create one big executable jar and remove the temporary 
             unjar directory -->
       <target name="execjar" depends="unjar">
           <echo>package the .class files as an executable .jar file</echo>
           <jar destfile="${ant.project.name}.jar" compress="true">
                <fileset dir="${classes}"/>
                <fileset dir="${unjartemp}"/>
                <manifest>
                   <attribute name="Built-By" value="${user.name}"/>
                   <attribute name="Main-Class" value="gizmoball.Gizmoball"/>
                   <section name="Gizmoball">
                       <attribute name="Sealed" value="false"/>
                   </section>
               </manifest>
           </jar>
           <delete dir="${unjartemp}"/>
       </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>

