<!--
  JBoss, Home of Professional Open Source
  Copyright 2006, Red Hat Middleware LLC, and individual contributors
  as indicated by the @author tags.
  See the copyright.txt in the distribution for a full listing
  of individual contributors.
  This copyrighted material is made available to anyone wishing to use,
  modify, copy, or redistribute it subject to the terms and conditions
  of the GNU Lesser General Public License, v. 2.1.
  This program is distributed in the hope that it will be useful, but WITHOUT A
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public License,
  v.2.1 along with this distribution; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA  02110-1301, USA.


  (C) 2005-2006,
  @author JBoss Inc.
-->

<!-- $Id: xts-build.xml,v 1.12.4.1 2005/11/22 10:42:05 kconner Exp $ -->

<!-- ====================================================================== -->
<!--                                                                        -->
<!--           Copyright (c) 2003, Arjuna Technologies Limited.             -->
<!--                                                                        -->
<!--                 WS-Transaction / XTS demo application                  -->
<!--                                                                        -->
<!-- ====================================================================== -->

<project name="xts-demo" default="build" basedir=".">

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

    <!-- n.b. run this via the build.sh script to ensure that the property  -->
    <!-- settings in jboss.properties are set automatically                 -->

    <!-- The properties to override are the following:                      -->
    <!--    hostname (defaults to localhost)                                -->
    <!--    port (defaults to 8080 for jboss)                               -->
    <!--    urlstub (defaults to xtsdemowebservices for JBoss)              -->

    <!-- the demo needs to be linked against the client libraries           -->
    <!-- installed jboss directory                                          -->

    <property environment="env"/>
    <property name="jboss.home" value="${env.JBOSS_HOME}"/>

    <!--    deploy.dir The deployment directory for the ear                 -->

    <property name="deploy.dir" location="${jboss.home}/server/default/deploy"/>

    <!--  default target build will build an ear file for the demo app for  -->
    <!--  use in a JBoss server with XTS deployed as a JBoss service        -->
    <!--  archive. The demo client communicates with demo services deployed -->
    <!--  as JaxWS endpoints. It employs the WS-COOR and WS-AT/BA 1.1       -->
    <!--  protocol implementation of web services transactions              -->

    <!--  target buildrpc will build an ear file for the demo app using     -->
    <!--  JaxRPC to communicate between the demo client and services. It    -->
    <!--  employs the WS-COOR and WS-AT/BA 1.1 protocol implementation of   -->
    <!--  web services transactions                                         -->

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

    <xmlproperty file="${xmlpropertyfile}" keeproot="false"/>

    <property name="xts.home" value=".."/>

    <property name="lib.dir" location="${xts.home}/lib"/>
    <property name="ext.dir" location="${lib.dir}/ext"/>
    <property name="jboss.client.lib.dir" location="${jboss.home}/client"/>
    <property name="jboss.common.lib.dir" location="${jboss.home}/common/lib"/>

    <property name="lib.libs" value="jbossxts-api.jar"/>

    <property name="ext.libs" value="jbossjta.jar jbossts-common.jar commons-logging.jar"/>
    <property name="jboss.client.libs" value="jaxb-api.jar jboss-javaee.jar jbossws-native-jaxrpc.jar
            jbossws-native-jaxws.jar jbossws-client.jar stax-api.jar jbossws-native-saaj.jar
            jbossws-native-jaxws-ext.jar jbossws-native-core.jar jbossws-common.jar"/>

    <property name="jboss.common.libs" value="servlet-api.jar"/>

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

    <property name="build.dir" location="build"/>
    <property name="src.dir" location="src"/>
    <property name="dd.dir" location="dd"/>
    <property name="jboss.dd.dir" location="${dd.dir}/jboss"/>
    <property name="build.jboss.dd.dir" location="${build.dir}/dd/jboss"/>

    <property name="buildrpc.dir" location="buildrpc"/>
    <property name="srcrpc.dir" location="srcrpc"/>
    <property name="ddrpc.dir" location="ddrpc"/>
    <property name="jboss.ddrpc.dir" location="${ddrpc.dir}/jboss"/>
    <property name="build.jboss.ddrpc.dir" location="${buildrpc.dir}/dd/jboss"/>

    <property name="web.dir" location="web"/>
    <property name="build.web.dir" location="${build.dir}/web"/>

    <property name="javac.debug"             value="on"/>
    <property name="javac.optimize"          value="off"/>

    <path id="lib.path">
        <fileset dir="${lib.dir}" includes="${lib.libs}"/>
    </path>
    <path id="ext.path">
        <fileset dir="${ext.dir}" includes="${ext.libs}"/>
    </path>

    <path id="jboss.client.path">
        <fileset dir="${jboss.client.lib.dir}" includes="${jboss.client.libs}"/>
        <fileset dir="${jboss.common.lib.dir}" includes="${jboss.common.libs}"/>
    </path>

    <filterset id="webxmlrpc.filter">
        <filter token="restaurantATURL" value="${restaurantATRPCURL}"/>
        <filter token="restaurantBAURL" value="${restaurantBARPCURL}"/>
        <filter token="taxiATURL" value="${taxiATRPCURL}"/>
        <filter token="taxiBAURL" value="${taxiBARPCURL}"/>
        <filter token="theatreATURL" value="${theatreATRPCURL}"/>
        <filter token="theatreBAURL" value="${theatreBARPCURL}"/>
        <filter token="hostname" value="${hostname}"/>
        <filter token="port" value="${port}"/>
        <filter token="urlstub" value="${urlstub}rpc"/>
    </filterset>

    <filterset id="webxml.filter">
        <filter token="restaurantATURL" value="${restaurantATURL}"/>
        <filter token="restaurantBAURL" value="${restaurantBAURL}"/>
        <filter token="taxiATURL" value="${taxiATURL}"/>
        <filter token="taxiBAURL" value="${taxiBAURL}"/>
        <filter token="theatreATURL" value="${theatreATURL}"/>
        <filter token="theatreBAURL" value="${theatreBAURL}"/>
        <filter token="hostname" value="${hostname}"/>
        <filter token="port" value="${port}"/>
        <filter token="urlstub" value="${urlstub}"/>
    </filterset>

    <target name="clean">
        <delete dir="${build.dir}"/>
        <delete dir="${buildrpc.dir}"/>
        <delete>
            <fileset dir="." includes="**/*.bak" defaultexcludes="no"/>
            <fileset dir="." includes="**/*~"    defaultexcludes="no"/>
            <fileset dir="." includes="**/#*#"   defaultexcludes="no"/>
            <fileset dir="." includes="**/.#*"   defaultexcludes="no"/>
        </delete>
    </target>

    <target name="init-properties">
        <property name="hostname" value="localhost"/>
        <property name="port" value="8080"/>
        <property name="urlstub" value="xtsdemowebservices"/>
        <path id="compile.path">
            <path refid="lib.path"/>
            <path refid="jboss.client.path"/>
            <path refid="ext.path"/>
        </path>
    </target>

    <target name="init" depends="init-properties">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dir}/classes"/>
        <mkdir dir="${build.jboss.dd.dir}"/>
    </target>

    <target name="initrpc" depends="init-properties">
        <mkdir dir="${buildrpc.dir}"/>
        <mkdir dir="${buildrpc.dir}/classes"/>
        <mkdir dir="${build.jboss.ddrpc.dir}"/>
    </target>

    <target name="compilerpc" depends="initrpc">
        <javac destdir="${buildrpc.dir}/classes" debug="${javac.debug}"
            optimize="${javac.optimize}" deprecation="${javac.deprecation}" >
            <classpath>
                <path refid="compile.path"/>
            </classpath>
            <src path="${srcrpc.dir}"/>
            <patternset>
                <include name="com/arjuna/xts/nightout/clients/jboss/**"/>
                <include name="com/arjuna/xts/nightout/services/**"/>
            </patternset>
        </javac>
    </target>

    <target name="compile" depends="init">
        <javac destdir="${build.dir}/classes" debug="${javac.debug}"
            optimize="${javac.optimize}" deprecation="${javac.deprecation}" >
            <classpath>
                <path refid="compile.path"/>
            </classpath>
            <src path="${src.dir}"/>
            <patternset>
	        <!-- client app -->
                <include name="com/jboss/jbosstm/xts/demo/client/**/*"/>
	        <!-- server impl -->
                <include name="com/jboss/jbosstm/xts/demo/services/**"/>
	        <!-- generated server interfaces and service classes -->
                <include name="com/jboss/jbosstm/xts/demo/restaurant/**"/>
                <include name="com/jboss/jbosstm/xts/demo/taxi/**"/>
                <include name="com/jboss/jbosstm/xts/demo/theatre/**"/>
            </patternset>
        </javac>
    </target>

    <!-- the server side elements -->
    <target name="jboss-webservices" depends="compile">
        <copy tofile="${build.dir}/classes/com/jboss/jbosstm/xts/demo/services/context-handlers.xml"
	      file="${jboss.dd.dir}/context-handlers.xml"/>
        <war destfile="${build.dir}/xts-demo-webservices.war" webxml="${jboss.dd.dir}/service-web-app.xml" >
	    <!-- include app wsdl -->
            <webinf dir="${jboss.dd.dir}" includes="wsdl/*.wsdl"/>
	        <!-- server impl -->
	    <classes dir="${build.dir}/classes">
		 <include name="com/jboss/jbosstm/xts/demo/services/**/*"/>
	    </classes>
	        <!-- generated server interfaces -->
	    <classes dir="${build.dir}/classes/"
		includes="com/jboss/jbosstm/xts/demo/restaurant/IRestaurantServiceAT.class"/>
	    <classes dir="${build.dir}/classes/"
		includes="com/jboss/jbosstm/xts/demo/restaurant/IRestaurantServiceBA.class"/>
	    <classes dir="${build.dir}/classes/"
		includes="com/jboss/jbosstm/xts/demo/theatre/ITheatreServiceAT.class"/>
	    <classes dir="${build.dir}/classes/"
		includes="com/jboss/jbosstm/xts/demo/theatre/ITheatreServiceBA.class"/>
	    <classes dir="${build.dir}/classes/"
		includes="com/jboss/jbosstm/xts/demo/taxi/ITaxiServiceAT.class"/>
	    <classes dir="${build.dir}/classes/"
		includes="com/jboss/jbosstm/xts/demo/taxi/ITaxiServiceBA.class"/>
        </war>
    </target>

    <target name="jboss-webservicesrpc" depends="compilerpc">
        <war destfile="${buildrpc.dir}/xts-demo-webservicesrpc.war" webxml="${jboss.ddrpc.dir}/service-web-app.xml">
            <webinf dir="${jboss.ddrpc.dir}" excludes="client-web-app.xml service-web-app.xml application.xml client-jaxrpc-mapping.xml"/>
            <classes dir="${buildrpc.dir}/classes">
                <include name="com/arjuna/xts/nightout/services/**"/>
            </classes>
        </war>
    </target>

    <!-- the client side elements -->
    <target name="jboss-webapp" depends="compile">
        <copy tofile="${build.dir}/client-web-app.xml" file="${jboss.dd.dir}/client-web-app.xml">
            <filterset refid="webxml.filter"/>
        </copy>

        <war warfile="${build.dir}/xts-demo.war" webxml="${build.dir}/client-web-app.xml">
	    <!-- include app wsdl and wscoor wsdl -->
            <webinf dir="${jboss.dd.dir}" includes="wsdl/*.wsdl"/>
	    <!-- impl classes -->
            <classes dir="${build.dir}/classes"
                includes="com/jboss/jbosstm/xts/demo/client/**"/>
	    <!-- generated interfaces -->
            <classes dir="${build.dir}/classes"
                includes="com/jboss/jbosstm/xts/demo/restaurant/IRestaurantServiceAT.class"/>
            <classes dir="${build.dir}/classes"
                includes="com/jboss/jbosstm/xts/demo/restaurant/IRestaurantServiceBA.class"/>
            <classes dir="${build.dir}/classes"
                includes="com/jboss/jbosstm/xts/demo/theatre/ITheatreServiceAT.class"/>
            <classes dir="${build.dir}/classes"
                includes="com/jboss/jbosstm/xts/demo/theatre/ITheatreServiceBA.class"/>
            <classes dir="${build.dir}/classes"
                includes="com/jboss/jbosstm/xts/demo/taxi/ITaxiServiceAT.class"/>
            <classes dir="${build.dir}/classes"
                includes="com/jboss/jbosstm/xts/demo/taxi/ITaxiServiceBA.class"/>
	    <!-- jsp files -->
            <fileset dir="${web.dir}" excludes="indexrpc.jsp"/>
        </war>
    </target>

    <target name="jboss-webapprpc" depends="compilerpc">
        <copy tofile="${buildrpc.dir}/client-web-app.xml" file="${jboss.ddrpc.dir}/client-web-app.xml">
            <filterset refid="webxmlrpc.filter"/>
        </copy>

        <copy tofile="${build.web.dir}/index.jsp" file="${web.dir}/indexrpc.jsp">
                <filterset refid="webxmlrpc.filter"/>
        </copy>

        <war warfile="${buildrpc.dir}/xts-demorpc.war" webxml="${buildrpc.dir}/client-web-app.xml">
            <classes dir="${buildrpc.dir}/classes">
                <exclude name="com/arjuna/xts/nightout/services/**/*"/>
            </classes>
            <fileset dir="${web.dir}" excludes="index.jsp indexrpc.jsp"/>
            <fileset dir="${build.web.dir}" includes="index.jsp"/>
            <webinf dir="${jboss.ddrpc.dir}" includes="client-jaxrpc-mapping.xml wsdl/**"/>
        </war>
    </target>

    <!-- the ear files -->
    <target name="jboss-ear" depends="jboss-webservices, jboss-webapp">
        <copy tofile="${build.jboss.dd.dir}/application.xml" file="${jboss.dd.dir}/application.xml">
            <filterset refid="webxml.filter"/>
        </copy>
        <ear earfile="${build.dir}/xts-demo.ear"
            appxml="${build.jboss.dd.dir}/application.xml">
            <fileset dir="${build.dir}" includes="xts-demo-webservices.war xts-demo.war"/>
        </ear>
    </target>

    <target name="jboss-earrpc" depends="jboss-webservicesrpc, jboss-webapprpc">
        <copy tofile="${build.jboss.ddrpc.dir}/application.xml" file="${jboss.ddrpc.dir}/application.xml">
            <filterset refid="webxmlrpc.filter"/>
        </copy>
        <ear earfile="${buildrpc.dir}/xts-demorpc.ear"
            appxml="${build.jboss.ddrpc.dir}/application.xml">
            <fileset dir="${buildrpc.dir}" includes="xts-demo-webservicesrpc.war xts-demorpc.war"/>
        </ear>
    </target>

    <target name="build" depends="jboss-ear"/>

    <target name="buildrpc" depends="jboss-earrpc"/>

    <target name="deploy" depends="build, undeploy">
        <copy file="${build.dir}/xts-demo.ear" tofile="${deploy.dir}/xts-demo.ear"/>
    </target>

    <target name="undeploy">
        <delete file="${deploy.dir}/xts-demo.ear"/>
    </target>

    <target name="deployrpc" depends="buildrpc, undeployrpc">
        <copy file="${buildrpc.dir}/xts-demorpc.ear" tofile="${deploy.dir}/xts-demorpc.ear"/>
    </target>

    <target name="undeployrpc">
        <delete file="${deploy.dir}/xts-demorpc.ear"/>
    </target>
</project>
