<!--
   Copyright 2003-2004 The Apache Software Foundation

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<project name="Clazz" default="jar" basedir=".">


<!--
        "Clazz" component of the Apache Commons Subproject
        $Id$
-->


<!-- ========== Initialize Properties ===================================== -->

  <property file="${user.home}/build.properties"/>   <!-- User local        -->
  <property file="build.properties"/>                <!-- Component local   -->
  <property file="../build.properties"/>             <!-- Commons local     -->

<!-- ========== Component Declarations ==================================== -->

  <!-- The name of this component -->
  <property name="component.name"          value="clazz"/>

  <!-- The title of this component -->
  <property name="component.title"         value="New generation of Introspection"/>

  <!-- The primary package name of this component -->
  <property name="component.package"       value="org.apache.commons.clazz"/>

  <!-- The current version number of this component -->
  <property name="component.version"       value="0.1"/>

  <!-- The jar name of this component -->
  <property name="jar.name"
           value="commons-${component.name}.jar"/>

  <!-- The base directory for compilation targets -->
  <property name="build.home"              value="target"/>

  <!-- The base directory for component configuration files -->
  <property name="conf.home"               value="src/conf"/>

  <!-- The base directory for distribution targets -->
  <property name="dist.home"               value="dist"/>

  <!-- The base directory for component sources -->
  <property name="source.home"             value="src/java"/>

  <!-- The base directory for unit test sources -->
  <property name="test.home"               value="src/test"/>

  <!-- Anakia props -->
  <property name="docs.src" value="./xdocs"/>
  <property name="docs.dest" value="${dist.home}/docs"/>


<!-- ========== Compiler Defaults ========================================= -->


  <!-- Should Java compilations set the 'debug' compiler option? -->
  <property name="compile.debug"           value="true"/>

  <!-- Should Java compilations set the 'deprecation' compiler option? -->
  <property name="compile.deprecation"     value="true"/>

  <!-- Should Java compilations set the 'optimize' compiler option? -->
  <property name="compile.optimize"        value="true"/>

  <!-- Construct compile classpath -->
  <path id="compile.classpath">
    <pathelement location="${build.home}/classes"/>
    <pathelement location="${junit.jar}"/>
    <pathelement location="${commons-collections.jar}"/>
    <pathelement location="${commons-logging.jar}"/>
  </path>


<!-- ========== Test Execution Defaults =================================== -->


  <!-- Construct unit test classpath -->
  <path id="test.classpath">
    <pathelement location="${build.home}/classes"/>
    <pathelement location="${build.home}/tests"/>
    <pathelement location="${junit.jar}"/>
    <pathelement location="${commons-collections.jar}"/>
    <pathelement location="${commons-logging.jar}"/>
  </path>

  <!-- Should all tests fail if one does? -->
  <property name="test.failonerror"        value="true"/>

  <!-- The test runner to execute -->
  <property name="test.runner"             value="junit.textui.TestRunner"/>


<!-- ========== Executable Targets ======================================== -->

  <target name="check_available">
    <available 
      classname="junit.framework.Test"
      property="junit.present"
      classpathref="compile.classpath"
    />

  </target>

  <target name="init"
    description="Initialize and evaluate conditionals"
    depends="check_available">
    <echo message="-------- ${component.name} ${component.version} --------"/>
    <filter  token="name"                  value="${component.name}"/>
    <filter  token="package"               value="${component.package}"/>
    <filter  token="version"               value="${component.version}"/>

    <echo message="junit.jar = ${junit.jar}"/>
    <echo message="commons-collections.jar = ${commons-collections.jar}"/>
    <echo message="commons-logging.jar = ${commons-logging.jar}"/>
  </target>

  <target name="check.junit" unless="junit.present">
    <antcall target="property-warning">
      <param name="name" value="junit.jar"/>
      <param name="value" value="${junit.jar}"/>
    </antcall>
  </target>

  <target name="property-warning">
    <echo>
      +----------------------------------------------------------------+
      + F A I L E D  R E Q U I R E M E N T                             |
      +----------------------------------------------------------------+
      | You must define the following property in order                |
      | to build ${component.name}:
      |                                                                |
      | ${name} = ${value}
      |                                                                |
      | You can set this property in the provided build.properties     |
      | file, or you may set this property in your                     |
      | ${user.home}/build.properties file.                            
      +----------------------------------------------------------------+
    </echo>
    <fail message="Failed Requirement"/>
  </target>

  <target name="prepare" depends="init,check.junit"
   description="Prepare build directory">
    <mkdir dir="${build.home}"/>
    <mkdir dir="${build.home}/classes"/>
    <mkdir dir="${build.home}/conf"/>
    <mkdir dir="${build.home}/tests"/>
  </target>

  <target name="static" depends="prepare"
   description="Copy static files to build directory">
    <tstamp/>
    <copy  todir="${build.home}/conf" filtering="on">
      <fileset dir="${conf.home}" includes="*.MF"/>
    </copy>
  </target>


  <target name="compile" depends="static"
   description="Compile shareable components">
    <javac  srcdir="${source.home}"
           destdir="${build.home}/classes"
             debug="${compile.debug}"
       deprecation="${compile.deprecation}"
          optimize="${compile.optimize}">
      <classpath refid="compile.classpath"/>
    </javac>
    <copy    todir="${build.home}/classes" filtering="on">
      <fileset dir="${source.home}" excludes="**/*.java"/>
    </copy>
  </target>


  <target name="compile.tests" depends="compile"
   description="Compile unit test cases">
    <javac  srcdir="${test.home}"
           destdir="${build.home}/tests"
             debug="${compile.debug}"
       deprecation="${compile.deprecation}"
          optimize="${compile.optimize}">
      <classpath refid="test.classpath"/>
    </javac>
    <copy    todir="${build.home}/tests" filtering="on">
      <fileset dir="${test.home}" excludes="**/*.java"/>
    </copy>
  </target>


  <target name="clean"
   description="Clean build and distribution directories">
    <delete    dir="${build.home}"/>
    <delete    dir="${dist.home}"/>
  </target>


  <target name="all" depends="clean,compile"
   description="Clean and compile all components"/>


  <target name="javadoc" depends="compile"
   description="Create component Javadoc documentation">
    <mkdir      dir="${dist.home}"/>
    <mkdir      dir="${dist.home}/docs"/>
    <mkdir      dir="${dist.home}/docs/apidocs"/>
    <javadoc sourcepath="${source.home}"
           classpathref="compile.classpath"
                destdir="${dist.home}/docs/apidocs"
           packagenames="org.apache.commons.*"
                 author="true"
                private="false"
                version="true"
               doctitle="&lt;h1&gt;${component.title}&lt;/h1&gt;"
            windowtitle="${component.title} (Version ${component.version})"
                 bottom="Copyright (c) 2001 - Apache Software Foundation"/>
  </target>

  <!-- ================================================================== -->
  <!-- J A R                                                              -->
  <!-- ================================================================== -->
  <target name="jar" depends="compile" description="Build jar">
    <mkdir      dir="${dist.home}"/>
    <copy      file="LICENSE.txt"
             tofile="${build.home}/classes/META-INF/LICENSE.txt"/>
    <copy      file="NOTICE.txt"
             tofile="${build.home}/classes/META-INF/NOTICE.txt"/>
    <jar    jarfile="${dist.home}/${jar.name}"
            basedir="${build.home}/classes"
           manifest="${build.home}/conf/MANIFEST.MF"/>
  </target>
  
  <!-- ================================================================== -->
  <!-- I N S T A L L  J A R                                               -->
  <!-- ================================================================== -->

  <target name="install-jar" depends="jar" 
          description="==> Installs .jar file in ${lib.repo}">
    <copy todir="${lib.repo}" filtering="no">
      <fileset dir="${dist.home}">
        <include name="${jar.name}"/>
      </fileset>
    </copy>
  </target>

  <!-- ================================================================== -->
  <!-- D I S T                                                            -->
  <!-- ================================================================== -->

  <target name="dist" depends="compile,jar,xdoc,javadoc"
   description="Create binary distribution">
    <mkdir      dir="${dist.home}"/>
    <copy      file="LICENSE.txt"
              todir="${dist.home}"/>
    <copy      file="NOTICE.txt"
              todir="${dist.home}"/>
  </target>

<!-- ========== Unit Test Targets ========================================= -->

  <target name="test"  depends="compile.tests,
                                test.clazz"
   description="Run all unit test cases">
  </target>

  <target name="test.clazz">
    <echo message="Running Clazz tests ..."/>
    <java classname="${test.runner}" fork="yes"
        failonerror="${test.failonerror}">
      <arg value="org.apache.commons.clazz.ClazzTest"/>
      <classpath refid="test.classpath"/>
    </java>
  </target>
</project>
