<!--
  JBoss, Home of Professional Open Source
  Copyright 2008, 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) 2008, 2009
  @author JBoss, a division of Red Hat.
-->

<!--
    Ant build script to mostly automate the installation of JBossTS components into JBossAS.
    @author Jonathan Halliday (jonathan.halliday@redhat.com), September 2008.
    @author Ivo Studensky (istudens@redhat.com)
-->
<project name="jbossts-install" default="usage" basedir=".">

    <!-- Select which server the JBossTS component will install into.
        For JTS, must have an ORB configured.
        For XTS, must have JBossWSNative configured.
        Path relative to our location (docs/examples/transactions) -->
    <property name="target.server.dir" value="../../../server/all"/>

    <target name="usage">
        <echo message="Usage: 'ant jts' : installs JBossTS JTS (distributed JTA) component"/>
        <echo message="       'ant xts' : installs JBossTS XTS (Web Services Transactions) component"/>
        <echo message="       'ant tools' : installs the embedded transactions tools."/>
        <echo message="                     WARNING: tools are prototype and unsupported"/>
    </target>

    <!-- install XTS into the designated server. We expand the .sar to make it easier to
        reference individual .jar files in a user's classpath or edit the config files. -->
    <target name="xts">
        <mkdir dir="${target.server.dir}/deploy/jbossxts.sar"/>
        <unzip src="jbossxts.sar" dest="${target.server.dir}/deploy/jbossxts.sar/"/>
    </target>

    <!-- deploy the embedded tools into the designated server -->
    <target name="tools">
        <copy file="jbossts-tools.sar" todir="${target.server.dir}/deploy/"/>
    </target>

    <!-- install the JTS into the designated server -->
    <target name="jts">

        <!-- rename the JTA version of the properties file rather than deleting it,
            as it may have customizations we don't want to lose. -->
        <move file="${target.server.dir}/conf/jbossts-properties.xml"
              tofile="${target.server.dir}/conf/jbossts-properties-old-for-jta.xml"/>

        <copy file="jbossts-properties.xml" todir="${target.server.dir}/conf/"/>

        <echo message="Transaction service configuration file installed."/>

        <!-- rewrite the config files for the server that is using JTS -->
        <antcall target="modify-jts-config-files">
            <param name="server.dir" value="${target.server.dir}"/>
        </antcall>

        <echo message="JBossAS config files updated to run JTS in config ${target.server.dir}"/>

    </target>

    <target name="modify-jts-config-files">

        <!--
            edit the conf/jbossts-properties.xml file and remove the
            recovery extension property containing the value
                "com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule"
        -->
        <replaceregexp
            file="${server.dir}/conf/jbossts-properties.xml"
            match="&lt;property\s+name=.com\.arjuna\.ats\.arjuna\.recovery\.recoveryExtension\d+.\s*value=.com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.\s*/&gt;"
            replace=""  />


        <!--
            In deploy/transaction-jboss-beans.xml, update the TransactionManager class and dependencies as follows:
                <bean name="TransactionManager" class="com.arjuna.ats.jbossatx.jts.TransactionManagerService">
                ...
                    <start>
                       <parameter><inject bean="jboss:service=CorbaORB" property="ORB"/></parameter>
                    </start>
                ...
                </bean>
        -->
        <replaceregexp byline="true"
            file="${server.dir}/deploy/transaction-jboss-beans.xml"
            match="com.arjuna.ats.jbossatx.jta.TransactionManagerService"
            replace="com.arjuna.ats.jbossatx.jts.TransactionManagerService"  />

        <replaceregexp
            file="${server.dir}/deploy/transaction-jboss-beans.xml"
            match="&lt;/bean&gt;"
            replace="    &lt;start&gt;&lt;parameter&gt;&lt;inject bean=&quot;jboss:service=CorbaORB&quot; property=&quot;ORB&quot;/&gt;&lt;/parameter&gt;&lt;/start&gt;&#10;&#10;    &lt;/bean&gt;" />

        <!--
            Edit the conf/jacorb.properies as follows.
              - change the jacorb.poa.thread_pool_max property to 32
        -->
        <replaceregexp
            file="${server.dir}/conf/jacorb.properties"
            match="jacorb.poa.thread_pool_max\s*=\s*\d+"
            replace="jacorb.poa.thread_pool_max=32"  />

	<!--
	     Edit the deploy/iiop-service.xml and modify the PortableInterceptorInitializers attribute as follows.
             remove the following lines
                 <!- - comment out to disable null transaction propagation over IIOP - ->
                 <initializer>org.jboss.tm.iiop.TxServerClientInterceptorInitializer</initializer>
                 <!- - comment out to disable transaction demarcation over IIOP - ->
                 <initializer>org.jboss.tm.iiop.TxServerInterceptorInitializer</initializer>
             add the following lines
                 <!- - JBoss TS interceptor. - ->
                 <initializer>com.arjuna.ats.jts.orbspecific.jacorb.interceptors.interposition.InterpositionORBInitializerImpl</initializer>
                 <!- - RMI/IIOP tx context interceptor - ->
                 <initializer>com.arjuna.ats.jbossatx.jts.InboundTransactionCurrentInitializer</initializer>
	-->
        <replaceregexp
            file="${server.dir}/deploy/iiop-service.xml"
            match="org.jboss.tm.iiop.TxServerClientInterceptorInitializer"
            replace="com.arjuna.ats.jts.orbspecific.jacorb.interceptors.interposition.InterpositionORBInitializerImpl"  />
        <replaceregexp
            file="${server.dir}/deploy/iiop-service.xml"
            match="org.jboss.tm.iiop.TxServerInterceptorInitializer"
            replace="com.arjuna.ats.jbossatx.jts.InboundTransactionCurrentInitializer"  />

    </target>
</project>