<!--
  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.
-->
<project name="WSAS" default="com.arjuna.mw.wsas.jar" basedir=".">
	<!-- Set module name -->
	<property name="com.arjuna.mwlabs.ts.modulename" value="wsas"/>

	<!-- Set default properties filename -->
	<property name="com.arjuna.mw.wsas.properties" value="wsas.properties"/>

	<!-- Load Build Properties File -->
	<property file="${com.arjuna.mw.wsas.properties}"/>

	<!-- Set property defaults -->
	<property environment="env"/>
	<property name="jboss.dir" value="${env.JBOSS_HOME}"/>
	<property name="deploy.dir" value="${jboss.dir}/server/default/deploy"/>

    <property name="jboss.lib.dir" location="${jboss.dir}/lib"/>
    <property name="jboss.client.lib.dir" location="${jboss.dir}/client"/>
    <property name="jboss.common.lib.dir" location="${jboss.dir}/common/lib"/>

    <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"/>
    <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="com.arjuna.mwlabs.wsas.resourcebundle" value="wsas_msg_en_US.properties"/>

	<!-- Set internal property defaults -->
	<!-- Path names -->
	<property name="com.arjuna.mwlabs.wsas.src" value="classes"/>
	<property name="com.arjuna.mwlabs.wsas.dest.root" value="build"/>
	<property name="com.arjuna.mwlabs.wsas.dest" value="${com.arjuna.mwlabs.wsas.dest.root}/classes"/>
	<property name="com.arjuna.mwlabs.wsas.jar.dest" value="${com.arjuna.mwlabs.wsas.dest.root}/lib"/>
	<property name="com.arjuna.mwlabs.wsas.htdocs.dest" value="build/htdocs"/>

	<!-- test path names -->
	<property name="com.arjuna.mwlabs.wsas.tests.src" value="tests/classes"/>
	<property name="com.arjuna.mwlabs.wsas.tests.dd" value="tests/dd"/>
	<property name="com.arjuna.mwlabs.wsas.tests.dest.root" value="tests/build"/>
	<property name="com.arjuna.mwlabs.wsas.tests.dest" value="tests/build/classes"/>
	<property name="com.arjuna.mwlabs.wsas.tests.dd.dest" value="tests/build/dd"/>
	<property name="com.arjuna.mwlabs.wsas.tests.webapps.dest" value="tests/build/webapps"/>
	<property name="com.arjuna.mwlabs.wsas.tests.jar.dest" value="tests/build/lib"/>

	<!-- class path behaviour -->
    <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="build.sysclasspath" value="last"/>
	<property name="com.arjuna.mwlabs.classpathbuilderfilename" location="buildsystem.classpath"/>

	<path id="com.arjuna.mwlabs.wsas.lib.classpath">
        <fileset dir="${com.arjuna.jta.install.ext}" includes="${jta.ext.jars}"/>
        <fileset dir="${com.arjuna.jta.install.lib}" includes="${jta.lib.jars}"/>
    </path>

	<!-- tests library and path to library -->
	<property name="tests.libs" value="junit.jar"/>
	<property name="tests.depend.libs" value="${tests.libs} ${com.arjuna.mwlabs.ts.modulename}.jar"/>

	<path id="com.arjuna.mwlabs.wsas.tests.lib.path">
	  <fileset dir="${com.arjuna.xts.ext}" includes="${tests.libs}"/>
	  <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>

	<!-- Initialisation -->
	<target name="com.arjuna.mwlabs.wsas.init">
		<!-- Define default build properties -->
		<tstamp>
			<format property="com.arjuna.mw.wsas.date" pattern="yyyy/mm/dd hh:mm aa"/>
		</tstamp>
		<!-- Compile with debugging? -->
		<condition property="com.arjuna.mwlabs.debug" value="no">
			<equals arg1="${com.arjuna.mw.debug}" arg2="no"/>
		</condition>
		<property name="com.arjuna.mwlabs.debug" value="yes"/>

		<!-- Compile with deprecation? -->
		<condition property="com.arjuna.mwlabs.deprecation" value="yes">
			<equals arg1="${com.arjuna.mw.deprecation}" arg2="yes"/>
		</condition>
		<property name="com.arjuna.mwlabs.deprecation" value="no"/>
		<!-- Make the destination directory -->
		<mkdir dir="${com.arjuna.mwlabs.wsas.dest}"/>
	</target>

	<!-- Define classpath builder task and add this JAR to the classpath -->
	<taskdef name="classpath-builder" classname="com.hp.mw.buildsystem.ant.ClasspathBuilder" classpathref="com.arjuna.buildsystem.classpath"/>

	<!-- Compilation targets -->
	<target name="com.arjuna.mw.wsas.compile"
	depends="com.arjuna.mwlabs.wsas.compile,
		com.arjuna.mw.wsas.htdocs, com.arjuna.mwlabs.wsas.generateresourcebundle"/>

	<target name="com.arjuna.mwlabs.wsas.compile" depends="com.arjuna.mwlabs.wsas.init">
		<echo message="Compiling module"/>
		<javac srcdir="${com.arjuna.mwlabs.wsas.src}" destdir="${com.arjuna.mwlabs.wsas.dest}"
               debug="${com.arjuna.mwlabs.debug}" deprecation="${com.arjuna.mwlabs.deprecation}"
		       classpathref = "com.arjuna.mwlabs.wsas.lib.classpath"/>
	</target>

	<!-- htdocs paths -->
	<path id="com.arjuna.mw.wsas.htdocs.path" path="${com.arjuna.mwlabs.wsas.src}"/>

	<!-- Build htdocs for just mw, or mw and mwlabs -->
	<property name="com.arjuna.mwlabs.wsas.htdocs.list" value="com.arjuna.mw.*"/>

	<!-- Jar targets -->
	<target name="com.arjuna.mw.wsas.jar" depends="com.arjuna.mw.wsas.compile">
		<echo message="Building jar file"/>
		<mkdir dir="${com.arjuna.mwlabs.wsas.jar.dest}"/>
		<jar jarfile="${com.arjuna.mwlabs.wsas.jar.dest}/${com.arjuna.mwlabs.ts.modulename}.jar" basedir="${com.arjuna.mwlabs.wsas.dest}"/>
	</target>

	<target name="com.arjuna.mw.wsas.htdocs"
				depends="com.arjuna.mwlabs.wsas.init">
		<echo message="Building htdocs "/>
		<mkdir dir="${com.arjuna.mwlabs.wsas.htdocs.dest}"/>
		<path id="com.arjuna.mwlabs.wsas.htdocs.path">
			<path refid="com.arjuna.mw.wsas.htdocs.path"/>
		</path>

		<javadoc
			sourcepathref="com.arjuna.mwlabs.wsas.htdocs.path"
			destdir="${com.arjuna.mwlabs.wsas.htdocs.dest}"
			packagenames="${com.arjuna.mwlabs.wsas.htdocs.list}"
	        >
			<classpath>
				<path refid="com.arjuna.mwlabs.wsas.lib.classpath"/>
				<path path="${com.arjuna.mwlabs.wsas.src}"/>
			</classpath>
		</javadoc>
	</target>

        <target name="com.arjuna.mwlabs.wsas.generateresourcebundle">

            <echo message="Generating WSAS Bundle"/>

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

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

                 <doclet name="com.hp.mw.buildsystem.doclet.resbundledoclet.ResourceBundleDoclet">
                    <path>
                        <pathelement path="${com.arjuna.buildsystem.classpath}"/>
                    </path>
                    <param name="-basedir" value="${basedir}/${com.arjuna.mwlabs.wsas.dest}"/>
                    <param name="-resourcebundle" value="${com.arjuna.mwlabs.wsas.resourcebundle}"/>
                 </doclet>
            </javadoc>

        </target>

	<!-- test targets -->
	<target name="com.arjuna.mwlabs.wsas.tests.init">
        <delete dir="${com.arjuna.mwlabs.wsas.tests.dest.root}"/>
		<!-- make the test destination directories -->
		<mkdir dir="${com.arjuna.mwlabs.wsas.tests.dest.root}"/>
		<mkdir dir="${com.arjuna.mwlabs.wsas.tests.dest}"/>
		<mkdir dir="${com.arjuna.mwlabs.wsas.tests.dd.dest}"/>
		<mkdir dir="${com.arjuna.mwlabs.wsas.tests.webapps.dest}"/>
		<mkdir dir="${com.arjuna.mwlabs.wsas.tests.jar.dest}"/>
	</target>

    <!-- this assumes the required libs have already been built -->
    
	<target name="com.arjuna.mwlabs.wsas.tests.compile" depends="com.arjuna.mwlabs.wsas.tests.init">
	  <javac destdir="${com.arjuna.mwlabs.wsas.tests.dest}" debug="yes" optimize="no">
	    <classpath>
	      <pathelement path="${com.arjuna.mwlabs.wsas.jar.dest}/${com.arjuna.mwlabs.ts.modulename}.jar"/>
	      <path refid="com.arjuna.mwlabs.wsas.tests.lib.path"/>
	      <path refid="com.arjuna.mwlabs.wsas.lib.classpath"/>
	    </classpath>
	    <src path="${com.arjuna.mwlabs.wsas.tests.src}"/>
	  </javac>
	</target>

	<target name="com.arjuna.mwlabs.wsas.tests.webapps" depends="com.arjuna.mwlabs.wsas.tests.compile">
	  <copy file="${com.arjuna.mwlabs.wsas.tests.dd}/wsas-tests_web-app.xml" tofile="${com.arjuna.mwlabs.wsas.tests.dd.dest}/web-app.xml">
	  </copy>
	  <war warfile="${com.arjuna.mwlabs.wsas.tests.webapps.dest}/wsas-tests.war" webxml="${com.arjuna.mwlabs.wsas.tests.dd.dest}/web-app.xml">
	    <classes dir="${com.arjuna.mwlabs.wsas.tests.dest}"/>
	  </war>
	  <ear earfile="${com.arjuna.mwlabs.wsas.tests.webapps.dest}/wsas-tests.ear" appxml="${com.arjuna.mwlabs.wsas.tests.dd}/wsas-tests_application.xml">
	    <!-- we only need to deploy the ext test libs (junit) and
	         the tests war in JBoss AS 5.0. the rest of the XTS
	         code is deployed as a sar and the TS code is deployed
	         in the server lib
	    -->
	    <fileset dir="${com.arjuna.xts.ext}" includes="${tests.libs}"/>
	    <fileset dir="${com.arjuna.mwlabs.wsas.tests.webapps.dest}" includes="wsas-tests.war"/>
	  </ear>
	</target>

	<target name="com.arjuna.mwlabs.wsas.tests.deploy" depends="com.arjuna.mwlabs.wsas.tests.webapps, com.arjuna.mwlabs.wsas.tests.undeploy">
	  <copy file="${com.arjuna.mwlabs.wsas.tests.webapps.dest}/wsas-tests.ear" tofile="${deploy.dir}/wsas-tests.ear"/>
	</target>

	<target name="com.arjuna.mwlabs.wsas.tests.undeploy">
	  <delete file="${deploy.dir}/wsas-tests.ear"/>
	</target>

	<!-- Clean targets -->
	<target name="com.arjuna.mw.wsas.clean">
		<echo message="Cleaning module"/>
		<delete dir="${com.arjuna.mwlabs.wsas.dest}"/>
		<delete dir="${com.arjuna.mwlabs.wsas.dest.root}"/>
		<delete dir="${com.arjuna.mwlabs.wsas.htdocs.dest}"/>
		<delete file="${com.arjuna.mwlabs.wsas.jar.dest}/${com.arjuna.mwlabs.ts.modulename}.jar"/>
		<delete file="${com.arjuna.mwlabs.wsas.info.dest}"/>
		<!-- delete the test destination directories -->
		<delete dir="${com.arjuna.mwlabs.wsas.tests.dest.root}"/>
	</target>

	<!-- Short target names -->
	<target name="compile" depends="com.arjuna.mw.wsas.compile"/>
	<target name="jar" depends="com.arjuna.mw.wsas.jar"/>
	<target name="clean" depends="com.arjuna.mw.wsas.clean"/>
	<target name="tests-webapps" depends="com.arjuna.mwlabs.wsas.tests.webapps"/>
	<!-- production target for 1.1 tests - tests are not version specific -->
    <target name="tests-11" depends="tests-webapps"/>
    <target name="tests-both" depends="tests-webapps"/>
	<target name="tests-deploy" depends="com.arjuna.mwlabs.wsas.tests.deploy"/>
	<target name="tests-undeploy" depends="com.arjuna.mwlabs.wsas.tests.undeploy"/>
</project>
