<!--
  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) 2005-2008,
  @author JBoss Inc.
-->
<project name="JBossTS QA Suite Distribution" default="dist">

	<property environment="env"/>
	<property name="driver.home" value="dbdrivers"/>

	<!-- set this property to the location of a JBossTS JTA/JTS build or installation -->
	<property name="org.jboss.jbossts.qa.ts.home" location="../install"/>
	<property name="jbossts.install.lib" location="${org.jboss.jbossts.qa.ts.home}/lib"/>

	<!-- set this property to the location of a DTF TestingFramework.jar build -->
	<property name="org.jboss.jbossts.qa.testingframework_location" location="../ext/TestingFramework.jar"/>

	<!-- TODO cd ArjunaJTS/orbportability; ant -f build-anttasks.xml -->
	<property name="org.jboss.jbossts.qa.idlcompiler.lib"
			  location="../ArjunaJTS/orbportability/lib/ext"/>

	<!-- set these to the location(s) of the database drivers -->

	<fileset id="oracle.drivers" dir="${driver.home}/oracle_10_2_0_4/">
		<include name="ojdbc14.jar"/>
	</fileset>

	<fileset id="mssql.drivers" dir="${driver.home}/mssql2005_sqljdbc_2.0/enu/">
		<include name="sqljdbc.jar"/>
        <include name="sqljdbc4.jar"/>
	</fileset>

	<!-- 8.1.408 is broken, use something more recent. -->
	<fileset id="pgsql.drivers" dir="${driver.home}/">
		<include name="postgresql-8.3-603.jdbc3.jar"/>
	</fileset>

	<!-- server version 5 is the first with XA support, do use anything less.
	 		driver versions before 5.0.5 are broken, don't use them either. -->
	<fileset id="mysql.drivers" dir="${driver.home}/">
		<include name="mysql-connector-java-5.1.7-bin.jar"/>
	</fileset>

	<fileset id="ibmdb2.drivers" dir="${driver.home}/DB2_v9/">
		<include name="db2jcc*.jar"/>
	</fileset>

	<fileset id="sybase.drivers" dir="${driver.home}/jConnect-6_0/classes/">
		<include name="jconn3.jar"/>
	</fileset>

	<!-- you should not need to configure anything below here -->

    <property name="driver.url" value="http://www.qa.jboss.com/jdbc-drivers/"/>

	<property name="org.jboss.jbossts.qa.server_manager_location" location="ext/jboss-server-manager-0.1.1.GA.jar"/>
	<property name="org.jboss.jbossts.qa.dist.buildroot" location="build"/>

    <path id="database.drivers.path">
        <fileset refid="oracle.drivers"/>
        <fileset refid="mssql.drivers"/>
        <fileset refid="pgsql.drivers"/>
        <fileset refid="mysql.drivers"/>
        <fileset refid="ibmdb2.drivers"/>
        <fileset refid="sybase.drivers"/>
    </path>

    <target  name="get.drivers">

        <mkdir dir="${driver.home}/oracle_10_2_0_4"/>
        <get src="${driver.url}/ojdbc14.jar"
             dest="${driver.home}/oracle_10_2_0_4/ojdbc14.jar"/>

        <mkdir dir="${driver.home}/mssql2005_sqljdbc_2.0/enu"/>
        <get src="${driver.url}/sqljdbc_2.0/enu/sqljdbc.jar"
             dest="${driver.home}/mssql2005_sqljdbc_2.0/enu/sqljdbc.jar"/>
        <get src="${driver.url}/sqljdbc_2.0/enu/sqljdbc4.jar"
             dest="${driver.home}/mssql2005_sqljdbc_2.0/enu/sqljdbc4.jar"/>

        <get src="http://jdbc.postgresql.org/download/postgresql-8.3-604.jdbc3.jar"
             dest="${driver.home}/postgresql-8.3-603.jdbc3.jar"/>

        <get src="${driver.url}/mysql-connector-java-5.1.7-bin.jar"
             dest="${driver.home}/mysql-connector-java-5.1.7-bin.jar"/>

        <mkdir dir="${driver.home}/DB2_v9"/>
        <get src="${driver.url}/DB2_v9/db2jcc.jar"
             dest="${driver.home}/DB2_v9/db2jcc.jar"/>
        <get src="${driver.url}/DB2_v9/db2jcc_license_cu.jar"
             dest="${driver.home}/DB2_v9/db2jcc_license_cu.jar"/>

        <mkdir dir="${driver.home}/jConnect-6_0/classes"/>
        <get src="${driver.url}/jConnect-6_0/classes/jconn3.jar"
             dest="${driver.home}/jConnect-6_0/classes/jconn3.jar"/>

    </target>


    <target name="buildtype">
		<available file="${jbossts.install.lib}/jbossjts.jar" property="buildtype" value="jts"/>
		<available file="${jbossts.install.lib}/jts.jar" property="buildtype" value="jts"/>

		<available file="${jbossts.install.lib}/jbossjta.jar" property="buildtype" value="jta"/>
		<available file="${jbossts.install.lib}/jta.jar" property="buildtype" value="jta"/>

		<available file="${jbossts.install.lib}/jbossjta-integration.jar" property="integration.build"/>
		<available file="${jbossts.install.lib}/jbossjts-integration.jar" property="integration.build"/>

        <condition property="dist.as">
			<and>
				<isset property="integration.build"/>
				<isset property="as"/>
			</and>
		</condition>

        <fail unless="env.JBOSS_HOME" message="Please set the JBOSS_HOME environment variable" if="integration.build" />

        <condition property="have.jdbc" value="true">
            <and>
                <available file="${driver.home}"/>
                <not>
                    <equals arg1="${java.specification.version}" arg2="1.6"/>
                </not>
            </and>
        </condition>


    </target>

	<target name="dist.as" depends="buildtype" if="dist.as">
		<fail unless="env.JBOSS_HOME" message="Please set the JBOSS_HOME environment variable" />
		<echo message="copying ${env.JBOSS_HOME} - this may take a while ..."/>
		<mkdir dir="${org.jboss.jbossts.qa.dist.buildroot}/as"/>
		<copy todir="${org.jboss.jbossts.qa.dist.buildroot}/as">
			<fileset dir="${env.JBOSS_HOME}"/>
		</copy>
	</target>

	<target name="clean" depends="buildtype">
		<delete dir="${org.jboss.jbossts.qa.dist.buildroot}"/>

        <ant dir="tests" antfile="build-${buildtype}.xml" target="clean"/>
	</target>

	<target name="init" depends="buildtype">
		<mkdir dir="${org.jboss.jbossts.qa.dist.buildroot}"/>
		<antcall target="dist.as"/>
	</target>

	<target name="dist" depends="clean, init">

        <!-- build the test suite -->
		<ant dir="tests" antfile="build-${buildtype}.xml">
			<reference refid="database.drivers.path"/>
            <property name="org.jboss.jbossts.qa.server_manager_location"
			          value="${org.jboss.jbossts.qa.server_manager_location}"/>
		</ant>

		<!-- prepare the content of the qa distribution, which is the product build
			plus the qa stuff overlayed on it -->
		<copy todir="${org.jboss.jbossts.qa.dist.buildroot}">
			<fileset dir="${org.jboss.jbossts.qa.ts.home}"/>
		</copy>
		<copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa/jdbc_profiles">
			<fileset dir="config/jdbc_profiles"/>
		</copy>
		<copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa/perf_profiles">
			<fileset dir="config/perf_profiles"/>
		</copy>
		<copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa/memory_profiles">
			<fileset dir="config/memory_profiles"/>
		</copy>
		<copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa/lib">
			<fileset file="${org.jboss.jbossts.qa.testingframework_location}"/>
			<fileset file="tests/build/jbossts-${buildtype}-qa.jar"/>
			<fileset file="tests/build/astest.jar"/>
			<fileset file="tests/build/java.policy"/>
			<fileset file="${org.jboss.jbossts.qa.server_manager_location}"/>
        </copy>
        <copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa/lib/all_dbdrivers/" failonerror="${have.jdbc}">
            <fileset refid="oracle.drivers"/>
			<fileset refid="mssql.drivers"/>
			<fileset refid="pgsql.drivers"/>
			<fileset refid="mysql.drivers"/>
			<fileset refid="ibmdb2.drivers"/>
			<fileset refid="sybase.drivers"/>
		</copy>
		<copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa" failonerror="false">
			<fileset dir="tests/build/qa">
				<include name="resources/**/*"/>
			</fileset>
			<fileset dir="tests">
				<include name="scripts/**/*"/>
			</fileset>
		</copy>
		<!-- testing is done with some non-default properties: -->
		<copy file="config/jbossts-${buildtype}-properties.xml"
                tofile="${org.jboss.jbossts.qa.dist.buildroot}/etc/jbossts-properties.xml" overwrite="true">
		</copy>

        <!-- for 'loca'l tests, we need some libs we would otherwise have got from DTF -->
        <mkdir dir="${org.jboss.jbossts.qa.dist.buildroot}/qa/lib/ext"/>
        <copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa/lib/ext" failonerror="false">
            <fileset dir="ext">
                <include name="fscontext.jar"/>
                <include name="providerutil.jar"/>
            </fileset>
        </copy>

        <!-- build the qa distribution installer package -->
		<zip destfile="${org.jboss.jbossts.qa.dist.buildroot}/jbossts-${buildtype}-qa-distribution.zip"
			basedir="${org.jboss.jbossts.qa.dist.buildroot}" excludes="jbossts-${buildtype}-qa-distribution.zip"/>

    </target>

	<target name="help">
<echo>Supported targets:
  jta - build tests for the standalone jta transaction engine
  jts - build tests for the standalone jts transaction engine
  jbossjta - build tests for the integrated jta transaction engine
  jbossjts - build tests for the integrated jts transaction engine
  dist - build tests for the last build of the transaction engine

  To include a copy of the AS (pointed to by the JBOSS_HOME
  environment variable) in the distribution please set the ant
  property 'as' to true.</echo>
	</target>
</project>
