<!--
  JBoss, Home of Professional Open Source
  Copyright 2007, 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) 2007,
  @author JBoss Inc.
-->

<project name="sar" default="sar-both" basedir=".">

    <!-- ================================================================== -->
    <!-- build and install the XTS component as a service archive           -->

    <!-- The properties to override are the following:                      -->
    <!--    coordinator.hostname (defaults to ${hostname})                  -->
    <!--    coordinator.port (defaults to ${port})                          -->
    <!--    xts.home The installation directory for XTS                     -->
    <!--    server deployment directory (set via env var JBOSS_HOME)        -->
    <!-- ================================================================== -->

    <!-- devs: run 'ant jta; cd XTS; ant install' after svn checkout -->

    <!-- the directory in which XTS resides -->
    <property name="xts.home" value="../xts-install"/>

    <!-- the name of the host where the coordinator resides. this defaults to the
    special symbol server.bind.address which will be substituted with the actual
    server bind address employed when jboss is started -->
    <property name="coordinator.hostname" value="server.bind.address"/>

    <!-- the name of the port the coordinator is listening on.  this defaults to the
    special symbol jboss.web.bind.port which will be substituted with the actual
    jboss web service HTTP listener port employed when jboss is started -->
    <property name="coordinator.port" value="jboss.web.bind.port"/>

    <!-- the directory in which your installed app server resides -->
    <property environment="env"/>

    <condition property="jbossas.home" value="${env.JBOSS_HOME}">
      <isset property="env.JBOSS_HOME"/>
    </condition>

    <fail unless="jbossas.home">
The JBoss installation directory must be specified with the JBOSS_HOME environment variable or the jboss.home property.
    </fail>

    <property name="lib.dir" location="${xts.home}/lib"/>
    <property name="webapps.dir" location="${xts.home}/webapps"/>
    <property name="conf.dir" location="${xts.home}/conf"/>
    <property name="ext.dir" location="${lib.dir}/ext"/>

    <property name="webinf.dir"         value="WEB-INF"/>
    <property name="metainf.dir"         value="META-INF"/>
    <property name="build.dir"         value="build"/>
    <property name="build.classes.dir" value="${build.dir}/classes"/>
    <property name="build.webinf.dir"       value="${build.dir}/WEB-INF"/>
    <property name="build.metainf.dir"       value="${build.dir}/META-INF"/>
    <property name="build.conf.dir" location="${build.dir}/conf"/>

    <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.client.lib.dir" value="${jbossas.home}/client"/>
    <!-- enable debugging of XTS service code -->

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

    <!-- name of the resource bundle -->
    <property name="xts.resourcebundle"
          value="xts_msg_en_US.properties"/>
    <!-- Define buildsystem classpath -->
    <property name="com.arjuna.buildsystem.lib.jars" value="buildsystem.jar"/>

    <property name="com.arjuna.buildsystem.dir" location="../../antbuildsystem"/>
    <property name="com.arjuna.buildsystem.lib" location="${com.arjuna.buildsystem.dir}/build/lib"/>

    <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"/>

    <property name="bridge.api.class.files" value="org/jboss/jbossts/xts/bridge/at/BridgeWrapper.class"/>

    <target name="init">
        <delete dir="${build.dir}"/>
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.classes.dir}"/>
        <mkdir dir="${build.dir}/tmp"/>
        <mkdir dir="${build.webinf.dir}"/>
        <mkdir dir="${build.metainf.dir}"/>
        <mkdir dir="${build.conf.dir}"/>
    </target>

    <!-- TODO are the xts engine and its WS stack conceptually separate deployments? at what level do they integrate? spi or jax-ws?-->

    <!-- by default build XTS service archive supporting 1.1 WS-C/T protocols -->
    <target name="sar" depends="sar-11"/>

    <target name="compile" depends="init">
        <javac srcdir="src" destdir="${build.classes.dir}" debug="${javac.debug}" excludes="org/jboss/jbossts/xts/bridge/**/*" >
            <classpath>
                <fileset dir="${jboss.client.lib.dir}" includes="${jboss.client.lib.jars}"/>
                <pathelement location="${jbossas.home}/lib/jboss-system-jmx.jar"/>
                <fileset dir="${lib.dir}" includes="*.jar"/>
                <fileset dir="${lib.dir}/ext" includes="jbossjta.jar jbossjts.jar jbossts-common.jar"/>
            </classpath>
        </javac>
    </target>

    <!-- compile the 1.1 specific classes in the sar source which support WS-AT 1.1. bridging -->
    <target name="compile11" depends="compile">
        <javac srcdir="src" destdir="${build.classes.dir}" debug="${javac.debug}" includes="org/jboss/jbossts/xts/bridge/**/*" >
            <classpath>
                <fileset dir="${jboss.client.lib.dir}" includes="${jboss.client.lib.jars}"/>
                <pathelement location="${jbossas.home}/lib/jboss-system-jmx.jar"/>
                <fileset dir="${lib.dir}" includes="*.jar"/>
                <fileset dir="${lib.dir}/ext" includes="jbossjta.jar jbossjts.jar jbossts-common.jar"/>
            </classpath>
        </javac>
    </target>

    <!-- build the messages resource bundle for use by the XTS logger -->
    <target name="dev-resourcebundle">
        <echo message="Generating XTS Bundle"/>

        <javadoc    packagenames="org.jboss.jbossts.*"
                    failonerror="yes"
                    private="yes"
                    defaultexcludes="yes"
                    classpath="${build.classes.dir}">

            <packageset dir="src" defaultexcludes="yes">
              <include name="org/jboss/jbossts/**"/>
            </packageset>

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

    <target name="api-both-jar">
        <mkdir dir="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-c-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-t-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-t10-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-t11-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/wstx-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/wstx10-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/wstx11-api.jar" dest="${build.dir}/tmp/api"/>
        <!-- include bridge api class -->
        <copy todir="${build.dir}/tmp/api">
            <fileset dir="${build.classes.dir}" includes="${bridge.api.class.files}"/>
        </copy>
        <jar file="${build.dir}/jbossxts-api.jar" basedir="${build.dir}/tmp/api"/>
        <copy file="${build.dir}/jbossxts-api.jar" tofile="${lib.dir}/jbossxts-api.jar"/>
        <delete dir="${build.dir}/tmp/api"/>
    </target>

    <target name="api11-jar">
        <mkdir dir="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-c-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-t-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-t11-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/wstx-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/wstx11-api.jar" dest="${build.dir}/tmp/api"/>
        <!-- include bridge api class -->
        <copy todir="${build.dir}/tmp/api">
            <fileset dir="${build.classes.dir}" includes="${bridge.api.class.files}"/>
        </copy>
        <jar file="${build.dir}/jbossxts-api.jar" basedir="${build.dir}/tmp/api"/>
        <copy file="${build.dir}/jbossxts-api.jar" tofile="${lib.dir}/jbossxts-api.jar"/>
        <delete dir="${build.dir}/tmp/api"/>
    </target>
    
    <target name="api10-jar">
        <mkdir dir="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-c-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-t-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/ws-t10-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/wstx-api.jar" dest="${build.dir}/tmp/api"/>
        <unjar src="${lib.dir}/wstx10-api.jar" dest="${build.dir}/tmp/api"/>
        <jar file="${build.dir}/jbossxts-api.jar" basedir="${build.dir}/tmp/api"/>
        <copy file="${build.dir}/jbossxts-api.jar" tofile="${lib.dir}/jbossxts-api.jar"/>
        <delete dir="${build.dir}/tmp/api"/>
    </target>

    <!-- build XTS service archive supporting both 1.0 and 1.1 WS-C/T protocols -->
    <target name="sar-both" depends="init, compile11, compile, dev-resourcebundle, api-both-jar">
        <!-- create config jar containing conf files for 1.0 and 1.1 -->
        <filter token="coordinator.hostname" value="${coordinator.hostname}"/>
        <filter token="coordinator.port" value="${coordinator.port}"/>
        <copy todir="${build.conf.dir}" filtering="true">
            <fileset dir="${conf.dir}" includes="*.xml"/>
        </copy>
        <jar jarfile="${build.dir}/config.jar">
            <fileset dir="${build.conf.dir}"/>
        </jar>

        <!-- copy 11 and 1.0 application.xml to build dir -->
        <copy toFile="${build.metainf.dir}/application.xml" file="${metainf.dir}/application.xml"/>

        <!-- pack everything in the service archive -->
        <jar jarfile="${build.dir}/jbossxts.sar">
            <!-- include generic 1.0 and 1.1 jars -->
	    <!--
            <fileset dir="${lib.dir}" includes="*.jar"/>
-->
            <fileset dir="${lib.dir}" includes="*.jar" excludes="*-api.jar"/>

            <fileset dir="${build.dir}" includes="jbossxts-api.jar"/>

            <!-- include 1.0 and 1.1 web apps -->
            <fileset dir="${webapps.dir}" includes="*.war"/>

            <!-- include config jar -->
            <fileset dir="${build.dir}" includes="config.jar"/>

            <!-- include service def (e.g. dependencies) -->
            <fileset dir="." includes="META-INF/jboss-beans.xml"/>

            <!-- include web service config -->
            <fileset dir="${build.dir}" includes="META-INF/application.xml"/>

            <!-- include sar boot and shutdown code and 1.1 bridge code *but* exclude the bridge API class -->
	        <fileset dir="${build.classes.dir}" includes="**/*" excludes="${bridge.api.class.files}"/>
        </jar>
    </target>

    <!-- build XTS service archive supporting 1.1 WS-C/T protocols -->
    <target name="sar-11" depends="init, compile11, compile, dev-resourcebundle, api11-jar">
        <!-- create config jar containing conf files for 1.1 -->
        <filter token="coordinator.hostname" value="${coordinator.hostname}"/>
        <filter token="coordinator.port" value="${coordinator.port}"/>
        <copy todir="${build.conf.dir}" filtering="true">
            <fileset dir="${conf.dir}" includes="*11.xml"/>
        </copy>
        <jar jarfile="${build.dir}/config.jar">
            <fileset dir="${build.conf.dir}"/>
        </jar>

        <!-- copy 11 application.xml to build dir -->
        <copy toFile="${build.metainf.dir}/application.xml" file="${metainf.dir}/application11.xml"/>

        <!-- pack everything in the service archive -->
        <jar jarfile="${build.dir}/jbossxts.sar">
            <!-- include generic and 1.1 jars -->
            <fileset dir="${lib.dir}" includes="*.jar" excludes="*10.jar *api.jar"/>

            <fileset dir="${build.dir}" includes="jbossxts-api.jar"/>

            <!-- include 1.1 web apps-->
            <fileset dir="${webapps.dir}" includes="*11.war"/>

            <!-- include config jar -->
            <fileset dir="${build.dir}" includes="config.jar"/>

            <!-- include service def (e.g. dependencies) -->
            <fileset dir="." includes="META-INF/jboss-beans.xml"/>

            <!-- include web service config -->
            <fileset dir="${build.dir}" includes="META-INF/application.xml"/>

            <!-- include sar boot and shutdown code and 1.1 bridge code *but* exclude the bridge API class -->
	        <fileset dir="${build.classes.dir}" includes="**/*" excludes="${bridge.api.class.files}"/>
        </jar>
    </target>

    <!-- build XTS service archive supporting 1.0 WS-C/T protocols -->
    <target name="sar-10" depends="init, compile, dev-resourcebundle, api10-jar">
        <!-- create config jar containing conf files for 1.0 -->
        <filter token="coordinator.hostname" value="${coordinator.hostname}"/>
        <filter token="coordinator.port" value="${coordinator.port}"/>
        <copy todir="${build.conf.dir}" filtering="true">
            <fileset dir="${conf.dir}" includes="*.xml" excludes="*11.xml"/>
        </copy>
        <jar jarfile="${build.dir}/config.jar">
            <fileset dir="${build.conf.dir}"/>
        </jar>

        <!-- copy 10 application.xml to build dir -->
        <copy toFile="${build.metainf.dir}/application.xml" file="${metainf.dir}/application10.xml"/>

        <!-- pack everything in the service archive -->
        <jar jarfile="${build.dir}/jbossxts.sar">
            <!-- include generic and 1.0 jars -->
            <fileset dir="${lib.dir}" includes="*.jar" excludes="*11.jar *api.jar"/>

            <fileset dir="${build.dir}" includes="jbossxts-api.jar"/>

            <!-- include 1.0 web apps -->
            <fileset dir="${webapps.dir}" includes="*10.war"/>

            <!-- include config jar -->
            <fileset dir="${build.dir}" includes="config.jar"/>

            <!-- include service def (e.g. dependencies) -->
            <fileset dir="." includes="META-INF/jboss-beans.xml"/>

            <!-- include web service config -->
            <fileset dir="${build.dir}" includes="META-INF/application.xml"/>

            <!-- include sar boot and shutdown code -->
            <fileset dir="${build.classes.dir}" includes="**/*"/>
        </jar>
    </target>

    <target name="clean">
      <delete dir="${build.dir}"/>
      <delete file="${lib.dir}/jbossxts-api.jar"/>
    </target>

    <!-- convenience targets to build and deploy the service archive -->
    <target name="deploy-11" depends="undeploy, sar-11">
        <copy file="${build.dir}/jbossxts.sar" todir="${jbossas.home}/server/default/deploy"/>
    </target>

    <target name="deploy-10" depends="undeploy, sar-10">
        <copy file="${build.dir}/jbossxts.sar" todir="${jbossas.home}/server/default/deploy"/>
    </target>

    <target name="deploy-both" depends="undeploy, sar-both">
        <copy file="${build.dir}/jbossxts.sar" todir="${jbossas.home}/server/default/deploy"/>
    </target>

    <!-- by default deploy sar implementing 1.1 and 1.0 WS-C/T protocols -->
    <target name="deploy" depends="deploy-both">
    </target>

    <target name="undeploy">
        <delete file="${jbossas.home}/server/default/deploy/jbossxts.sar"/>
    </target>

</project>
