<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.

This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation.  Sun designates this
particular file as subject to the "Classpath" exception as provided
by Sun in the LICENSE file that accompanied this code.

This code 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
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).

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

Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
CA 95054 USA or visit www.sun.com if you need additional information or
have any questions.
 -->
<project name="JavaHelp" default="release" basedir=".">
    <description>Builds, tests, and runs the project JavaHelp.</description>
    <import file="nbproject/build-impl.xml"/>
    
    <property name="dist.dir" value="dist/lib"/> <!-- XXX -->
    
    <property name="servlet-jar" value="${basedir}/lib/servlet-api.jar"/>
    <available property="servlet-jar-present" file="${servlet-jar}"/>

    <property name="jsp-jar" value="${basedir}/lib/jsp-api.jar"/>
    <available property="jsp-jar-present" file="${jsp-jar}"/>
    
    <property name="jdic-jar" value="${basedir}/lib/jdic.jar"/>
    <available property="jdic-jar-present" file="${jdic-jar}"/>

    <property name="tomcat-zip" value="${java.io.tmpdir}/apache-tomcat-5.5.20.zip"/>
    <available property="tomcat-zip-present" file="${tomcat-zip}"/>

    <property name="jdic-zip" value="${java.io.tmpdir}/jdic-0.8.4.1-bin-windows.zip"/>
    <available property="jdic-zip-present" file="${jdic-zip}"/>
    
    <target name="-pre-init" 
        depends="unpack-servlet-jar,unpack-jsp-jar,unpack-jdic-jar"/>
        
    <target name="release" description="Build the full JavaHelp JARs" 
            depends="build-jsearch-jars,copy-jsearch-jars,create-javahelp-jars"/>
            
            
    <target name="release-source" description="Build the source zip file">
        <property name="version" value="2.0.05"/>
        <mkdir dir="dist"/>
        <zip destfile="dist/javahelp2-src-${version}.zip" filesonly="true">
            <zipfileset dir=".." prefix="javahelp2-${version}">
                <and>
                    <filename name="**/*"/>
                    <none>
                        <filename name="**/dist/**/*"/>
                        <filename name="**/build/**/*"/>
                        <filename name="www/**/*"/>
                        <filename name="**/*.jar"/>
                        <filename name="**/*.zip"/>
                    </none>
                    <or>
                        <contains text="GNU General Public License"/>
                        <filename name="**/nbproject/*.xml"/>
                        <filename name="**/nbproject/*.properties"/>
                        <filename name="**/manifest.mf"/>
                    </or>
                </and>
            </zipfileset>
        </zip>
    </target>
            
    <target name="unpack-servlet-jar" unless="servlet-jar-present" depends="download-tomcat-zip">
        <echo message="Unpacking ${tomcat-zip}"/>
        <unzip src="${tomcat-zip}" dest="${java.io.tmpdir}/"/>
        <copy failonerror="true" file="${java.io.tmpdir}/apache-tomcat-5.5.20/common/lib/servlet-api.jar"
            tofile="${servlet-jar}"/>
    </target>
    
    <target name="unpack-jsp-jar" depends="download-tomcat-zip" unless="jsp-jar-present">
        <echo message="Copying ${jsp-jar}"/>
        <copy failonerror="true" file="${java.io.tmpdir}/apache-tomcat-5.5.20/common/lib/jsp-api.jar"
            tofile="${jsp-jar}"/>
    </target>
    
    <target name="download-tomcat-zip" unless="tomcat-zip-present">
        <echo message="Downloading Apache Tomcat for servlet-api.jar and jsp-api.jar"/>
        <get src="http://archive.apache.org/dist/tomcat/tomcat-5/v5.5.20/bin/apache-tomcat-5.5.20.zip"
            dest="${tomcat-zip}"/>
    </target>
    
    <target name="unpack-jdic-jar" description="Download JDIC Jar" unless="jdic-jar-present" 
            depends="download-jdic-zip">                
        <unzip src="${jdic-zip}" dest="${java.io.tmpdir}"/>
        <copy failonerror="true" file="${java.io.tmpdir}/jdic-0.8.4.1-bin-windows/jdic.jar"
            tofile="${jdic-jar}"/>
    </target>
    
    <target name="download-jdic-zip" unless="jdic-zip-present">
        <echo>
Downloading JDIC.  If you get an error like 'Server redirected too many times' download it manually from
https://jdic.dev.java.net/servlets/ProjectDocumentView?documentID=5715&amp;showInfo=true 
Then copy the zip file to ${jdic-zip} and re-build
        </echo>
        <get src="https://jdic.dev.java.net/files/documents/880/5715/jdic-0.8.4.1-bin-windows.zip"
            dest="${jdic-zip}"/>
    </target>

    <target name="build-jsearch-jars">
        <ant inheritall="false" inheritrefs="false" 
            antfile="${basedir}/../JSearchIndexer_nbproject/build.xml" target="jar"/>
        <ant inheritall="false" inheritrefs="false" 
            antfile="${basedir}/../JSearchClient_nbproject/build.xml" target="jar"/>
        <delete file="../JSearchIndexer_nbproject/BUILD_LOCK"/>
    </target>
    
    <target name="copy-jsearch-jars">
        <property name="jsearch-client-jar" value="../JSearchClient_nbproject/dist/jsearch-client.jar"/>
        <available property="jsearch-client-jar-present" file="${jsearch-client-jar}"/>

        <property name="jsearch-indexer-jar" value="../JSearchIndexer_nbproject/dist/jsearch-indexer.jar"/>
        <available property="jsearch-indexer-jar-present" file="${jsearch-client-jar}"/>

        <property name="jsearch-jar" value="../JSearchIndexer_nbproject/dist/jsearch.jar"/>
        <available property="jsearch-jar-present" file="${jsearch-jar}"/>

        <property name="jsearch-misc-jar" value="../JSearchIndexer_nbproject/dist/jsearch-misc.jar"/>
        <available property="jsearch-misc-jar-present" file="${jsearch-misc-jar}"/>
        
        <fail unless="jsearch-client-jar-present" message="${jsearch-client-jar} missing.  Build JSearchIndexer and JSearchClient first."/>
        <fail unless="jsearch-indexer-jar-present" message="${jsearch-indexer-jar} missing.  Build JSearchIndexer and JSearchClient first."/>
        <fail unless="jsearch-misc-jar-present" message="${jsearch-misc-jar} missing.  Build JSearchIndexer and JSearchClient first."/>
        <fail unless="jsearch-jar-present" message="${jsearch-jar} missing.  Build JSearchIndexer and JSearchClient first."/>
        
        <copy file="${jsearch-indexer-jar}" tofile="${dist.dir}/jsearch-indexer.jar"/>
        <copy file="${jsearch-client-jar}" tofile="${dist.dir}/jsearch-client.jar"/>
        <copy file="${jsearch-misc-jar}" tofile="${dist.dir}/jsearch-misc.jar"/>
        <copy file="${jsearch-jar}" tofile="${dist.dir}/jsearch.jar"/>
    </target>
    
    <target name="create-javahelp-jars">
        <delete file="${dist.dir}/jhbasic.jar"/>
        <jar jarfile="${dist.dir}/jhbasic.jar" manifest="manifest.mf">
            <fileset dir="${basedir}/build/classes">
                <include name="**/*"/>
                <exclude name="**/package.html"/>
                <exclude name="javax/help/plaf/basic/BasicSearch*.class"/>
                <exclude name="javax/help/search/**"/>
                <include name="javax/help/tagext/NavigatorsTEI.class"/>
                <exclude name="javax/help/SearchHit.class"/>
                <exclude name="javax/help/SearchTOC*.class"/>
                <exclude name="javax/help/JHelpSearchNavigator.class"/>
            </fileset>
        </jar>
        
        <delete file="${dist.dir}/jh.jar"/>
        <jar jarfile="${dist.dir}/jh.jar" manifest="manifest.mf">
            <fileset dir="${basedir}/build/classes">
                <include name="**/*"/>
                <exclude name="**/package.html"/>
            </fileset>
            <fileset dir="${basedir}/../JSearchClient_nbproject/build/classes">
                <include name="com/sun/java/help/search/**"/>
                <exclude name="**/package.html"/>
            </fileset>
        </jar>
        
        <copy todir="${basedir}/build/allclasses">
            <fileset dir="${basedir}/build/classes">
                <include name="**/*"/>
                <exclude name="**/package.html"/>
            </fileset>
            <fileset dir="${basedir}/../JSearchClient_nbproject/build/classes">
                <include name="com/sun/java/help/search/**"/>
                <exclude name="**/package.html"/>
            </fileset>
            <fileset dir="${basedir}/../JSearchIndexer_nbproject/build/classes">
                <include name="*/**"/>
                <exclude name="**/package.html"/>
            </fileset>
        </copy>
        
        <jar jarfile="${dist.dir}/jhall.jar" manifest="manifest.mf">
            <fileset dir="${basedir}/build/allclasses">
                <include name="**/*"/>
            </fileset>
        </jar>
        
        <mkdir dir="${dist.dir}/../bin"/>
        <copy todir="${dist.dir}/../bin">
            <fileset dir="${basedir}/../jhMaster/JavaHelp/javahelp/bin">
                <include name="**"/>
            </fileset>
        </copy>
        
        <jar jarfile="${dist.dir}/../bin/jhindexer.jar">
            <manifest>
                <attribute name="Class-Path" value="../lib/jhall.jar"/>
                <attribute name="Main-Class" value="com.sun.java.help.search.Indexer"/>
            </manifest>
        </jar>
        
        <jar jarfile="${dist.dir}/../bin/jhsearch.jar">
            <manifest>
                <attribute name="Class-Path" value="../lib/jhall.jar"/>
                <attribute name="Main-Class" value="com.sun.java.help.search.QueryEngine"/>
            </manifest>
        </jar>
    </target>

    <available property="post.clean.needed" file="${basedir}/build/allclasses"/>
    <target name="-post-clean" if="post.clean.needed">
        <delete dir="dist"/>
        <delete dir="${basedir}/build/allclasses"/>
        <subant target="clean">
            <dirset dir="..">
                <include name="JSearchClient_nbproject"/>
                <include name="JSearchIndexer_nbproject"/>
            </dirset>
        </subant>
    </target>
    
    <target name="-post-jar">
        <echo>

            
To build the entire javahelp distribution, run the "release" ant target.

        </echo>
    </target>
</project>
