<!--
========================================================================
 Copyright (c) 1999 Mort Bay Consulting (Australia) Pty. Ltd.
 $Id: build.xml,v 1.13 2005/12/06 01:16:44 gregwilkins Exp $
========================================================================

targets:

clean       - Remove all generated files.
tidy        - Remove unneeded generated files.
prepare     - Set up build directory structure.
classes     - compile the classes
j2ee.jar    - Builds the j2ee jar.
demo        - Runs the demo web application.
all         - everything

-->

<!--

 Currently only builds against JBoss - you will need to set
 -Djboss.home on the command line...

-->
<project name="J2EE Integration" default="all" basedir=".">

  <property name="package"          value="j2ee" />
  <property environment="env"/>
  <property file="../../ant.properties" />
  <property file="../build.package.properties" />
  <property file="jboss.properties" />

  <property name="j2ee.etc"       value="${basedir}/etc"/>
  <property name="generated.src"  value="${basedir}/gensrc"/>
  <property name="mortbay.j2ee.jar" value="${lib}/org.mortbay.j2ee.jar"/>
  <property name="org.jboss.jetty.jar" value="${lib}/org.jboss.jetty.jar"/>
  <property name="jboss.jetty.sar" value="${basedir}/jetty-${RELEASE.MAJOR.MINOR}-jboss-${jboss.version}.sar"/>
  <property name="jboss.jetty.deploy.dir" value="${jboss.home}/server/default/deploy/jboss-jetty.sar"/>

  <path id="jboss.classpath">
    <pathelement location="${jboss.home}/client/jboss-j2ee.jar"/>
    <pathelement location="${jboss.home}/client/log4j.jar"/>
    <pathelement location="${jboss.home}/lib/jboss-common.jar"/>
    <pathelement location="${jboss.home}/lib/jboss-system.jar"/>
    <pathelement location="${jboss.home}/lib/jboss-jmx.jar"/>
    <pathelement location="${jboss.home}/server/all/lib/jboss.jar"/>
    <pathelement location="${jboss.home}/server/all/lib/jbosssx.jar"/>
    <pathelement location="${jboss.home}/server/all/lib/jbossha.jar"/>
    <pathelement location="${jboss.home}/server/all/lib/jgroups.jar"/> 
    <pathelement location="${jboss.home}/server/all/deploy/jbossha-httpsession.sar"/> 
  </path>


  <!-- add other appserver integration classpaths here -->

  <path id="j2ee.classpath"> <!-- clumsy but - should work - I hate ant -->
    <pathelement location="${classes}"/>
    <pathelement location="${servlet.jar}"/>
    <pathelement location="${jetty.jar}"/>
    <pathelement location="${mortbay.jmx.jar}"/>
    <pathelement location="${ext}/javax77.jar"/>
    <pathelement location="${lib}/org.mortbay.jsr77.jar"/>
    <pathelement location="${jetty.ext}/commons-logging.jar"/>
    <path refid="jboss.classpath"/>
  </path>

  <path id="xdoclet.classpath"> 
    <path refid="j2ee.classpath"/>
    <fileset dir="${xdoclet.home}/lib">
      <include name="**/*.jar"/>
    </fileset>
  </path>


<!--=========================================================================-->
  <target name="jsr77">
    <ant dir="../jsr77" inheritAll="false"/>
    <available property="jsr77.available" file="../lib/org.mortbay.jsr77.jar"/>
    <fail unless="jsr77.available" message="Build extra/jsr77 subproject failed"/>
  </target>


  <target name="prepare" depends="jsr77">
    <mkdir dir="${lib}" />
    <mkdir dir="${classes}" />
    <mkdir dir="${generated.src}" />

    <taskdef
     name="jmxdoclet"
     classname="xdoclet.modules.jmx.JMXDocletTask"
     classpathref="xdoclet.classpath"/>

    <taskdef
     name="ejbdoclet"
     classname="xdoclet.modules.ejb.EjbDocletTask"
     classpathref="xdoclet.classpath"/>

  </target>

  <target name="tidy" >
    <delete dir="${classes}"/>
    <delete dir="${generated.src}"/>
  </target>

  <target name="clean" depends="tidy">
    <delete file="${mortbay.j2ee.jar}"/>
    <delete file="${org.jboss.jetty.jar}"/>
    <delete file="${org.jboss.sar}"/>
    <delete includeEmptyDirs="true" quiet="true">
      <fileset dir="${basedir}">
        <include name="*.sar"/>
      </fileset>
    </delete>
  </target>

<!--=========================================================================-->


<!--=========================================================================-->
  <target name="classes" depends="prepare">

    <jmxdoclet
     destdir="${generated.src}"
     excludedtags="@version,@author,@todo">
      <fileset dir="${src}">
       <include name="**/*Service.java"/>
      </fileset>
      <mbeaninterface mergedir="${j2ee.etc}/templates"/>
    </jmxdoclet>


    <copy todir="${classes}">
      <fileset dir="${src}">
        <include name="**/defaultManifest.mf" />
        <include name="**/*.properties" />
        <include name="**/*.dtd" />
      </fileset>
    </copy>

    <javac destdir="${classes}"
           classpathref="j2ee.classpath"
           debug="on"
           optimize="off"
           deprecation="off"
           >
       <src path="${src}"/>
       <src path="${generated.src}"/>

       <include name="**/*.java"/>
       <exclude name="org/mortbay/j2ee/**/test/**"/>
       <exclude name="org/mortbay/j2ee/session/**/CMP*.java"/>
       <exclude name="org/mortbay/j2ee/session/**/CMR*.java"/>
    </javac>
  </target>

  <target name="j2ee.jar" depends="classes">
    <jar jarfile="${mortbay.j2ee.jar}" basedir="${classes}" >
       <include name="org/mortbay/**"  />
       <exclude name="org/mortbay/**/test/**" />
    </jar>
  </target>

  <target name="jboss.jetty.jar" depends="classes">
    <jar jarfile="${org.jboss.jetty.jar}" basedir="${classes}" >
       <include name="org/jboss/**"  />
       <exclude name="org/jboss/**/test/**" />
    </jar>
  </target>


  <target name="jboss.jetty.sar" depends="jboss.jetty.jar,j2ee.jar">

    <jar jarfile="${jboss.jetty.sar}">
      <metainf dir="${j2ee.etc}">
        <include name="jboss-service.xml"/>
      </metainf>
      <fileset dir="${lib}">   
        <include name="org.jboss.jetty.jar"/>
        <include name="org.mortbay.j2ee.jar"/>
	<include name="org.mortbay.jsr77.jar"/>
      </fileset>
      <fileset dir="${jetty.lib}">   
        <include name="org.mortbay.jetty.jar"/>
        <include name="org.mortbay.jmx.jar"/>
        <include name="javax.servlet.jar"/>
      </fileset>
      <fileset dir="${jetty.ext}">   
        <include name="jasper-*.jar"/>
        <include name="ant*.jar"/>
        <include name="commons-logging.jar"/>
        <include name="commons-el.jar"/>
      </fileset>
      <fileset dir="${jetty.etc}">   
        <include name="webdefault.xml"/>
      </fileset>
    </jar>
  </target>

  <target name="deploy" depends="jboss.jetty.sar">
    <mkdir dir="${jboss.jetty.deploy.dir}" />
    <unjar src="${jboss.jetty.sar}" dest="${jboss.jetty.deploy.dir}"/>
  </target>

  <target name="test" depends="classes" >
    <java classname="org.mortbay.j2ee.TestHarness"
          classpath="${classes}:${classpath}"
          fork="yes"
          failonerror="yes"
          >
    </java>
    <java classname="org.mortbay.servlets.packageindex.PackageVersionOrdererTest"
          classpath="${classes}:${classpath}"
          fork="yes"
          failonerror="yes"
          >
      <!--jvmarg line="-DDEBUG"/-->
    </java>
  </target>

  <target name="run" depends="classes" >
    <java classname="org.mortbay.jetty.Server"
          fork="yes"
          failonerror="yes"
          classpath="${classes}:${classpath};${rtclasspath}"
          >
      <!--jvmarg line="-DDEBUG_PATTERNS=HttpConnection.handle,i3sp,ServletHandler.handle -DDEBUG=yes -DDEBUG_VERBOSE=9999 -DLOG_OPTIONS=tsTL -Djetty.home=. -Djetty.log=." /-->
      <jvmarg line="-DDEBUG=yes -DDEBUG_VERBOSE=9999 -DLOG_OPTIONS=tsTL -Djetty.home=. -Djetty.log=." />
      <arg line="src/org/mortbay/servlets/packageindex/JettyServer.xml" />
    </java>
  </target>
  <target name="all" depends="j2ee.jar,jboss.jetty.jar,jboss.jetty.sar"/>

</project>

