<?xml version="1.0" encoding="UTF-8"?>
<!--
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 - JOnAS: Java(TM) Open Application Server
 - Copyright (C) 2005-2009 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.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="${jonas.root}/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" />

  </target>
  
  <!-- jonas_base control -->
  <target name="init_jonasbase">
  <input message="Choose your jonas_base : [default : ${myenv.JONAS_BASE}] :"
           addproperty="jonas.base"
           defaultvalue="${myenv.JONAS_BASE}" />
  </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" />
    <!-- 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, init_jonasbase"
          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="tomcat,jetty,"
           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}"
                       master="${jonas.master}"
                       development="${jonas.development}"	/>
      <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}"
                    ondemandenabled="${webcontainer.ondemandenabled}"
                    ondemandredirectPort="${webcontainer.ondemanderedirectport}" >
        <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="${user.home}/${drivers.dir}">
          <include name="${rajdbc.jdbcdriverjarfile}" />
        </fileset>
      </lib>

    </jant:jonasbase>
  </target>
  
  <!-- Cluster daemon instance creation -->

  <target name="create_jonas_clusterDaemon"
          depends="init, init_jonasbase"
          description="Create a new JOnAS ClusterDaemon Configuration">
    <echo message=" Creating JONAS cluster daemon in the directory ${jonas.base} " />

    <jant:newjc jonasRoot="${jonas.root}"
                destDirPrefix=""
                update="off"
                cdDir="${jonas.base}">
      <clusterDaemon domainName="${discovery.domainName}"
                     cdDir="${jonas.base}"
                     protocol="${cluster.daemon.protocol}"
                     port="${cluster.daemon.port}"
                     interactionMode="${cluster.daemon.interactionMode}" />
    </jant:newjc>

    <!-- clean the cluster daemon configuration -->
    <delete includeemptydirs="true">
      <fileset dir="${jonas.base}/conf" excludes="carol.properties trace.properties clusterd.xml jgroups-discovery.xml" />
    </delete>
    <delete dir="${jonas.base}/deploy" failonerror="true" />
    <delete dir="${jonas.base}/lib" failonerror="true" />
    <touch file="${jonas.base}/conf/jonas.properties" />
  </target>

</project>
