Code Listings

This appendix lists code written for the project.

Ant Build File

<?xml version="1.0"?>
<!-- Ant build.xml file for CS445 project                          -->
<!--                                                               -->
<!-- Copyright 2003, Mark Craig                                    -->
<!--                                                               -->
<project name="Basic RefEntry Servlet" default="war" basedir=".">
<!-- Generic project properties                                    -->
  <property name="project.fullname" value="Basic RefEntry Servlet"/>
  <property name="project.version"  value="1.0"/>
  <property name="project.name"     value="refentry"/>

<!-- Source locations for the build                                -->
  <property name="bin.dir" value="bin"/>
  <property name="src.dir" value="src"/>

<!-- Destination locations for the build                           -->
  <property name="out.dir"    value="."/>
  <property name="build.dir"  value="${out.dir}/build"/>
  <property name="class.dir"  value="${build.dir}/classes"/>
  <property name="copy.dir"   value="${build.dir}/copy"/>
  <property name="doc.dir"    value="${build.dir}/docs"/>
  <property name="serial.dir" value="${build.dir}/serial"/>
  <property name="dist.dir"   value="${out.dir}/dist"/>

<!-- Initialization target                                         -->
  <target name="init">
    <tstamp/>
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.dir}/build"/> <!-- For build.xml file, etc.-->
    <mkdir dir="${class.dir}"/>
    <mkdir dir="${copy.dir}"/>
    <mkdir dir="${doc.dir}"/>
    <mkdir dir="${doc.dir}/api"/>
    <mkdir dir="${serial.dir}"/>
    <mkdir dir="${dist.dir}"/>
  </target>

<!-- Compile the Java code from ${src.dir} into ${class.dir}       -->
  <target name="compile" depends="init">
    <javac srcdir="${src.dir}" destdir="${class.dir}"/>
  </target>

<!-- Compile the Java format wrapper tool                          -->
  <target name="tool" depends="init,compile">
    <javac srcdir="${out.dir}" includes="format.java">
      <classpath>
        <pathelement path="${class.dir}"/>
      </classpath>
    </javac>
  </target>

<!-- Compile the ServletUnit based tests for the finished servlet  -->
  <target name="servletunit" depends="init">
    <javac srcdir="${out.dir}" includes="Test*.java">
      <classpath>
        <pathelement path="${class.dir}"/>
      </classpath>
    </javac>
  </target>

<!-- Copy the javadoc, sources, and format wrapper                 -->
  <target name="copy" depends="init,servletunit,tool">
    <copy file="${out.dir}/docs/install.txt"  todir="${doc.dir}"/>
    <copy file="${out.dir}/docs/README.txt"   todir="${doc.dir}"/>
    <copy file="${out.dir}/docs/relnotes.txt" todir="${doc.dir}"/>
    <copy file="${out.dir}/docs/project.sgml" todir="${doc.dir}"/>
    <copy file="${out.dir}/build.xml"         todir="${build.dir}/build"/>
    <copy file="${out.dir}/format.class"      todir="${build.dir}/build"/>
    <copy file="${out.dir}/format.java"       todir="${build.dir}/build"/>
    <copy file="${out.dir}/TestClient.class"  todir="${build.dir}/build"/>
    <copy file="${out.dir}/TestClient.java"   todir="${build.dir}/build"/>
    <copy file="${out.dir}/TestGarbageRequests.class"
      todir="${build.dir}/build"/>
    <copy file="${out.dir}/TestGarbageRequests.java"
      todir="${build.dir}/build"/>
    <copy file="${out.dir}/TestOkayRequests.class"
      todir="${build.dir}/build"/>
    <copy file="${out.dir}/TestOkayRequests.java"
      todir="${build.dir}/build"/>
    <copy file="${out.dir}/TestThreads.class" todir="${build.dir}/build"/>
    <copy file="${out.dir}/TestThreads.java"  todir="${build.dir}/build"/>
    <copy todir="${copy.dir}">
      <fileset dir="${src.dir}"/>
    </copy>
  </target>

<!-- Serialize the back end and common words                       -->
  <property name="src"        value="${src.dir}/conf/refentrys.props"/>
  <property name="xsl"        value="${src.dir}/conf/xslt.props"/>
  <property name="cw"         value="${src.dir}/conf/cw.props"/>
  <property name="scw"        value="${serial.dir}/commonWords"/>
  <property name="sbe"        value="${serial.dir}/backend"/>
  <property name="class.base" value="org.mcraig.cs445.refentry"/>
  <target name="serialize" depends="compile">
    <java classname="${class.base}.Build" fork="yes" failonerror="true">
      <arg
        line="-src ${src} -xsl ${xsl} -cw ${cw} -cwOut ${scw} -beOut ${sbe}"
      />
      <classpath>
        <pathelement path="${class.dir}"/>
        <pathelement path="${java.class.path}"/>
      </classpath>
    </java>
  </target>

<!-- Generate the javadoc                                          -->
  <target name="javadoc" depends="init">
    <javadoc
      access="package"
      author="true"
      destdir="${doc.dir}/api"
      sourcepath="${src.dir}"
      use="true"
      windowtitle="Basic RefEntry Servlet API">
      <packageset dir="${src.dir}">
        <include name="org/mcraig/cs445/refentry/**"/>
      </packageset>
      <doctitle><![CDATA[<h1>Basic RefEntry Servlet API</h1>]]></doctitle>
      <bottom><![CDATA[<i>Copyright  2002-2003 Mark Craig</i>]]></bottom>
    </javadoc>
  </target>

<!-- Run the acceptance tests                                      -->
  <target name="accept" depends="compile">
    <java classname="${class.base}.AcceptanceTest"
      failonerror="true" fork="yes">
      <classpath>
        <pathelement location="${class.dir}"/>
        <pathelement path="${java.class.path}"/>
      </classpath>
    </java>
  </target>
  
<!-- Generate the war file                                         -->
  <target name="war" depends="accept,copy,javadoc,serialize">
    <war
      destfile="${dist.dir}/${project.name}.war"
      webxml="${src.dir}/web.xml">
      <webinf     dir="${serial.dir}"/>
      <classes    dir="${class.dir}"/>
      <zipfileset dir="${doc.dir}" prefix="docs"/>
      <zipfileset dir="${copy.dir}" prefix="src"/>
      <zipfileset dir="${build.dir}/build"/>
    </war>
  </target>

<!-- Clean up the build directory                                  -->
  <target name="clean">
    <delete dir="${build.dir}"/>
    <delete><fileset dir="${out.dir}" includes="*.class"/></delete>
  </target>

<!-- Clean everything                                              -->
  <target name="cleandist" depends="clean">
    <delete dir="${dist.dir}"/>
  </target>

</project>