<!-- A "project" describes a set of targets that may be requested
     when Ant is executed.  The "default" attribute defines the
     target which is executed if no specific target is requested,
     and the "basedir" attribute defines the current working directory
     from which Ant executes the requested task.  This is normally
     set to the current working directory.
-->

<project name="EASRoot" default="default" basedir=".">

<!-- $Revision: 1.1 $ / $Date: 2005/12/14 21:19:24 $ -->

<!-- 
This ant build file:
        Generates Java source from .GEN files
        builds from src into build/classes
        
-->

<!-- ===================== Property Definitions =========================== -->
<!--
  Each of the following properties are used in the build script.
  Values for these properties are set by the first place they are
  defined, from the following list:
  * Definitions on the "ant" command line (ant -Dcatalina.home=xyz compile)
  * Definitions from a "build.properties" file in the top level
    source directory
  * Definitions from a "build.properties" file in the developer's
    home directory
  * Default definitions in this build.xml file

  You will note below that property values can be composed based on the
  contents of previously defined properties.  This is a powerful technique
  that helps you minimize the number of changes required when your development
  environment is modified.  Note that property composition is allowed within
  "build.properties" files as well as in the "build.xml" script.
  <property file="build.properties"/>
  <property file="${user.home}/build.properties"/>
-->

<!-- ==================== File and Directory Names ======================== -->
<!--
  These properties generally define file and directory names (or paths) that
  affect where the build process stores its outputs.
-->
  <property name="extensions.name" value="okiReversi" />
  <property name="build.home"  value="${basedir}/build"/>
  <property name="build.class" value="${build.home}/classes" />
  <property name="build.lib"   value="${build.home}/lib" />
  <property name="dist.home"   value="${basedir}/dist"/>
  <property name="dist.src"    value="${dist.home}/src"/>
  <property name="dist.doc"    value="${dist.home}/docs"/>
  <property name="dist.lib"    value="${dist.home}/lib"/>
  <property name="lib.home"    value="../lib"/>
  <property name="extlib.home" value="../extlib"/>
  <property name="jar.name.eas"    value="eas"/>
  <property name="jar.dir"     value="${dist.lib}"/>
  <property name="package.dir" value="${dist.lib}/package"/>
  

<!--  ==================== Compilation Control Options ==================== -->
<!--
  These properties control option settings on the Javac compiler when it
  is invoked using the <javac> task.

  compile.debug        Should compilation include the debug option?
  compile.deprecation  Should compilation include the deprecation option?
  compile.optimize     Should compilation include the optimize option?
-->
  <property name="compile.debug"       value="true"/>
  <property name="compile.deprecation" value="true"/>
  <property name="compile.optimize"    value="false" /> 


<!-- ==================== External Dependencies =========================== -->
<!--
  Use property values to define the locations of external JAR files on which
  your application will depend.  In general, these values will be used for
  two purposes:
  * Inclusion on the classpath that is passed to the Javac compiler
  * Being copied into a target directory during execution of a "deploy" target.
-->
  <property name="junit.jar"   value="${extlib.home}/junit.jar" />


<!-- ==================== Compilation Classpath =========================== -->
<!--
  Rather than relying on the CLASSPATH environment variable, Ant includes
  features that makes it easy to dynamically construct the classpath you
  need for each compilation.
-->
  <path id="compile.classpath">
    <pathelement location="${basedir}" />	
    <pathelement path="${build.class}"/>
    <pathelement location="${lib.home}/${extensions.name}.jar" />	
    <pathelement location="${lib.home}/okiOSID-2.0.jar" />	

    <pathelement path="${extlib.home}/CometOsid2Impl.jar" />
    <pathelement path="${extlib.home}/MITSearchTypes.jar" />
    <pathelement path="${extlib.home}/postgresql.jar" />
    <pathelement path="${extlib.home}/mysql-connector-java-3.0.15-ga-bin.jar" />
    <pathelement path="${java.class.path}" />
  </path>


<!-- ==================== All Target ====================================== -->
<!--
  The "all" target is a shortcut for running the "clean" target and the "codegen" 
  target followed by the "compile" target, to force a complete recompile.
-->
  <target name="all" depends="clean, codegen, compile"
    description="Clean build and dist, then compile"/>


<!-- ==================== Clean Target ==================================== -->
<!--
  The "clean" target deletes any previous "build" and "dist" directory,
  so that you can be ensured the application can be built from scratch.
-->

  <target name="clean" depends="prepare">
    <delete dir="${build.home}" />
    <delete dir="${dist.home}" />
  </target>


<!-- ==================== Prepare Target ================================== -->
<!--
  The "prepare" target is used to create the "build" destination directory,
  and copy the static contents of your web application to it.  If you need
  to copy static files from external dependencies, you can customize the
  contents of this task.

  Normally, this task is executed indirectly when needed.
-->

  <target name="prepare">

    <!-- Determine if Java 1.4 is available on this machine -->
    <condition property="java1.4.present"> 
      <equals arg1="${ant.java.version}" arg2="1.4" /> 
    </condition>
    
    <!-- Set Ant batch file based on test for platform -->
    <condition property="ant.exec" value="ant.bat"> 
      <os family="windows"/>
    </condition>
    <condition property="ant.exec" value="ant"> 
      <not>
        <os family="windows"/>
      </not>
    </condition>
    
    <tstamp />
  </target>


<!-- ==================== junit Target ================================== -->
<!--
  junit initialization task
-->

  <target name="junit">
    <available property="junit.present" classname="junit.framework.TestCase" >
      <classpath>
        <pathelement location="${junit.jar}" />
        <pathelement path="${java.class.path}" />
      </classpath>
    </available>    
  </target>


<!-- ==================== Codegen Target ================================== -->
<!--
  The "codegen" target generates source files by running the Codegenerator on .GEN files
  then moving the emitted source files to directories in preparation for compilation.
-->

  <target name="codegen" depends="prepare">
    <apply executable="${ant.exec}" failonerror="true">
      <arg value="codegen" />
      <arg value="-f" />
      <fileset dir="${basedir}">
        <include name="**/*/build.xml"/>
      </fileset>
    </apply>

  </target>
  

<!-- ==================== Compile Target(s) ================================== -->
<!--
  The "compile" target transforms source files (from your "src" directory)
  into object files in the appropriate location in the build directory.
-->

  <target name="compile" depends="prepare"
    description="Compile Java sources">
    <mkdir dir="${build.class}"/>


    <!--  only one or the other of the compiles will occur,
        depending on the value of java1.4.present -->
    <antcall target="compile1.4" inheritAll="true" />

    <!-- Copy associated resource files -->
  </target>

  <target name="compile1.4"
      description="Compile Java sources for java2 1.4"
      if="java1.4.present">
    <javac srcdir="${dist.src}" destdir="${build.class}"
        debug="${compile.debug}"
        deprecation="${compile.deprecation}"
        optimize="${compile.optimize}"
        target="1.1" 
    >
      <classpath refid="compile.classpath"/>
      <include name="**/**/*.java"/>
    </javac>

  </target>


<!-- ==================== Dist Target ================================== -->
<!-- 
  The "dist" target creates a binary distribution of your application
  in a directory structure ready to be archived in a tar.gz or zip file.
  Note that this target depends on two others:
  * "jarall" so that the entire web application (including external
    dependencies) will have been assembled
  * "javadoc" so that the application Javadocs will have been created
-->

  <target name="dist" depends="javadoc"
    description="Create binary distribution">

    <!-- Copy documentation subdirectory -->
    <copy todir="${dist.home}/docs">
      <fileset dir="doc"/>
    </copy>

    <!-- Copy the contents of the build directory -->
    <mkdir dir="${dist.home}/lib"/>
    <copy todir="${dist.home}/lib">
      <fileset dir="${build.home}/lib"/>
    </copy>
  </target>


<!-- ==================== Javadoc Target ================================== -->
<!--
  The "javadoc" target creates Javadoc documentation for the Java
  classes included in your application.  Normally, this is only required
  when preparing a distribution release, but is available as a separate
  target in case the developer wants to create Javadocs independently.
  
  Adding -breakiterator is recommended for use in Javadoc 1.2 to avoid warnings
  i.e. <javadoc additionalparam="-breakiterator".... 
-->

  <target name="javadoc" depends="compile">
    
    <!--  only one or the other of the compiles will occur,
        depending on the value of java1.4.present -->
    <antcall target="javadoc1.4" inheritAll="true" />
  </target>
  
  <target name="javadoc1.4"
      description="Create Javadoc documentation"
      if="java1.4.present"
  >
    <mkdir dir="${dist.home}/docs/javadoc"/>
    <javadoc additionalparam="-breakiterator" 
      destdir="${dist.home}/docs/javadoc" 
      overview="${basedir}/overview.html" 
      verbose="no"
      packagenames="mit.edu.*" 
      sourcepath="."
      doctitle="Open Service Interface Definition"
      windowtitle="Open Service Interface Definition"
      stylesheetfile="${basedir}/stylesheet.css"
     >
      <sourcepath location="${dist.src}"/>
      <classpath refid="compile.classpath"/>
    </javadoc>
  </target>

<!-- ==================== Jalopy Task Definition ======================== --> 
<!-- 
      In order to avoid possible classpath issues, specify a lookup classpath 
      here rather than copy the Jalopy .jars into the /lib directory of Ant. 
--> 
      <taskdef name="jalopy" 
                       classname="de.hunsicker.jalopy.plugin.ant.AntPlugin"> 
        <classpath> 
              <fileset dir="${extlib.home}/jalopy/lib"> 
                <include name="*.jar" /> 
              </fileset> 
        </classpath> 
      </taskdef> 


<!-- ==================== Format Target ================================= --> 
<!-- 
  Format the Java sources using Jalopy. 
--> 

    <target name="format" depends="compile"> 
      <!-- 
        Invokes Jalopy as follows: 
        - Load your code convention from the given url 
        - The import optimization feature will work (if enabled in the active 
              convention), because a classpath reference is specified 
       
              Don't forget to setup an include pattern as Jalopy truly expects 
              valid Java source files as input! 
                --> 
      <jalopy convention="${basedir}/OkiConventions.xml" 
                      history="file" 
                      loglevel="info" 
                      classpathref="compile.classpath"> 
        <fileset dir="${dist.src}"> 
              <include name="**/*.java" /> 
        </fileset> 
      </jalopy> 
    </target> 
  
<!-- ==================== jar-eas Target ================================== -->
<!-- 
-->
  <target name="jar-nv" depends="compile"
   description="jar the contents of the build directory as eas">
    <mkdir dir="${dist.lib}"/>

    <jar basedir="${build.class}" 
        includes="**" 
        jarfile="${jar.dir}/${jar.name.eas}.jar" 
        manifest="manifest.mf"/> 

</target>

<!-- ==================== DirectorySearch Task ================================ -->
    <target name="eas" depends="compile" description="Runs the Directory Search App" >
        <delete file="eas.log"/>
        <java classname="eas.DirectorySearch" failonerror="true" fork="true">
            <arg value="user.properties"/>
            <arg value="EAS"/>
            <arg value="true"/>  <!-- true = connected -->
            <classpath>
                <path refid="compile.classpath"/>
            </classpath>
        </java>
    </target>

<!-- ==================== DirectorySearch Task Macintosh ================================ -->
<!--
  The "eas" target runs the DirectorySearch app.
-->
    <target name="eas-mac" depends="compile" description="Runs the Directory Search App" >
        <delete file="eas.log"/>
        <java classname="eas.DirectorySearch" failonerror="true" fork="true">
            <jvmarg value="-Dapple.laf.useScreenMenuBar=true"/>
            <jvmarg value="-Dcom.apple.mrj.application.apple.menu.about.name=DirectorySearch"/>
            <arg value="user.properties"/>
            <arg value="EAS"/>
            <arg value="true"/>  <!-- true = connected -->
            <classpath>
                <path refid="compile.classpath"/>
            </classpath>
        </java>
    </target>


<!-- ==================== mac-dist-common Task ============================= -->
    <property name="mac.appdir"    value="${build.home}/eas/eas.app"/>
    <property name="mac.contents" value="${mac.appdir}/Contents"/>
    <property name="mac.bundle_signature" value="EAS"/> <!-- must match MacOS/Info.plist CFBundleSignature -->

    <target name="mac-dist-common" depends="compile">
 
      <jar jarfile="eas.jar"
            basedir="${build.class}" 
            includes="**/*.*"/>
        
      <mkdir dir="${build.home}/eas"/>
      <mkdir dir="${mac.contents}/MacOS"/>
      <mkdir dir="${mac.contents}/Resources/Java/localization"/>
      <mkdir dir="${mac.contents}/Resources/Java/resources"/>
      <mkdir dir="${mac.contents}/Resources/Java/doc"/>
      <mkdir dir="${mac.contents}/Resources/Java/doc/EASHelp_files"/>
      
      <echo file="${mac.contents}/PkgInfo" message="APPL${mac.bundle_signature}"/>
      <copy file="MacOS/JavaApplicationStub" todir="${mac.contents}/MacOS" verbose="true"/>
      <chmod file="${mac.contents}/MacOS/JavaApplicationStub" perm="755" verbose="true"/>
      <copy file="MacOS/eas.icns" todir="${mac.contents}/Resources" verbose="true"/>
    </target>
    
<!-- ==================== mac-dist Task ============================= -->
    <target name="mac-dist" depends="mac-dist-common" 
        description="Creates a Mac OS X distributable Applcation directory.">
        <copy file="MacOS/Info.plist" todir="${mac.contents}" verbose="true"/>
        <copy file="eas.jar" todir="${mac.contents}" verbose="true"/>
        <copy file="${lib.home}/okiOSID-2.0.jar" todir="${mac.contents}" verbose="true"/>
        <copy file="${lib.home}/okiReversi.jar" todir="${mac.contents}" verbose="true"/>
        <copy file="${extlib.home}/CometOsid2Impl.jar" todir="${mac.contents}" verbose="true"/>
        <copy file="${extlib.home}/MITSearchTypes.jar" todir="${mac.contents}" verbose="true"/>
        <copy file="${extlib.home}/postgresql.jar" todir="${mac.contents}" verbose="true"/>
        <copy file="${extlib.home}/mysql-connector-java-3.0.15-ga-bin.jar" todir="${mac.contents}" verbose="true"/>
        
        <copy file="user.properties" todir="${mac.appdir}" verbose="true"/>
        <copy file="osidimpl.properties" todir="${mac.appdir}" verbose="true"/>
        <copy file="eas.properties" todir="${mac.appdir}" verbose="true"/>
        <copy file="cometsql.properties" todir="${mac.appdir}" verbose="true"/>
        <copy file="osid_registry.properties" todir="${mac.appdir}" verbose="true"/>
        
        <copy todir="${mac.contents}/Resources/Java/localization">
            <fileset dir="${basedir}/localization">
                <include name="*.*"/>
            </fileset>    
        </copy>
        <copy todir="${mac.contents}/Resources/Java/resources">
            <fileset dir="${basedir}/resources">
                <include name="*.*"/>
            </fileset>    
        </copy>
        <copy todir="${mac.contents}/Resources/Java/doc">
            <fileset dir="${basedir}/doc">
                <include name="*.*"/>
            </fileset>    
        </copy>
    </target>

</project>
