<?xml version="1.0" encoding="UTF-8"?>
<!--
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - EasyBeans
 - Copyright (C) 2006-2007 Bull S.A.S.
 - Contact: easybeans@objectweb.org
 -
 - This library is free software; you can redistribute it and/or
 - modify it under the terms of the GNU Lesser General Public
 - License as published by the Free Software Foundation; either
 - version 2.1 of the License, or any later version.
 -
 - This library is distributed in the hope that it will be useful,
 - but WITHOUT ANY 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 along with this library; if not, write to the Free Software
 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 - USA
 -
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - $Id: jonas-common.xml 12737 2008-01-29 16:10:59Z durieuxp $
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -->

<project xmlns:easybeans="http://easybeans.ow2.org"
         name="EasyBeans - Common rules for JOnAS server"
         basedir=".">

  <!-- build.properties hold the properties that can be customized -->
  <property file="build.properties" />

  <!-- some properties are build from environment variables -->
  <property environment="myenv" />
  <property name="jonas.root" value="${myenv.JONAS_ROOT}" />

  <property name="javac.debug" value="on" />
  <property name="javac.optimize" value="off" />
  <property name="javac.deprecation" value="off" />
  <property name="javac.verbose" value="off" />
  <property name="javac.compiler" value="modern" />
  <property name="javac.nowarn" value="off" />

  <!-- Set the uncustomizable properties -->
  <property name="lib.dir" value="${jonas.root}/lib" />
  <property name="src.dir" value="src/java" />
  <property name="resources.dir" value="etc" />
  <property name="examples.classes.dir" value="../../classes" />
  <property name="rar.classes.dir" value="../../classes.rar" />
  <condition property="jonas.base" value="${myenv.JONAS_BASE}">
    <available file="${myenv.JONAS_BASE}" />
  </condition>
  <condition property="jonas.base" value="${jonas.root}">
    <available file="${jonas.root}" />
  </condition>

  <!-- Unpack the rar file from JONAS_BASE/rars or JONAS_BASE/rars/autoload -->
  <unjar dest="${rar.classes.dir}">
    <fileset dir="${jonas.base}">
      <include name="rars/*easybeans-rar_for_jonas*.rar" />
      <include name="rars/autoload/*easybeans-rar_for_jonas*.rar" />
    </fileset>
  </unjar>


  <!-- The classpath to be used to compile examples -->
  <path id="base.classpath">
    <pathelement location="${jonas.base}/conf" />
    <fileset dir="${lib.dir}">
      <include name="commons/**/*.jar" />
    </fileset>
    <fileset dir="${lib.dir}">
      <!-- In that bundle we have the @OSGiResource -->
      <include name="bundles/easybeans-*.jar" />
      <include name="bundles/javaee-api-*.jar" />
      <include name="common/easybeans-ant-tasks.jar"/>
      <include name="bootstrap/felix-launcher.jar"/>
    </fileset>
  </path>

  <!-- Set the properties -->
  <property name="dist.clients.dir" value="${jonas.base}/clients" />
  <property name="dist.deploy.dir" value="${jonas.base}/deploy" />
  <property name="dist.webapps.dir" value="${jonas.base}/webapps" />
  <!-- EJB go in deploy directory -->
  <property name="ejb.dir" value="${dist.deploy.dir}" />
  <!-- WAR go in webapps directory in standalone mode-->
  <property name="war.dir" value="${dist.webapps.dir}" />
  <!-- Client go in clients directory in standalone mode-->
  <property name="client.dir" value="${dist.clients.dir}" />
  <!-- EAR go in deploy directory in standalone mode-->
  <property name="ear.dir" value="${dist.deploy.dir}" />


  <target name="clean">
    <!-- directories removal -->
    <delete dir="${examples.classes.dir}" />
    <delete dir="${rar.classes.dir}" />
  </target>

  <!-- Below is the XML shared between EasyBeans standalone/JOnAS/Jetty/Tomcat -->

  <target name="init">
    <!-- directories building -->
    <mkdir dir="${examples.classes.dir}" />
    <mkdir dir="${dist.clients.dir}" />
    <mkdir dir="${dist.deploy.dir}" />
    <mkdir dir="${dist.webapps.dir}" />

    <!-- Set the war.dd.file property to 'empty-value' if not set -->
    <condition property="war.dd.file" value="${war.dd}">
      <available file="${war.dd}" />
    </condition>
    <condition property="war.dd.file" value="empty-value">
      <not>
        <available file="${war.dd}" />
      </not>
    </condition>

    <!-- Set the ejb.persistence.dd.file property to 'empty-value' if not set -->
    <condition property="ejb.persistence.dd.file" value="${ejb.persistence.dd}">
      <available file="${ejb.persistence.dd}" />
    </condition>
    <condition property="ejb.persistence.dd.file" value="empty-value">
      <not>
        <available file="${ejb.persistence.dd}" />
      </not>
    </condition>

    <!-- Ant tasks provided by EasyBeans -->
    <typedef resource="org/ow2/easybeans/ant/antlib.xml"
             uri="http://easybeans.ow2.org">
      <classpath refid="base.classpath" />
    </typedef>
  </target>

  <target name="compile" description="Compile classes" depends="init">
    <javac srcdir="${src.dir}"
           destdir="${examples.classes.dir}"
           debug="${javac.debug}"
           deprecation="${javac.deprecation}"
           optimize="${javac.optimize}"
           verbose="${javac.verbose}"
           compiler="${javac.compiler}"
           nowarn="${javac.nowarn}">
      <classpath refid="base.classpath" />
    </javac>
  </target>

  <!-- Generate an EJB jar file if it is not included in an EAR -->
  <target name="ejb-standalone" unless="ear.name">
    <easybeans:ejb exploded="${archives.exploded}"
                   dest="${ejb.dir}/${ejb.name}.jar"
                   persistencedd="${ejb.persistence.dd.file}">
      <fileset dir="${examples.classes.dir}">
        <patternset refid="ejb.patternset" />
      </fileset>
    </easybeans:ejb>
  </target>

  <target name="ejb" if="ejb.name">
    <antcall target="ejb-standalone" />
  </target>

  <!-- Generate a war file if it is not included in an EAR -->
  <target name="war-standalone" unless="ear.name">
    <easybeans:war exploded="${archives.exploded}"
                   dest="${war.dir}/${war.name}.war"
                   dd="${war.dd.file}">
      <classes dir="${examples.classes.dir}">
        <patternset refid="war.patternset" />
      </classes>
    </easybeans:war>
  </target>

  <target name="war" if="war.name">
    <antcall target="war-standalone" />
  </target>

  <!-- Generate a client jar file (which don't go in client container) -->
  <target name="client-standalone">
    <easybeans:client dest="${client.dir}/${client.name}.jar"
                      mainclass="${client.main.class}">
      <fileset dir="${examples.classes.dir}">
        <patternset refid="client.patternset" />
      </fileset>
    </easybeans:client>
  </target>

  <target name="client" if="client.name">
    <antcall target="client-standalone" />
  </target>

  <!-- Generate an EAR if it is selected -->
  <target name="ear" if="ear.name">
    <easybeans:ear exploded="${archives.exploded}"
                   dest="${ear.dir}/${ear.name}.ear">
      <ejb dest="${ejb.name}.jar" persistencedd="${ejb.persistence.dd.file}">
        <fileset dir="${examples.classes.dir}">
          <patternset refid="ejb.patternset" />
        </fileset>
      </ejb>
      <war dest="${war.name}.war" dd="${war.dd.file}">
        <classes dir="${examples.classes.dir}">
          <patternset refid="war.patternset" />
        </classes>
      </war>
    </easybeans:ear>
  </target>


  <target name="run.client" description="Launch client">
    <java fork="true" classname="${client.main.class}">
      <!--  <jvmarg line="-Xint -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=4142,suspend=y"/>  -->
      <classpath path="${examples.classes.dir}" />
      <classpath refid="base.classpath" />
      <classpath path="${client.dir}/${client.name}.jar" />
    </java>
  </target>


  <!-- Install example -->
  <target name="install"
          depends="init, compile, ejb, war, ear, client"
          description="Install this example in a deployable directory">
  </target>

</project>
