<?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-jb.xml 20342 2010-09-17 12:34:43Z pelletib $
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 -->

<!--
 -  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>

  <target name="define_jdbcxml_values">
    <!-- init values for default jdbcXml -->
    <jant:property name="xmljdbc.name" value="xmljdbc.${db.name}.name" />
    <jant:property name="xmljdbc.username" value="xmljdbc.${db.name}.username" />
    <jant:property name="xmljdbc.password" value="xmljdbc.${db.name}.password" />
    <jant:property name="xmljdbc.url" value="xmljdbc.${db.name}.url" />
    <jant:property name="xmljdbc.mapper" value="xmljdbc.${db.name}.mapper" />
    <jant:property name="xmljdbc.classname" value="xmljdbc.${db.name}.classname" />
    <jant:property name="xmljdbc.initconpool" value="xmljdbc.${db.name}.initconpool" defaultValue="10" />
    <jant:property name="xmljdbc.minconpool" value="xmljdbc.${db.name}.minconpool" defaultValue="10" />
    <jant:property name="xmljdbc.maxconpool" value="xmljdbc.${db.name}.maxconpool" defaultValue="100" />
    <jant:property name="xmljdbc.maxopentime" value="xmljdbc.${db.name}.maxopentime" defaultValue="60" />
    <jant:property name="xmljdbc.maxwaiters" value="xmljdbc.${db.name}.maxwaiters" defaultValue="100" />
    <jant:property name="xmljdbc.maxwaitingtime" value="xmljdbc.${db.name}.maxwaitingtime" defaultValue="5" />
    <jant:property name="xmljdbc.pstmtmax" value="xmljdbc.${db.name}.pstmtmax" defaultValue="100" />
    <jant:property name="xmljdbc.samplingperiod" value="xmljdbc.${db.name}.samplingperiod" defaultValue="30" />
    <jant:property name="xmljdbc.connmaxage" value="xmljdbc.${db.name}.connmaxage" defaultValue="1440" />
    <jant:property name="xmljdbc.conchecklevel" value="xmljdbc.${db.name}.conchecklevel" defaultValue="0" />
    <jant:property name="xmljdbc.conteststmt" value="xmljdbc.${db.name}.conteststmt" defaultValue="" />

  </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,define_jdbcxml_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}" />
              -->

      <jdbcXml name="${xmljdbc.name}" mapper="${xmljdbc.hsql.mapper}" username="${xmljdbc.username}" password="${xmljdbc.password}" url="${xmljdbc.url}" className="${xmljdbc.classname}" initConPool="${xmljdbc.initconpool}" minConPool="${xmljdbc.minconpool}" maxConPool="${xmljdbc.maxconpool}" maxWaiters="${xmljdbc.maxwaiters}" maxWaitTime="${xmljdbc.maxwaitingtime}" pstmtMax="${xmljdbc.pstmtmax}" samplingPeriod="${xmljdbc.samplingperiod}" maxOpenTime="${xmljdbc.maxopentime}" connMaxAge="${xmljdbc.connmaxage}" conTestStmt="${xmljdbc.conteststmt}" conCheckLevel="${xmljdbc.conchecklevel}" newFile="true" />
      <jdbcXml name="jdbc_xa1" mapper="${xmljdbc.hsql.mapper}" username="${xmljdbc.username}" password="${xmljdbc.password}" url="${xmljdbc.url}" className="${xmljdbc.classname}" initConPool="${xmljdbc.initconpool}" minConPool="${xmljdbc.minconpool}" maxConPool="${xmljdbc.maxconpool}" maxWaiters="${xmljdbc.maxwaiters}" maxWaitTime="${xmljdbc.maxwaitingtime}" pstmtMax="${xmljdbc.pstmtmax}" samplingPeriod="${xmljdbc.samplingperiod}" maxOpenTime="${xmljdbc.maxopentime}" connMaxAge="${xmljdbc.connmaxage}" conTestStmt="${xmljdbc.conteststmt}" conCheckLevel="${xmljdbc.conchecklevel}" newFile="false" />
      <jdbcXml name="jdbc_xa2" mapper="${xmljdbc.hsql.mapper}" username="${xmljdbc.username}" password="${xmljdbc.password}" url="${xmljdbc.url}" className="${xmljdbc.classname}" initConPool="${xmljdbc.initconpool}" minConPool="${xmljdbc.minconpool}" maxConPool="${xmljdbc.maxconpool}" maxWaiters="${xmljdbc.maxwaiters}" maxWaitTime="${xmljdbc.maxwaitingtime}" pstmtMax="${xmljdbc.pstmtmax}" samplingPeriod="${xmljdbc.samplingperiod}" maxOpenTime="${xmljdbc.maxopentime}" connMaxAge="${xmljdbc.connmaxage}" conTestStmt="${xmljdbc.conteststmt}" conCheckLevel="${xmljdbc.conchecklevel}" newFile="false" />

      <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>
