<!--
  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.
-->

<!-- ====================================================================== -->
<!--                                                                        -->
<!--        Copyright (c) 2002, 2003, Arjuna Technologies Limited.          -->
<!--                                                                        -->
<!--                      Web service - Coordination                        -->
<!--                                                                        -->
<!-- ====================================================================== -->

<project name="WebServicesCoordination" default="dev-webapps" basedir=".">

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

    <property environment="env"/>
    <property name="jboss.home" value="${env.JBOSS_HOME}"/>
    <property name="jboss.server" value="default"/>
    <property name="jboss.lib.dir" location="${jboss.home}/lib"/>
    <property name="jboss.client.lib.dir" location="${jboss.home}/client"/>
    <property name="jboss.server.dir" location="${jboss.home}/server/${jboss.server}"/>
    <property name="jboss.server.lib.dir" location="${jboss.server.dir}/lib"/>
    <property name="jboss.common.lib.dir" location="${jboss.home}/common/lib"/>

    <!-- ================================================================== -->
    <property name="deploy.dir" value="${jboss.server.dir}/deploy"/>

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

    <property name="build.dir"               value="build"/>
    <property name="dev.src.dir"             value="dev/src"/>
    <property name="dev.src10.dir"             value="dev/src10"/>
    <property name="dev.src11.dir"             value="dev/src11"/>
    <property name="dev.dd.dir"              value="dev/dd"/>
    <property name="tests.src.dir"           value="tests/src"/>
    <property name="tests.dd.dir"            value="tests/dd"/>
    <property name="build.dev.classes.dir"   value="${build.dir}/dev/classes"/>
    <property name="build.dev.classes10.dir"   value="${build.dir}/dev/classes10/classes"/>
    <property name="build.dev.classes11.dir"   value="${build.dir}/dev/classes11/classes"/>
    <property name="build.dev.lib.dir"       value="${build.dir}/dev/lib"/>
    <property name="build.dev.dd.dir"        value="${build.dir}/dev/dd"/>
    <property name="build.dev.webapps.dir"   value="${build.dir}/dev/webapps"/>
    <property name="build.tests.classes.dir" value="${build.dir}/tests/classes"/>
    <property name="build.tests.lib.dir"     value="${build.dir}/tests/lib"/>
    <property name="build.tests.dd.dir"      value="${build.dir}/tests/dd"/>
    <property name="build.tests.webapps.dir" value="${build.dir}/tests/webapps"/>

    <!-- classes provided for clients via api jar -->
    <property name="ws-c.api.classes" value="com/arjuna/wsc/AlreadyRegisteredException.class"/>
    
    <property name="com.arjuna.buildsystem.dir" location="../../antbuildsystem"/>
    <property name="com.arjuna.jta.install" location="../../install"/>

    <property name="com.arjuna.buildsystem.lib" location="${com.arjuna.buildsystem.dir}/build/lib"/>
    <property name="com.arjuna.jta.install.lib" location="${com.arjuna.jta.install}/lib"/>
    <property name="com.arjuna.jta.install.ext" location="${com.arjuna.jta.install.lib}/ext"/>
    <property name="com.arjuna.xts.ext" location="../ext"/>

    <property name="com.arjuna.buildsystem.lib.jars" value="buildsystem.jar"/>

    <property name="jta.lib.jars" value="jbossjta.jar jbossjts.jar"/>
    <property name="jta.ext.jars" value="jbossts-common.jar commons-logging.jar"/>
    <property name="xts.ext.jars" value=""/>
    <property name="jboss.client.lib.jars" 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 jboss-logging-spi.jar"/>
    <property name="jboss.common.lib.jars" value="servlet-api.jar"/>
    <property name="jboss.lib.jars" value="dom4j.jar"/>

    <property name="tests.libs" value="junit.jar"/>

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

    <path id="lib.ext.path">
        <fileset dir="${com.arjuna.jta.install.ext}" includes="${jta.ext.jars}"/>
        <fileset dir="${com.arjuna.jta.install.lib}" includes="${jta.lib.jars}"/>
        <fileset dir="${jboss.client.lib.dir}" includes="${jboss.client.lib.jars}"/>
        <fileset dir="${jboss.common.lib.dir}" includes="${jboss.common.lib.jars}"/>
        <fileset dir="${jboss.lib.dir}" includes="${jboss.lib.jars}"/>
    </path>

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

	<!-- name of the resource bundle -->
    <property name="com.arjuna.mwlabs.wsc.resourcebundle"
	      value="wsc_msg_en_US.properties"/>
    <!-- Define classpath builder task -->
    <path id="com.arjuna.buildsystem.classpath">
        <fileset dir="${com.arjuna.buildsystem.lib}" includes="${com.arjuna.buildsystem.lib.jars}"/>
    </path>
    <property name="com.arjuna.buildsystem.classpath" refid="com.arjuna.buildsystem.classpath"/>
	<taskdef name="classpath-builder" classname="com.hp.mw.buildsystem.ant.ClasspathBuilder" classpathref="com.arjuna.buildsystem.classpath"/>
	<!-- class path behaviour -->
	<property name="build.sysclasspath" value="last"/>
	<property name="com.arjuna.mwlabs.classpathbuilderfilename" location="buildsystem.classpath"/>

    <target name="clean">
        <delete dir="${build.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" depends="clean,init-dir"/>

    <target name="init-dir">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dev.classes.dir}"/>
        <mkdir dir="${build.dev.classes10.dir}"/>
        <mkdir dir="${build.dev.classes11.dir}"/>
        <mkdir dir="${build.dev.lib.dir}"/>
        <mkdir dir="${build.dev.dd.dir}"/>
        <mkdir dir="${build.dev.webapps.dir}"/>
        <mkdir dir="${build.tests.classes.dir}"/>
        <mkdir dir="${build.tests.lib.dir}"/>
        <mkdir dir="${build.tests.dd.dir}"/>
        <mkdir dir="${build.tests.webapps.dir}"/>
    </target>

    <target name="dev-compile-generic" depends="init">
        <javac destdir="${build.dev.classes.dir}" debug="${javac.debug}" optimize="${javac.optimize}">
            <classpath>
                <path refid="lib.ext.path"/>
            </classpath>
            <src path="${dev.src.dir}"/>
        </javac>
    </target>

    <target name="dev-compile10" depends="dev-compile-generic">
        <javac destdir="${build.dev.classes10.dir}" debug="${javac.debug}" optimize="${javac.optimize}">
            <classpath>
                <path>
                  <pathelement path="${build.dev.classes.dir}"/>
                </path>
                <path refid="lib.ext.path"/>
            </classpath>
            <src path="${dev.src10.dir}"/>
        </javac>
    	<copy todir="${build.dev.classes.dir}">
    		<fileset dir="${dev.src10.dir}" excludes="**/*.java"/>
    	</copy>
    </target>

    <target name="dev-compile11" depends="dev-compile-generic">
        <javac destdir="${build.dev.classes11.dir}" debug="${javac.debug}" optimize="${javac.optimize}">
            <classpath>
                <path>
                  <pathelement path="${build.dev.classes.dir}"/>
                </path>
                <path refid="lib.ext.path"/>
            </classpath>
            <src path="${dev.src11.dir}"/>
        </javac>
    </target>

    <target name="dev-compile" depends="dev-compile11, dev-compile10"/>

    <target name="dev-resourcebundle">
        <echo message="Generating WS-C Bundle"/>

        <classpath-builder filename="${com.arjuna.mwlabs.classpathbuilderfilename}" inproperty="build.classpath"/>

        <javadoc    packagenames="com.arjuna.*"
                    failonerror="yes"
                    private="yes"
                    defaultexcludes="yes"
                    classpath="${build.classpath}">

            <packageset dir="${dev.src.dir}" defaultexcludes="yes">
              <include name="com/arjuna/**"/>
            </packageset>

            <packageset dir="${dev.src10.dir}" defaultexcludes="yes">
              <include name="com/arjuna/**"/>
            </packageset>

            <packageset dir="${dev.src11.dir}" defaultexcludes="yes">
              <include name="com/arjuna/**"/>
            </packageset>

             <doclet name="com.hp.mw.buildsystem.doclet.resbundledoclet.ResourceBundleDoclet">
                <path>
                    <pathelement path="${com.arjuna.buildsystem.classpath}"/>
                </path>
                <param name="-basedir" value="${basedir}/${build.dev.classes.dir}"/>
                <param name="-resourcebundle" value="${com.arjuna.mwlabs.wsc.resourcebundle}"/>
             </doclet>
        </javadoc>
    </target>

    <target name="dev-jars" depends="dev-compile, dev-resourcebundle" >
        <!-- wsdl files for services - loaded as /WEB-INF/wsdl/... -->
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/wscoor.wsdl" tofile="${build.dev.dd.dir}/wsdl/wscoor.wsdl"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/wscoor.xsd" tofile="${build.dev.dd.dir}/wsdl/wscoor.xsd"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/ws-addr.xsd" tofile="${build.dev.dd.dir}/wsdl/ws-addr.xsd"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/wscoor-activation-binding.wsdl" tofile="${build.dev.dd.dir}/wsdl/wscoor-activation-binding.wsdl"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/wscoor-registration-binding.wsdl" tofile="${build.dev.dd.dir}/wsdl/wscoor-registration-binding.wsdl"/>

        <!-- wsdl files for clients - loaded as <ClientClassDir>/wsdl/... -->
        <mkdir dir="${build.dev.classes11.dir}/org/oasis_open/docs/ws_tx/wscoor/_2006/_06/wsdl"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/wscoor.wsdl" tofile="${build.dev.classes11.dir}/org/oasis_open/docs/ws_tx/wscoor/_2006/_06/wsdl/wscoor.wsdl"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/wscoor.xsd" tofile="${build.dev.classes11.dir}/org/oasis_open/docs/ws_tx/wscoor/_2006/_06/wsdl/wscoor.xsd"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/ws-addr.xsd" tofile="${build.dev.classes11.dir}/org/oasis_open/docs/ws_tx/wscoor/_2006/_06/wsdl/ws-addr.xsd"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/wscoor-activation-binding.wsdl" tofile="${build.dev.classes11.dir}/org/oasis_open/docs/ws_tx/wscoor/_2006/_06/wsdl/wscoor-activation-binding.wsdl"/>
        <copy file="${dev.dd.dir}/wscoor1.1/wsdl/wscoor-registration-binding.wsdl" tofile="${build.dev.classes11.dir}/org/oasis_open/docs/ws_tx/wscoor/_2006/_06/wsdl/wscoor-registration-binding.wsdl"/>

	<copy file="${dev.dd.dir}/soapfault/wsdl/soapfault.wsdl" tofile="${build.dev.classes11.dir}/org/jboss/jbossts/xts/soapfault/wsdl/soapfault.wsdl"/>
	<copy file="${dev.dd.dir}/soapfault/wsdl/envelope.xsd" tofile="${build.dev.classes11.dir}/org/jboss/jbossts/xts/soapfault/wsdl/envelope.xsd"/>
        <jar jarfile="${build.dev.lib.dir}/ws-c.jar">
            <fileset dir="${build.dev.classes.dir}" excludes="${ws-c.api.classes}"/>
        </jar>
        <jar jarfile="${build.dev.lib.dir}/ws-c-api.jar">
            <fileset dir="${build.dev.classes.dir}" includes="${ws-c.api.classes}"/>
        </jar>
        <jar jarfile="${build.dev.lib.dir}/ws-c10.jar">
            <fileset dir="${build.dev.classes10.dir}"/>
        </jar>
        <jar jarfile="${build.dev.lib.dir}/ws-c11.jar">
            <fileset dir="${build.dev.classes11.dir}">
                <exclude name="com/arjuna/webservices11/wscoor/sei/**"/>
                <exclude name="handlers.xml"/>
            </fileset>
        </jar>
    </target>

    <target name="dev-webapps" depends="dev-jars" >
        <copy file="${dev.dd.dir}/ws-c_web-app.xml" tofile="${build.dev.dd.dir}/web-app.xml">
        </copy>
        <copy file="${dev.dd.dir}/ws-c11_web-app.xml" tofile="${build.dev.dd.dir}/web-app11.xml">
        </copy>
        <copy file="${dev.dd.dir}/ws-c_handlers.xml" tofile="${build.dev.classes11.dir}/handlers.xml"/>
        <war warfile="${build.dev.webapps.dir}/ws-c10.war" webxml="${build.dev.dd.dir}/web-app.xml"/>
        <war warfile="${build.dev.webapps.dir}/ws-c11.war" webxml="${build.dev.dd.dir}/web-app11.xml">
            <webinf dir="${build.dir}/dev/classes11" includes="classes/com/arjuna/webservices11/wscoor/sei/* classes/handlers.xml"/>
            <webinf dir="${build.dev.dd.dir}" includes="wsdl/**"/>
        </war>
    </target>

    <!-- this assumes the required libs have already been built -->
    <target name="tests-compile">
        <javac destdir="${build.tests.classes.dir}" debug="${javac.debug}" optimize="${javac.optimize}">
            <classpath>
                <pathelement path="${build.dev.lib.dir}/ws-c.jar"/>
                <pathelement path="${build.dev.lib.dir}/ws-c-api.jar"/>
                <pathelement path="${build.dev.lib.dir}/ws-c10.jar"/>
                <pathelement path="${build.dev.lib.dir}/ws-c11.jar"/>
                <path refid="tests.lib.path"/>
                <path refid="lib.ext.path"/>
            </classpath>
            <src path="${tests.src.dir}"/>
        </javac>
    </target>
    <!-- this assumes the required libs have already been built -->
    <target name="tests-compile11">
        <javac destdir="${build.tests.classes.dir}" debug="${javac.debug}" optimize="${javac.optimize}">
            <classpath>
                <pathelement path="${build.dev.lib.dir}/ws-c.jar"/>
                <pathelement path="${build.dev.lib.dir}/ws-c-api.jar"/>
                <pathelement path="${build.dev.lib.dir}/ws-c11.jar"/>
                <path refid="tests.lib.path"/>
                <path refid="lib.ext.path"/>
            </classpath>
            <src path="${tests.src.dir}"/>
	        <include name="com/arjuna/qa/**"/>
	        <include name="com/arjuna/wsc11/**"/>
        </javac>
    </target>

    <target name="tests-webapps" depends="tests-compile" >
        <copy file="${tests.dd.dir}/ws-c-tests_web-app.xml" tofile="${build.tests.dd.dir}/web-app.xml">
        </copy>
        <copy file="${tests.dd.dir}/ws-c11-tests_web-app.xml" tofile="${build.tests.dd.dir}/web-app11.xml">
        </copy>
        <war warfile="${build.tests.webapps.dir}/ws-c-tests.war" webxml="${build.tests.dd.dir}/web-app.xml">
            <classes dir="${build.tests.classes.dir}"/>
        </war>
        <war warfile="${build.tests.webapps.dir}/ws-c11-tests.war" webxml="${build.tests.dd.dir}/web-app11.xml">
            <classes dir="${build.tests.classes.dir}"/>
        </war>
        <ear earfile="${build.tests.webapps.dir}/ws-c-tests.ear" appxml="${tests.dd.dir}/ws-c-tests_application.xml">
            <!--
            <fileset dir="${com.arjuna.jta.install.ext}" includes="${jta.ext.jars}"/>
            -->
            <fileset dir="${com.arjuna.xts.ext}" includes="${tests.libs}"/>
            <!--
            <fileset dir="${com.arjuna.jta.install.lib}" includes="${jta.lib.jars}"/>
            <fileset dir="${build.dev.lib.dir}" includes="ws-c10.jar ws-c.jar"/>
            -->
            <fileset dir="${build.tests.webapps.dir}" includes="ws-c-tests.war"/>
            <fileset dir="${build.tests.webapps.dir}" includes="ws-c11-tests.war"/>
        </ear>
    </target>

    <target name="tests-webapps11" depends="tests-compile11" >
        <copy file="${tests.dd.dir}/ws-c11-tests_web-app.xml" tofile="${build.tests.dd.dir}/web-app11.xml">
        </copy>
        <war warfile="${build.tests.webapps.dir}/ws-c11-tests.war" webxml="${build.tests.dd.dir}/web-app11.xml">
            <classes dir="${build.tests.classes.dir}"/>
        </war>
        <ear earfile="${build.tests.webapps.dir}/ws-c-tests.ear" appxml="${tests.dd.dir}/ws-c11-tests_application.xml">
            <!--
            <fileset dir="${com.arjuna.jta.install.ext}" includes="${jta.ext.jars}"/>
            -->
            <fileset dir="${com.arjuna.xts.ext}" includes="${tests.libs}"/>
            <!--
            <fileset dir="${com.arjuna.jta.install.lib}" includes="${jta.lib.jars}"/>
            <fileset dir="${build.dev.lib.dir}" includes="ws-c10.jar ws-c.jar"/>
            -->
            <fileset dir="${build.tests.webapps.dir}" includes="ws-c11-tests.war"/>
        </ear>
    </target>

    <!-- production target for 1.1 tests -->
    <target name="tests-11" depends="tests-webapps11"/>

    <target name="tests-both" depends="tests-webapps"/>
    
    <target name="tests-deploy" depends="tests-webapps, tests-undeploy">
        <copy file="${build.tests.webapps.dir}/ws-c-tests.ear" tofile="${deploy.dir}/ws-c-tests.ear"/>
    </target>

    <target name="tests-deploy11" depends="tests-webapps11, tests-undeploy">
        <copy file="${build.tests.webapps.dir}/ws-c-tests.ear" tofile="${deploy.dir}/ws-c-tests.ear"/>
    </target>

    <target name="tests-undeploy">
        <delete file="${deploy.dir}/ws-c-tests.ear"/>
    </target>
</project>
