<!--
 - 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="visualisation-jfc" xmlns:ivy="antlib:org.apache.ivy.ant" default="build">
    <property name="module.depends" value="perftests" />
    <property name="module.test.depends" value="common common/tests" />

    <property name="module.manifest" value="true" />

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

    <!-- Overridden to produce Manifest containing Main-Class and Class-Path -->
    <target name="jar.manifest" depends="compile" if="module.manifest">
      <path id="class.path">
        <fileset dir="${build.lib}" >
          <include name="*.jar"/>
          <exclude name="${qpid.jar.name}"/>
        </fileset>
      </path>
      <pathconvert property="qpid.jar.classpath" pathsep=" " dirsep="/">
        <path refid="class.path"/>
        <globmapper from="${build.lib}${file.separator}*" to="*"/>
      </pathconvert>

      <jar destfile="${module.jar}" basedir="${module.classes}">
        <manifest>
          <attribute name="Class-Path" value="${qpid.jar.classpath}"/>
          <attribute name="Main-Class" value="org.apache.qpid.disttest.charting.ChartingUtil"/>
        </manifest>
      </jar>
    </target>

    <!-- JFreeChart and JFreeCommon -->
    <condition property="download.jfree.jars">
      <or>
        <istrue value="${download-jfree}"/>
        <istrue value="${optional.dependencies}"/>
        <istrue value="${optional}"/>
      </or>
    </condition>

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

    <!--check whether the JFree jar is present, possibly after download-->
    <target name="check-jfree-jars">
        <condition property="jfree.available">
            <and>
                <available file="${project.root}/${jfreechart.jar}"/>
                <available file="${project.root}/${jcommon.jar}"/>
            </and>
        </condition>
    </target>

    <!--echo that BDB is required if it isnt present, with associated licencing note-->
    <target name="jfree-jar-required" depends="jfree-licence-note-optional" unless="jfree.available">
       <echo>The JFreeChart 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/perftests/visualisation-jfc dir: ant download-jfree

   OR

   Adding -Ddownload-jfree=true to your regular build command.</echo>
        <fail>The JFreechart JARs were not found</fail>
    </target>

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

    <!--issue JFree licencing note-->
    <target name="jfree-licence-note">
       <echo>*NOTE* The JFreeChart and JFreeCommon libraries required by this optional module are licensed under the LGPL Licence, which is not compatible with the Apache Licence v2.0.

For a copy of the LGPL Licence, please see:
http://www.gnu.org/licenses/lgpl.html
       </echo>
    </target>

    <target name="check-csvjdbc-jars">
        <condition property="csvjdbc.available">
            <available file="${project.root}/${csvjdbc.jar}"/>
        </condition>
    </target>

    <!--check if an inline JFree download was requested with the build-->
    <target name="checkjfree-request-props" if="download.jfree.jars">
        <antcall target="download-jfree"/>
    </target>

    <!--echo that CSVJDBC is required if it isnt present, with associated licencing note-->
    <target name="csvjdbc-jar-required" depends="csvjdbc-licence-note-optional" unless="csvjdbc.available">
       <echo>The CSVJDBC 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/perftests/visualisation-jfc dir: ant download-csvjdbc

   OR

   Adding -Ddownload-csvjdbc=true to your regular build command.</echo>
        <fail>The CSVJDBC JAR was not found</fail>
    </target>

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

For a copy of the LGPL Licence, please see:
http://www.gnu.org/licenses/lgpl.html
       </echo>
    </target>

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

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

    <target name="checkcsvjdbc-request-props" if="download.csvjdbc.jar">
        <antcall target="download-csvjdbc"/>
    </target>

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

    <target name="build" depends="checkjfree-request-props, jfree-jar-required, checkcsvjdbc-request-props, csvjdbc-jar-required, module.build" />


</project>
