<!-- 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="OKI" default="jarall" basedir=".">

<!-- 
This ant build file:
        builds from src into build/classes
        makes okiServiceApi.jar from src/org/okip/*/*/api in lib
        makes okiServiceImpl.jar from src/org/okip/*/*/impl in lib
        makes okiServiceApiTest.jar from src/org/okip/*/*/test in lib
        runs ant on contrib/*/impl/build.xml, and copies resulting
                jar files from contrib/*/lib/ to lib
-->

<!-- ===================== 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="api.name"   value="okiServiceApi" />
  <property name="impl.name"   value="okiServiceImpl" />
  <property name="tests.name"   value="okiServiceApiTest" />
  <property name="build.home"    value="${basedir}/build"/>
  <property name="build.dir"  value="${build.home}/classes" />
  <property name="buildlib.dir"  value="${build.home}/lib" />
  <property name="dist.home"    value="${basedir}/dist"/>
  <property name="junit.jar"  value="${user.home}/lib/java/junit.jar" />
  <property name="servlet.jar" value="${user.home}/lib/java/servlet.jar" />


<!--  ==================== 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 the "/WEB-INF/lib" directory during execution
    of the "deploy" target.

  Because we will automatically include all of the Java classes that Tomcat 4
  exposes to web applications, we will not need to explicitly list any of those
  dependencies.  You only need to worry about external dependencies for JAR
  files that you are going to include inside your "/WEB-INF/lib" directory.

-->

<!-- Dummy external dependency -->
<!--
  <property name="foo.jar"
           value="/path/to/foo.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="${servlet.jar}" />
    <pathelement location="${junit.jar}" />
    <pathelement path="" />
    <pathelement path="${java.class.path}" />
  </path>

<!-- ==================== All Target ====================================== -->

<!--

  The "all" target is a shortcut for running the "clean" target followed
  by the "compile" target, to force a complete recompile.

-->

  <target name="all" depends="clean,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,cleancontrib">
    <delete dir="${build.home}" />
    <delete dir="${dist.home}" />
  </target>


  <target name="cleancontrib" depends="prepare">
    <apply executable="${ant.exec}">
      <arg value="clean" />
      <arg value="-f" />
      <fileset dir="${basedir}/contrib">
        <include name="**/impl/build.xml" />
      </fileset>
    </apply>
  </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">
    <available property="jdbc3.present" classname="javax.sql.RowSet"
    />
    <available property="servlet.present" classname="javax.servlet.http.HttpServletRequest" >
      <classpath>
        <pathelement location="${servlet.jar}" />
        <pathelement path="" />
        <pathelement path="${java.class.path}" />
      </classpath>
    </available>    

    <condition property="java1.4.present"> 
      <equals arg1="${ant.java.version}" arg2="1.4" /> 
    </condition>
    <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 initialization task

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

<!-- ==================== Compile Target ================================== -->

<!--

  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="JUNIT,prepare"
      description="Compile Java sources">
    <mkdir dir="${build.dir}"/>

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

    <!-- Copy associated resource files -->

    <copy todir="${build.dir}">
      <fileset dir="${basedir}/src">
        <include name="**/*.properties"/>
      </fileset>
    </copy>
  </target>

  <target name="compile1.3"
      description="Compile Java sources for java2 1.3"
      unless="java1.4.present">
    <javac   srcdir="${basedir}/src" destdir="${build.dir}"
              debug="${compile.debug}"
        deprecation="${compile.deprecation}"
           optimize="${compile.optimize}">
      <classpath refid="compile.classpath"/>
      <include name="**/api/*.java"/>
      <include name="**/impl/**/*.java"/>
      <include name="**/util/**/**/*.java"/>
      <exclude name="**/okifunc/**/*.java"/>
      <exclude name="**/dbc/impl/*.java" unless="jdbc3.present"/>
      <exclude name="**/dbc/test/*.java" unless="jdbc3.present"/>
      <exclude name="org/okip/util/agents/api/ServletAgent.java"
                            unless="servlet.present" />
      <include name="**/test/*.java" if="junit.present" />
    </javac>
  </target>

  <target name="compile1.4"
      description="Compile Java sources for java2 1.4"
      if="java1.4.present">
    <javac srcdir="${basedir}/src" destdir="${build.dir}"
           debug="${compile.debug}"
        deprecation="${compile.deprecation}"
           optimize="${compile.optimize}"
             source="1.4">
      <classpath refid="compile.classpath"/>
      <include name="**/api/*.java"/>
      <include name="**/impl/**/*.java"/>
      <include name="**/util/**/**/*.java"/>
      <exclude name="**/okifunc/**/*.java"/>
      <exclude name="**/dbc/impl/*.java" unless="jdbc3.present"/>
      <exclude name="org/okip/util/agents/api/ServletAgent.java"
                                    unless="servlet.present" />
      <include name="**/test/*.java" if="junit.present" />
    </javac>
  </target>

  <target name="compilecontrib" depends="jar">
    <apply executable="${ant.exec}">
      <arg value="-f" />
      <fileset dir="${basedir}/contrib">
        <include name="**/impl/build.xml" />
      </fileset>
    </apply>
  </target>

  <target name="jarall" depends="compilecontrib">
    <copy todir="${buildlib.dir}" flatten="yes">
      <fileset dir="${basedir}/contrib">
        <include name="**/impl/build/lib/*.jar" />
      </fileset>
    </copy>
  </target>

  <target name="jar" depends="compile">
    <mkdir dir="${buildlib.dir}"/>
    <jar jarfile="${buildlib.dir}/${api.name}.jar"
               basedir="${build.dir}" includes="org/okip/**/api/**, org/okip/**/util/**"/>
    <jar jarfile="${buildlib.dir}/${impl.name}.jar"
           basedir="${build.dir}" includes="org/okip/**/impl/**"/>
    <jar jarfile="${buildlib.dir}/${tests.name}.jar">
    <fileset dir="${build.dir}">
    <include name="org/okip/**/test/**"  if="junit.present" />
    </fileset>
  </jar>
</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="jarall,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.

-->

  <target name="javadoc" depends="compile"
      description="Create Javadoc documentation">

    <mkdir dir="${dist.home}/docs/javadoc"/>
    <javadoc sourcepath="src"
                destdir="${dist.home}/docs/javadoc"
           packagenames="org.*">
      <classpath refid="compile.classpath"/>
    </javadoc>
  </target>

<!-- ==================== runtests Target ================================= -->

<!--

  The "runtests" target runs any junit tests available.

-->
  <target name="runtests" depends="jar" if="junit.present">
    <java fork="yes" classname="junit.swingui.TestRunner"
            taskname="junit" failonerror="true">
      <classpath>
        <pathelement location="${servlet.jar}" />
        <pathelement location="${junit.jar}" />
        <pathelement path="" />
        <pathelement path="${buildlib.dir}/${api.name}.jar" />
        <pathelement path="${buildlib.dir}/${impl.name}.jar" />
        <pathelement path="${buildlib.dir}/${tests.name}.jar" />
        <pathelement path="${java.class.path}" />
      </classpath>
    </java>
  </target>
</project>
