<!--
 - Licensed to the Apache Software Foundation (ASF) under one
 - or more contributor license agreements.  See the NOTICE file
 - distributed with this work for additional information
 - regarding copyright ownership.  The ASF licenses this file
 - to you under the Apache License, Version 2.0 (the
 - "License"); you may not use this file except in compliance
 - with the License.  You may obtain a copy of the License at
 -
 -   http://www.apache.org/licenses/LICENSE-2.0
 -
 - Unless required by applicable law or agreed to in writing,
 - software distributed under the License is distributed on an
 - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 - KIND, either express or implied.  See the License for the
 - specific language governing permissions and limitations
 - under the License.
 -->
<project name="bdbstore" xmlns:ivy="antlib:org.apache.ivy.ant" default="build">
    <property name="module.depends" value="common broker" />
    <property name="module.test.depends" value="client common/tests broker/tests management/common systests broker-plugins/management-jmx" />
    <property name="module.genpom" value="true"/>

    <import file="../module.xml" />

    <condition property="download.bdb.jar">
      <or>
        <istrue value="${download-bdb}"/>
        <istrue value="${optional.dependencies}"/>
        <istrue value="${optional}"/>
      </or>
    </condition>

    <!--check whether the BDB jar is present, possibly after download-->
    <target name="check-bdb-jar">
        <available file="${project.root}/${bdb-je}" type="file" property="bdb.jar.available"/>
    </target>

    <!--echo that BDB is required if it isnt present, with associated licencing note-->
    <target name="bdb-jar-required" depends="bdb-licence-note-optional" unless="bdb.jar.available">
       <echo>The BDB JE library is required to use this optional module.

The jar file may be downloaded by either:

   Seperately running the following command from the qpid/java/bdbstore dir: ant download-bdb

   OR

   Adding -Ddownload-bdb=true to your regular build command.</echo>
        <fail>The BDB JE library was not found</fail>
    </target>

    <!--issue BDB licencing note if BDB isnt already present-->
    <target name="bdb-licence-note-optional" depends="check-bdb-jar" unless="bdb.jar.available">
        <antcall target="bdb-licence-note"/>
    </target>

    <!--issue BDB licencing note-->
    <target name="bdb-licence-note">
       <echo>*NOTE* The BDB JE library required by this optional module is licensed under the Sleepycat Licence, which is not compatible with the Apache Licence v2.0.

For a copy of the Sleepycat Licence, please see:
http://www.oracle.com/technetwork/database/berkeleydb/downloads/jeoslicense-086837.html</echo>
    </target>

    <!--check if an inline BDB download was requested with the build-->
    <target name="check-request-props" if="download.bdb.jar">
        <antcall target="download-bdb"/>
    </target>

    <!--download BDB, with licencing note-->
    <target name="download-bdb" depends="bdb-licence-note, load-ivy, configure-ivy" unless="${ivy.dont.retrieve}">
      <echo message="Resolving and retrieving dependencies..."/>
      <ivy:resolve type="jar,bundle" file="${project.root}/ivy.retrieve.xml" conf="bdbje"/>
      <ivy:retrieve type="jar,bundle" conf="bdbje" sync="true"
          pattern="${project.root}/lib/bdbstore/[artifact]-[revision].[ext]" />
    </target>

    <target name="build" depends="check-request-props, bdb-jar-required, module.build" />

</project>
