<!--
Build include file for the GridSphere Portal source code, see build.xml

 - $Id: build-deploy.xml 4882 2006-06-26 23:25:47Z novotny $

-->


<project name="GridSphere Deploy">

    <target name="deploy" depends="jar">

        <echo message="GridSphere AppServer: ${gridsphere.appserver}"/>

        <if>
            <equals arg1="${gridsphere.appserver}" arg2="jetty"/>
            <then>
                <echo message="Installing for Jetty"/>
                <antcall target="deploy-jetty"/>
            </then>
        </if>

        <if>
            <equals arg1="${gridsphere.appserver}" arg2="tomcat"/>
            <then>
                <echo message="Installing for Tomcat"/>
                <antcall target="deploy-tomcat"/>
            </then>
        </if>
    </target>


    <target name="deploy-common">

        <!-- Copy the gridsphere web app to build directory -->
        <pathconvert targetos="windows" dirsep="/" property="cathome">
            <path location="${appserver.home}"/>
        </pathconvert>
        <filter token="GRIDSPHERE_DB" value="${cathome}/webapps/${gridsphere.deploy}/WEB-INF/CustomPortal/database/gridsphere"/>
        <copy tofile="${build.webapps}/${gridsphere.deploy}/WEB-INF/CustomPortal/database/hibernate.properties"
              file="${gswebapp.dir}/WEB-INF/CustomPortal/database/hibernate.properties"
              filtering="true"/>
        <filter token="GRIDSPHERE_CONTEXT" value="${gridsphere.context}"/>
        <copy tofile="${build.webapps}/${gridsphere.deploy}/WEB-INF/web.xml"
              file="${gswebapp.dir}/WEB-INF/web.xml"
              filtering="true"/>
        <filter token="GRIDSPHERE_RELEASE" value="${gridsphere.name}"/>
        <copy tofile="${build.webapps}/${gridsphere.deploy}/WEB-INF/gridsphere.properties"
              file="${gswebapp.dir}/WEB-INF/gridsphere.properties"
              filtering="true"/>
        <copy todir="${build.webapps}/${gridsphere.deploy}">
            <fileset dir="${gswebapp.dir}">
                <exclude name="**/tlds/**"/>
                <exclude name="**/test/**"/>
            </fileset>
        </copy>
        <antcall target="modify-webxml"/>

        <!-- copy webappsdir to deployed location -->
        <copy todir="${appserver.home}/webapps">
            <fileset dir="${build.webapps}"/>
        </copy>

        <mkdir dir="${appserver.home}/webapps/${gridsphere.deploy}/docs"/>
        <copy todir="${appserver.home}/webapps/${gridsphere.deploy}/docs">
            <fileset dir="${gridsphere.build}/docs"/>
        </copy>

        <copy overwrite="true" todir="${appserver.home}/webapps/${gridsphere.deploy}/WEB-INF/lib">
            <fileset dir="${build.lib}">
                <include name="gridsphere-ui-tags*.jar"/>
                <include name="coreportlets*.jar"/>
            </fileset>
        </copy>

        <touch file="${appserver.home}/webapps/${gridsphere.deploy}/WEB-INF/CustomPortal/portlets/${gridsphere.deploy}.1"/>

        <!-- only copy if it is there -->
        <if>
            <available file="${build.lib}/gridsphere-jsp.jar"/>
            <then>
                <copy overwrite="true" file="${build.lib}/gridsphere-jsp.jar" todir="${appserver.home}/webapps/${gridsphere.deploy}/WEB-INF/lib"/>
            </then>
        </if>
    </target>

    <target name="modify-webxml">
        <!-- change web.xml if precompiled jsps are available -->
        <if>
            <equals arg1="${gridsphere.useprecompiledjsp}" arg2="true"/>
            <then>

                <if>        <!-- to avoid errormsg if not found -->
                    <available file="${gridsphere.build}/jsp/web.inc"/>
                    <then>
                        <loadfile property="web.inc" srcfile="${gridsphere.build}/jsp/web.inc" failonerror="false"/>
                    </then>
                </if>

                <condition property="web.inc" value="">
                    <not>
                        <isset property="${web.inc}"/>
                    </not>
                </condition>


                <!-- add the web.inc to web.xml (if avail)-->
                <copy
                    tofile="${gridsphere.build}/webapps/${gridsphere.deploy}/WEB-INF/web.xml"
                    file="${gridsphere.build}/webapps/${gridsphere.deploy}/WEB-INF/web-xml.tmpl" overwrite="true">
                    <filterset>
                        <filter token="PRECOMPILED-JSP" value="${web.inc}"/>
                    </filterset>
                </copy>          
            </then>
        </if>
        <delete file="${gridsphere.build}/webapps/${gridsphere.deploy}/WEB-INF/web-xml.tmpl"/>
    </target>


    <!-- ========================================================= -->
    <!-- =          JETTY                                        = -->
    <!-- ========================================================= -->


    <!-- deploys gridsphere to jetty -->
    <target name="deploy-jetty" depends="deploy-common">

        <copy overwrite="true" todir="${appserver.home}/ext">
            <fileset dir="lib">
                <exclude name="*.LICENSE"/>
            </fileset>
            <fileset dir="${build.lib}">
                <exclude name="gridsphere-test*.jar"/>
                <exclude name="gridsphere-ui-tags*.jar"/>
                <exclude name="coreportlets*.jar"/>
                <exclude name="gridsphere-jsp.jar"/>
            </fileset>
        </copy>

    </target>

    <!-- ========================================================= -->
    <!-- =          TOMCAT                                       = -->
    <!-- ========================================================= -->

    <target name="deploy-tomcat" depends="deploy-common">
        <!-- Copy context file -->
        <filter token="GRIDSPHERE_DEPLOY" value="${gridsphere.deploy}"/>
        <if>
            <available file="${appserver.home}/conf/Catalina" type="dir" property="tomcat5"/>
            <then>

                <copy file="webapps/gridsphere-context.xml"
                      tofile="${appserver.home}/conf/Catalina/localhost/${gridsphere.deploy}.xml" filtering="true"/>
                <if>
                    <available classname="org.apache.catalina.valves.FastCommonAccessLogValve">
                        <classpath>
                            <fileset dir="${appserver.home}/server/lib/">
                                <include name="*.jar"/>
                            </fileset>
                            <fileset dir="${appserver.home}/bin/">
                                <include name="*.jar"/>
                            </fileset>
                        </classpath>
                    </available>
                    <then>
                        <echo message="Detected Tomcat 5.5"/>
                        <copy file="${env.ANT_HOME}/lib/ant.jar" tofile="${appserver.home}/shared/lib/ant.jar"/>
                    </then>
                    <else>
                        <echo message="Detected Tomcat 5"/>
                    </else>
                </if>
            </then>
            <else>
                <echo message="Detected Tomcat 4"/>
                <copy file="webapps/gridsphere-context.xml" tofile="${appserver.home}/webapps/${gridsphere.deploy}.xml" filtering="true"/>
            </else>
        </if>

        <copy overwrite="true" todir="${appserver.home}/shared/lib">
            <fileset dir="lib">
                <exclude name="licenses/**"/>
                <exclude name="*.txt"/>
            </fileset>
            <fileset dir="${build.lib}">
                <exclude name="gridsphere-test*.jar"/>
                <exclude name="gridsphere-ui-tags*.jar"/>
                <exclude name="coreportlets*.jar"/>
                <exclude name="gridsphere-jsp.jar"/>
            </fileset>
        </copy>

        <copy file="webapps/log4j.xml" todir="${appserver.home}/common/classes"/>

    </target>

</project>
