<!-- =======================================================================

   Build file for the GridSphere Portal source code

Notes:
   This is a build file for use with the Jakarta Ant build tool.

Prerequisites:

   jakarta-ant from http://jakarta.apache.org

Build Instructions:
   Invoke "ant help"

Copyright:
  2002,2003

- $Id: build.eclipse.xml 4496 2006-02-08 20:27:04Z wehrens $

============================================================================ -->

<project name="GridSphere" default="help" basedir=".">


    <!-- Needed to import ant-contrib tasks -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="lib/ant-contrib-0.3.jar"/>
        </classpath>
    </taskdef>

    <taskdef resource="cactus.tasks">
        <classpath>
            <pathelement location="lib/cactus-integration-ant-20030401.jar"/>
        </classpath>
    </taskdef>

    <property file="build.properties"/>

    <property name="optimize" value="false"/>
    <property name="debug" value="on"/>
    <property name="deprecation" value="true"/>

    <!-- Version properties -->
    <property name="version" value="1.0.1"/>
    <property name="release" value=""/>
    <property name="version.release" value="${version} ${release}"/>
    <property name="gridsphere.project" value="gridsphere"/>
    <property name="gridsphere.name" value="GridSphere ${version.release}"/>
    <property name="gridsphere.api" value="GridSphere Portal Framework API ${version.release}"/>

    <!-- GridSphere build and dist directories -->

    <!--- Type of SQL Database to use -->
    <property name="DATABASE_TYPE" value="${gridsphere.database.type}"/>

    <!-- GridSphere webapps files -->
    <property name="gswebapp.dir" value="webapps/gridsphere"/>

    <!-- GridSphere DocBook documentation -->
    <property name="docbook.dir" value="docs/docbook"/>

    <property name="projects.dir" value="projects"/>

    <!-- GridSphere build targets -->
    <property name="build.lib" value="${gridsphere.build}/lib"/>
    <property name="build.classes" value="${gridsphere.build}/classes"/>
    <property name="build.webapps" value="${gridsphere.build}/webapps"/>
    <property name="build.docs" value="${gridsphere.build}/docs"/>
    <property name="build.javadoc" value="${build.docs}/javadocs"/>
    <property name="build.tests" value="${gridsphere.build}/tests"/>

    <patternset id="all.jars">
        <include name="lib/*.jar"/>
    </patternset>

    <!-- =================================================================== -->
    <!-- Sets the CLASSPATH                                                  -->
    <!-- =================================================================== -->

    <path id="eclipse-classpath">

        <pathelement location="${build.classes}"/>

        <pathelement location="${eclipse.build}"/>

        <!-- this is for the servlet JARs in Tomcat 4.1.x -->
        <fileset dir="${catalina.home}/common/lib">
            <include name="*.jar"/>
        </fileset>

        <!-- this is for the servlet JARs in Tomcat 4.1.x -->
        <fileset dir="${catalina.home}/shared/lib">
            <include name="*.jar"/>
        </fileset>

        <!-- this is for the XML JARs in Tomcat 4.1.x -->
        <fileset dir="${catalina.home}/common/endorsed">
            <include name="*.jar"/>
        </fileset>

        <fileset dir="lib">
            <exclude name="*.LICENSE"/>
            <include name="*.jar"/>
        </fileset>

        <pathelement path="${java.class.path}"/>
    </path>

    <target name="help" depends="">
        <echo message="dummy help"/>
    </target>


    <!-- =================================================================== -->
    <!-- Functions                                                           -->
    <!-- =================================================================== -->

    <!-- Copy the necessary resources to the Eclipse Build directory -->

    <target name="eclipse-resources" depends="">

        <mkdir dir="${eclipse.build}/gridsphere"/>

        <copy file="${gswebapp.dir}/WEB-INF/classes/log4j.properties"
            tofile="${eclipse.build}/gridsphere/log4j.properties"/>

        <copy todir="${eclipse.build}/gridsphere/resources">
            <fileset dir="config/resources"/>
        </copy>

    </target>


    <!-- =================================================================== -->
    <!-- Creates database                                                    -->
    <!-- =================================================================== -->

    <target name="eclipse-configure-database" depends="">
        <mkdir dir="${catalina.base}/webapps/gridsphere/WEB-INF/persistence/"/>
        <copy overwrite="true" file="webapps/gridsphere/WEB-INF/persistence/hibernate.properties" todir="${catalina.base}/webapps/gridsphere/WEB-INF/persistence/"/>
        <replace file="${catalina.base}/webapps/gridsphere/WEB-INF/persistence/hibernate.properties"
            token="@GRIDSPHERE_WEBAPP@"
            value="${catalina.base}/${gswebapp.dir}"/>
        <replace file="${catalina.base}/webapps/gridsphere/WEB-INF/persistence/hibernate.properties"
            token="@GRIDSPHERE_DB@"
            value="gridsphere"/>
    </target>

    <target name="eclipse-create-database" depends="eclipse-configure-database">
        <taskdef name="schemaexport"
            classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
            classpathref="eclipse-classpath"/>

        <schemaexport
            properties="${catalina.base}/webapps/gridsphere/WEB-INF/persistence/hibernate.properties"
            quiet="yes"
            text="no"
            drop="no"
            delimiter=";"
            output="schema-export.sql">
            <fileset dir="webapps/gridsphere/WEB-INF/persistence/">
                <include name="**/*.hbm.xml"/>
            </fileset>
        </schemaexport>
        <echo message="Successfully created new database"/>
    </target>



    <!-- =================================================================== -->
    <!-- Deploys GridSphere to Tomcat                                        -->
    <!-- =================================================================== -->
    <target name="eclipse-deploy" depends="eclipse-resources" description="Deploys GridSphere to a local server">

        <antcall target="eclipse-configure-database"/>

        <copy overwrite="yes" todir="${catalina.base}/webapps/gridsphere">
            <fileset dir="${gswebapp.dir}"/>
        </copy>

    </target>

    <target name="eclipse-local-config" depends="">
        <copy overwrite="yes" todir="${catalina.base}/webapps/gridsphere">
            <fileset dir="${local.config}"/>
        </copy>
    </target>

</project>
