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

<project name="XTSTestService" default="jar" basedir=".">
    <!-- build a JBoss service which runs a specific test of the XTS service according to an environment setting -->
    <!-- the tests will normally be run in a  JVM employing a TOAST agent and suitable configured TOAST rule set -->

  <property environment="env"/>
  <!-- we need JBOSS_HOME for deployment -->
  <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>

  <!-- ================================================================== -->
  <!-- build and install the XTS Test Service Jar                         -->
  <!-- ================================================================== -->

  <property name="src.dir" value="src"/>
  <property name="dd.dir" value="dd"/>
  <property name="wsdl.dir" value="${dd.dir}/wsdl"/>
  <property name="meta.inf.dir" value="dd/META-INF"/>
  <property name="web.inf.dir" value="dd/WEB-INF"/>
  <property name="build.dir" value="build"/>
  <property name="build.classes.dir" value="${build.dir}/classes"/>
  <property name="build.meta.inf.dir" value="${build.dir}/META-INF"/>
  <property name="build.lib.dir" value="${build.dir}/lib"/>
  <property name="build.webapps.dir" value="${build.dir}/webapps"/>

    <!-- the directory in which XTS resides -->
  <property name="xts.home" value="../../xts-install"/>
  <!-- the directory in which the XTS library code resides -->
  <property name="xts.lib.dir" value="${xts.home}/lib"/>
  <!-- the list of jars containing the XTS API classes -->
  <property name="xts.lib.jars" value="jbossxts-api.jar"/>

  <property name="jboss.client.lib.dir" value="${jbossas.home}/client"/>
  <property name="jboss.client.lib.jars" value="jaxb-api.jar jboss-javaee.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-jaxws.jar jboss-logging-spi.jar"/>
    <property name="jboss.common.lib.dir" location="${jbossas.home}/common/lib"/>
    <property name="jboss.common.lib.jars" value="servlet-api.jar"/>

  <target name="init">
    <delete dir="${build.dir}"/>
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${build.meta.inf.dir}"/>
    <mkdir dir="${build.webapps.dir}"/>
  </target>

  <!-- install ther META-INF data -->
  <target name="metainf">
    <copy todir="${build.meta.inf.dir}">
      <fileset dir="${meta.inf.dir}" includes="*"/>
    </copy>
  </target>

  <!-- compile the XTSTestService -->

    <target name="compile" depends="init">
    <javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="yes">
        <classpath>
            <fileset dir="${xts.lib.dir}" includes="${xts.lib.jars}"/>
            <fileset dir="${jboss.client.lib.dir}" includes="${jboss.client.lib.jars}"/>
            <fileset dir="${jboss.common.lib.dir}" includes="${jboss.common.lib.jars}"/>
        </classpath>
    </javac>
  </target>

  <!-- build a war containing the  compiled XTSTestService and the jboss-beans.xml -->

  <target name="war" depends="compile,metainf">
      <mkdir dir="${build.classes.dir}/org/jboss/jbossts/xts/servicetests/generated/wsdl/"/>
      <copy toDir="${build.classes.dir}/org/jboss/jbossts/xts/servicetests/generated/wsdl/" file="${wsdl.dir}/xtsservicetests.wsdl"/>
      <copy toDir="${build.classes.dir}/org/jboss/jbossts/xts/servicetests/service/" file="${dd.dir}/handlers.xml"/>
      <copy toDir="${build.classes.dir}/org/jboss/jbossts/xts/servicetests/service/subordinate" file="${dd.dir}/subordinatehandlers.xml"/>
     <war warfile="${build.webapps.dir}/xtstest.war" webxml="${web.inf.dir}/web.xml">
         <classes dir="${build.classes.dir}" includes="**/*"/>
         <metainf dir="${build.meta.inf.dir}"/>
         <webinf dir="${dd.dir}" includes="wsdl/**"/>
     </war>
  </target>

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

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

</project>
