<?xml version="1.0" encoding="UTF-8"?>
<!--
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - JOnAS: Java(TM) Open Application Server
 - Copyright (C) 2005-2007 Bull S.A.S.
 - Contact: jonas-team@ow2.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
 -
 - Initial developer(s): Florent BENOIT
 -
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - $Id: build-jb.xml 12730 2008-01-28 13:48:29Z sauthieg $
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -->

<!--
 -  build.xml file for creating a new JOnAS_BASE
 -->

<project name="JOnAS_BASE tools"
         default="create_jonas_base"
         basedir="."
         xmlns:jant="http://jonas.objectweb.org/ant">

  <!-- Define some properties -->
  <target name="init">

    <!-- properties -->
    <property environment="myenv" />
    <property name="jonas.root" value="${myenv.JONAS_ROOT}" />
    <property name="jonas.base" value="${myenv.JONAS_BASE}" />

    <!-- tasks classpath="${jonas.root}/lib/common/ow_jonas_ant.jar" -->

    <typedef resource="org/ow2/jonas/ant/antlib.xml"
             classpath="lib/common/ow_jonas_ant.jar"
             uri="http://jonas.objectweb.org/ant" />

    <!-- Define directories -->
    <property name="conf.dir" value="${user.home}/jb.config/conf" />

    <!-- Load user properties -->
    <property file="${conf.dir}/jonas-newjb.properties" />
    <property file="./build-jb.properties" />

    <!-- If not define in user properties -->
    <property name="drivers.dir" value="${user.home}/jb.config/lib" />

    <condition property="my-drivers.dir" value="${user.home}/${drivers.dir}">
      <not>
        <available file="${drivers.dir}" type="dir" />
      </not>
    </condition>
    <condition property="my-drivers.dir" value="${drivers.dir}">
      <not>
        <available file="${drivers.dir}" type="dir" />
      </not>
    </condition>

    <available file="${my-drivers.dir}"
               type="dir"
               property="drivers.dir.present"
               value="true" />
    <fail unless="drivers.dir.present"
          message="drivers.dir ${drivers.dir} doesn't exist" />

  </target>

  <target name="define_jdbcra_values">
    <!-- init values for default jdbcRa -->
    <property name="db.name" value="${rajdbc.name}" />
    <jant:property name="rajdbc.user" value="rajdbc.${db.name}.user" />
    <jant:property name="rajdbc.password" value="rajdbc.${db.name}.password" />
    <jant:property name="rajdbc.url" value="rajdbc.${db.name}.url" />
    <jant:property name="rajdbc.drivername" value="rajdbc.${db.name}.drivername" />
    <jant:property name="rajdbc.jndiname" value="rajdbc.${db.name}.jndiname" />
    <jant:property name="rajdbc.maxpoolsize"
               value="rajdbc.${db.name}.maxpoolsize"
               defaultValue="100" />
    <jant:property name="rajdbc.jdbcdriverjarfile"
               value="rajdbc.${db.name}.jdbcdriverjarfile" />
    <jant:property name="rajdbc.mappername" value="rajdbc.${db.name}.mappername" />
    <jant:property name="rajdbc.url" value="rajdbc.${db.name}.url" />
    <!-- init the rajdbc.p6spy if it's not already done -->
    <property name="rajdbc.p6spy" value="off" />
  </target>

  <!-- New JOnAS Base-->
  <target name="create_jonas_base"
          depends="init"
          description="Create a new JOnAS Base">

    <input message="Choose your protocol : [default : ${carol.defaultprotocol}] :"
           validargs="jrmp,iiop,irmi,"
           addproperty="carol.protocol"
           defaultvalue="${carol.defaultprotocol}" />

    <input message="Choose your database : [default : ${rajdbc.defaultname}] :"
           addproperty="rajdbc.name"
           defaultvalue="${rajdbc.defaultname}" />

    <input message="Choose your WebContainer : [default : ${webcontainer.service.defaultname}] :"
           validargs="jetty,tomcat,"
           addproperty="webcontainer.service.name"
           defaultvalue="${webcontainer.service.defaultname}" />
    <antcall target="internal_create_jonas_base" />

  </target>



  <!-- Internal creation of new JOnAS Base-->
  <target name="internal_create_jonas_base" depends="init,define_jdbcra_values">
    <echo message="JONAS_ROOT = ${jonas.root} and JONAS_BASE = ${jonas.base} " />

    <jant:jonasbase jonasRoot="${jonas.root}" destDir="${jonas.base}" update="off">
      <jonasProperties services="${jonas.services}"
           securityManager="${jonas.security.manager}"
           securityPropagation="${jonas.security.propagation}"
           csiv2Propagation="${jonas.csiv2.propagation}"
           transactionPropagation="${jonas.transaction.propagation}"
           configfile="${jonas.log.configfile}" />
      <jms port="${jms.port}"
           initialTopics="${jms.topics}"
           initialQueues="${jms.queues}" />
      <carol defaultPort="${carol.allport}"
             protocols="${carol.protocol}"
             jrmpOptimization="${carol.jrmpopt}"
               localRegistry="${carol.localregistry}"/>
      <!-- @name is optionnal, if there is only a <tomcat> inner element, tomcat service will be choosed -->
      <!-- @port is optionnal, if set it will affect both jetty6.xml and tomcat6-server.xml.
           If not set, the (tomcat|jetty)/http[@port] value is used -->
      <webcontainer name="${webcontainer.service.name}">
        <tomcat>
          <!-- Simply configure a HTTP/1.1 Connector : just set the port to use -->
          <http port="${webcontainer.port}" />
          <!-- Simply configure a Director Connector : just set the port to use
          <director port="1234" />
          -->
          <!-- Simply configure a AJP/1.3 Connector : just set the port to use
          <ajp port="2345" />
          -->
          <!-- Simply configure a HTTPS Connector : just set the port to use, the keystore and its password
          <https port="12345" keystoreFile="/path/to/your/keystore" keystorePass="changeit"/>
          -->
          <!-- Simply add a <Cluster> node into the <Host>
          <cluster listenPort="7777" mcastAddr="222.222.222.222" mcastPort="11111" />
          -->
        </tomcat>
        <jetty>
          <!-- Jetty doesn't support director and cluster sub tasks -->
          <http port="${webcontainer.port}" />
          <!--
          <ajp port="4567" />
          -->
          <!-- https for Jetty supports 2 more attributes @vm=(ibm|sun) and @keyPassword
          <https port="12345" keystoreFile="/path/to/your/keystore"
                 keystorePass="changeit" vm="sun" keyPassword="my.key.password"/>
          -->
        </jetty>
      </webcontainer>
      <db port="${db.port}" />
      <discovery sourcePort="${discovery.sourceport}"
                 greetingPort="${discovery.greetingport}"
                 mcastAddr="${discovery.mcastaddr}"
                 mcastPort="${discovery.mcastport}"
             ttl="${discovery.ttl}" />
      <jdbcRa name="db_access_jdbc1"
              mapperName="${rajdbc.mappername}"
              user="${rajdbc.user}"
              password="${rajdbc.password}"
              url="${rajdbc.url}"
              driverName="${rajdbc.drivername}"
              maxPoolSize="${rajdbc.maxpoolsize}"
              jndiName="${rajdbc.jndiname}"
              autoload="on"
              p6spy="${rajdbc.p6spy}" />
      <jdbcRa name="db_access_jdbc_xa1"
              mapperName="${rajdbc.mappername}"
              user="${rajdbc.user}"
              password="${rajdbc.password}"
              url="${rajdbc.url}"
              driverName="${rajdbc.drivername}"
              maxPoolSize="${rajdbc.maxpoolsize}"
              jndiName="jdbc_xa1"
              autoload="on"
              p6spy="${rajdbc.p6spy}" />
      <jdbcRa name="db_access_jdbc_xa2"
              mapperName="${rajdbc.mappername}"
              user="${rajdbc.user}"
              password="${rajdbc.password}"
              url="${rajdbc.url}"
              driverName="${rajdbc.drivername}"
              maxPoolSize="${rajdbc.maxpoolsize}"
              jndiName="jdbc_xa2"
              autoload="on"
              p6spy="${rajdbc.p6spy}" />
      <mail type="Session" name="${mail.session.name}" />
      <mail type="MimePartDataSource"
            name="${mail.mimepartds.name}"
            mailTo="${mail.to}"
            subject="${mail.subject}"
          host= "${mail.host}"/>
      <dbm dataSources="${rajdbc.name}" />
      <wsdlPublish>
        <!--
           <uddi name="juddi" username="jonas" password="jonas"
        orgName="ObjectWeb" orgPersonName="JOnAS"
        orgDesc="ObjectWeb Consortium (http://www.objectweb.org)"
        lifecyclemanagerURL="http://localhost:${webcontainer.port}/juddi/publish" queryManagerURL="http://localhost:${webcontainer.port}/juddi/inquiry" />-->
        <!-- encoding default = UTF-8 -->
        <file name="${wsdl.file.name}"
              dir="${wsdl.file.dir}"
              encoding="ISO-8859-1" />
      </wsdlPublish>
      <lib>
        <fileset dir="${my-drivers.dir}">
          <include name="${rajdbc.jdbcdriverjarfile}" />
        </fileset>
      </lib>

    </jant:jonasbase>
  </target>

</project>
