<!--
BEGIN COPYRIGHT BLOCK
Copyright (C) 2005 Red Hat, Inc.
All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
END COPYRIGHT BLOCK
-->

<project name="admservconsole" default="dist" basedir=".">
  <!-- Load properties -->
  <property file="build.properties"/>

  <!-- Paths -->
  <property name="built.dir"       value="${admservconsole.root}/built"/>
  <property name="package.dir"     value="${built.dir}/package"/>
  <property name="built.classdir"  value="${built.dir}/classes"/>
  <property name="javadoc.dir"     value="${built.dir}/doc"/>
  <property name="imports.dir"     value="${admservconsole.root}/imports"/>
  <property name="java.src.dir"    value="src"/>

  <!-- Component Paths - Override if needed -->
  <property name="ldapjdk.location" value="/usr/share/java"/>

  <!-- Prepare -->
  <target name="prepare_build">
    <!-- Create directories -->
    <mkdir dir="${built.classdir}"/>
  </target>

  <target name="prepare_dist">
    <!-- Create directories -->
    <mkdir dir="${package.dir}"/>
  </target>

  <target name="prepare_doc">
    <!-- Create directories -->
    <mkdir dir="${javadoc.dir}"/>
  </target>

  <!-- Imports -->
  <target name="import_console" depends="prepare_build" unless="console.location">
    <!-- Load imports file -->
    <input
      message="An imports file must be specified.  Enter the imports file that you want to use:"
      addproperty="imports.file"
      defaultvalue="imports"
    />
    <fail message="Imports file does not exist. (${imports.file})">
      <condition>
        <not>
          <available file="${imports.file}"/>
        </not>
      </condition>
    </fail>
    <property file="${imports.file}"/>
    <!-- Fetch console -->
    <mkdir dir="${imports.dir}/console"/>
    <get src="${console.import.location}/${console.import}"
         dest="${imports.dir}/console/${console.import}"/>
    <!-- Extract console -->
    <untar src="${imports.dir}/console/${console.import}"
           dest="${imports.dir}/console"
           compression="gzip"/>
    <move todir="${imports.dir}/console/unzipped">
      <fileset dir="${imports.dir}/console/${brand}-console-${admservconsole.version}"/>
    </move>
    <!-- Set console.location -->
    <property name="console.location" value="${imports.dir}/console/unzipped"/>
  </target>

  <!-- Build -->
  <target name="build" depends="import_console">
    <!-- Construct classpath -->
    <path id="admservconsole.classpath">
      <fileset dir="${console.location}">
        <include name="**/idm-console-base-*.jar"/>
        <include name="**/idm-console-mcc-*.jar"/>
        <include name="**/idm-console-nmclf-*.jar"/>
      </fileset>
      <fileset dir="${ldapjdk.location}">
        <include name="**/ldapjdk.jar"/> 
      </fileset>
      <pathelement path="${built.classdir}"/>
    </path>
    <!-- compile regular java code -->
    <javac   srcdir="${java.src.dir}"
             destdir="${built.classdir}"
             debug="${compile.debug}" deprecation="${compile.deprecation}"
             optimize="${compile.optimize}"
             verbose="no">
             <classpath refid="admservconsole.classpath"/>
             <exclude name="**/CVS/**"/>
    </javac>
  </target>

  <!-- Dist -->
  <target name="dist" depends="build,prepare_dist">
    <!-- Create jar files -->
    <jar jarfile="${package.dir}/${admservconsole.name}.jar" >
      <fileset dir="${built.classdir}">
        <include name="com/**/*.class" />
      </fileset>
    </jar>
    <jar jarfile="${package.dir}/${admservconsole.name}_${lang}.jar" >
      <fileset dir="${java.src.dir}">
         <include name="com/netscape/management/admserv/**/*.properties" />
         <include name="com/netscape/management/admserv/**/*.gif" />
         <include name="com/netscape/management/admserv/**/*.jpg" />
      </fileset>
    </jar>
  </target>

  <!-- Javadoc -->
  <target name="javadoc" depends="prepare_doc">
    <javadoc 
      packagenames="com.netscape.management.admserv.*"
      sourcepath="src"
      destdir="${javadoc.dir}"
      author="true"
      version="true"
      use="true"
      windowtitle="Admin Server Console API"
      doctitle="Admin Server Console API" />
  </target>

  <!-- Cleanup -->
  <target name="clean_all" depends="clean,clean_imports"/>

  <target name="clean">
    <delete dir="${built.dir}"/>
  </target>

  <target name="clean_imports">
    <delete dir="${imports.dir}"/>
  </target>

</project>
