<?xml version="1.0"?>
<!--
 -
 - 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.
 -
 -->

<!-- AMQP Java build file -->

<project name="qpid-client" default="jar" basedir=".">
    <property name="lib" value="${basedir}/lib"/>
    <property name="common.dir" value="${basedir}/../common"/>
    <property name="common.lib" value="${basedir}/../common/lib"/>
    <property name="client.dir" value="${basedir}"/>
    <property name="common.src" value="${common.dir}/src"/>
    <property name="common.resources" value="${common.dir}/resources"/>
    <property name="common.classes" value="${common.dir}/classes"/>
    <property name="client.src" value="${client.dir}/src"/>
    <property name="client.lib" value="${client.dir}/lib"/>
    <property name="client.tests" value="${client.dir}/test"/>
    <property name="client.classes" value="${client.dir}/classes"/>
    <property name="client.testclasses" value="${client.dir}/testclasses"/>
    <property name="generated.java.src" value="${common.dir}/generated/java"/>
    <property name="broker.classes" value="${basedir}/../broker/classes"/>
    <property name="broker.testclasses" value="${basedir}/../broker/testclasses"/>
    <property name="dist" value="${basedir}/dist"/>

    <!-- Setup details -->
    <target name="init">
        <tstamp>
            <format property="release" pattern="-dMMMyy" locale="en" timezone="GMT"/>
        </tstamp>

        <mkdir dir="${common.classes}"/>
        <mkdir dir="${client.classes}"/>
        <mkdir dir="${client.testclasses}"/>
    </target>

    <path id="amqp.classpath">
        <fileset dir="${basedir}/lib">
            <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${common.dir}/lib">
            <include name="**/*.jar"/>
        </fileset>
        <pathelement path="${common.classes}"/>
        <pathelement path="${client.classes}"/>
        <pathelement path="${client.testclasses}/"/>
        <pathelement path="${broker.classes}/"/>
        <pathelement path="${broker.testclasses}/"/>
    </path>

    <path id="client.test.classpath">
        <path refid="amqp.classpath"/>
        <fileset dir="${basedir}/test/lib">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <!-- Remove all built files -->
    <target name="clean" depends="init">
        <delete dir="${common.classes}"/>
        <delete dir="${client.classes}"/>
        <delete dir="${client.testclasses}"/>
    </target>

    <!-- Compile Java -->
    <target name="compile" depends="init, generate">
        <javac destdir="${common.classes}" target="1.5" source="1.5" debug="on">
            <classpath refid="amqp.classpath"/>
            <src path="${common.src}"/>
            <src path="${generated.java.src}"/>
        </javac>

        <javac destdir="${client.classes}" target="1.5" source="1.5" debug="on">
            <classpath refid="amqp.classpath"/>
            <src path="${client.src}"/>
        </javac>

        <copy todir="${common.classes}">
            <!-- copy any non java src files into the build tree, e.g. log4j.properties -->
            <fileset dir="${common.src}">
                <exclude name="**/*.java"/>
                <exclude name="**/package.html"/>
            </fileset>
            <fileset dir="${common.resources}">
                <exclude name="**/*.java"/>
                <exclude name="**/package.html"/>
            </fileset>
        </copy>

        <copy todir="${client.classes}">
            <!-- copy any non java src files into the build tree, e.g. log4j.properties -->
            <fileset dir="${client.src}">
                <exclude name="**/*.java"/>
                <exclude name="**/package.html"/>
            </fileset>
        </copy>
    </target>

    <target name="compiletests" depends="compile">
        <javac destdir="${client.testclasses}" target="1.5" source="1.5" classpathref="client.test.classpath" debug="on">
            <src path="${client.tests}"/>
        </javac>

        <copy todir="${client.testclasses}">
            <!-- copy any non java src files into the build tree, e.g. log4j.properties -->
            <fileset dir="${client.tests}">
                <exclude name="**/*.java"/>
                <exclude name="**/package.html"/>
            </fileset>
        </copy>
    </target>

    <!-- Generate framing source code from protocol specification -->
    <target name="generate" description="Generates framing source code from protocol specification">
         <ant dir="../common" target="generate"/>
    </target>

    <!-- Build jar archive -->
    <target name="jar" depends="compiletests">
        <mkdir dir="${dist}"/>
        <jar basedir="${common.classes}" jarfile="${dist}/amqp-common.jar"/>
        <jar basedir="${client.classes}" jarfile="${dist}/amqp-jms.jar"/>
        <jar basedir="${client.testclasses}" jarfile="${dist}/amqp-tests.jar"/>
    </target>

    <target name="dist" depends="compile">
        <mkdir dir="${dist}"/>
        <jar basedir="${common.classes}" jarfile="${dist}/amqp-common.jar"/>
        <jar basedir="${client.classes}" jarfile="${dist}/amqp-jms.jar"/>
    </target>

    <target name="javadoc" depends="compile, compiletests">
        <mkdir dir="${dist}/docs/api"/>
        <javadoc sourcepath="${client.src}" destdir="${dist}/docs/api"
                 packagenames="org.apache.qpid.*" classpathref="amqp.classpath" author="true"
                 version="true" windowTitle="AMQP Client API" doctitle="AMQP Client API"
                 footer="See &lt;a href=&quot;http://www.amqp.org&quot;&gt;www.amqp.org&lt;/a&gt; for more information."
                 use="true" verbose="false"/>
    </target>

    <target name="ServiceProvidingClient" depends="compiletests">
        <java fork="yes" classname="org.apache.qpid.requestreply1.ServiceProvidingClient">
              <classpath refid="amqp.classpath"/>
              <jvmarg value="-server"/>
              <sysproperty key="amqj.logging.level" value="INFO"/>
              <sysproperty key="amqj.server.shared_read_write_pool" value="true"/>
              <arg value="localhost:5672"/>
              <arg value="guest"/>
              <arg value="guest"/>
              <arg value="/vpath"/>
              <arg value="serviceQ1"/>
        </java>
    </target>

     <target name="ServiceRequestingClient" depends="compiletests">
        <java fork="yes" classname="org.apache.qpid.requestreply1.ServiceRequestingClient">
              <classpath refid="amqp.classpath"/>
              <jvmarg value="-server"/>
              <sysproperty key="amqj.logging.level" value="INFO"/>
              <sysproperty key="amqj.server.shared_read_write_pool" value="true"/>
              <arg value="localhost:5672"/>
              <arg value="guest"/>
              <arg value="guest"/>
              <arg value="/vpath"/>
              <arg value="serviceQ1"/>
              <arg value="5000"/>
              <arg value="512"/>
        </java>
    </target>

    <target name="HeadersListener" depends="compiletests">
        <java fork="yes" classname="org.apache.qpid.headers.Listener">
              <classpath refid="amqp.classpath"/>
              <jvmarg value="-server"/>
              <sysproperty key="amqj.logging.level" value="INFO"/>
              <sysproperty key="amqj.server.shared_read_write_pool" value="true"/>
        </java>
    </target>

    <target name="HeadersPublisher" depends="compiletests">
        <java fork="yes" classname="org.apache.qpid.headers.Publisher">
              <classpath refid="amqp.classpath"/>
              <jvmarg value="-server"/>
              <sysproperty key="amqj.logging.level" value="INFO"/>
              <sysproperty key="amqj.server.shared_read_write_pool" value="true"/>
              <arg value="5000"/>
              <arg value="1"/>
        </java>
    </target>

    <target name="profile" depends="compile" description="Profile Project">
        <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
        <nbprofiledirect>
          <classpath refid="amqp.classpath"/>
        </nbprofiledirect>
        <java fork="true" classname="org.apache.qpid.requestreply1.VmRequestReply"
              dir="${profiler.session.working.dir}"
              jvm="${profiler.info.jvm}">
          <jvmarg line="${profiler.info.jvmargs}"/>
          <env key="Path" path="${profiler.info.agentpath}:${env.Path}"/>
          <classpath refid="amqp.classpath"/>
          <jvmarg value="${profiler.info.jvmargs.agent}"/>
          <jvmarg line="${profiler.info.jvmargs}"/>
          <jvmarg value="-server"/>
          <jvmarg value="-Damqj.logging.level=INFO"/>
          <sysproperty key="amqj.shared_read_write_pool" value="true"/>
          <arg value="localhost:5672"/>
          <arg value="guest"/>
          <arg value="guest"/>
          <arg value="/vpath"/>
          <arg value="serviceQ1"/>
          <arg value="5000"/>
          <arg value="512"/>
        </java>
    </target>

    <target name="profile-single" depends="compile" description="Profile File">
        <fail unless="netbeans.home">This target can only run inside the NetBeans IDE.</fail>
        <nbprofile classname="${profile.class}">
            <classpath refid="amqp.classpath"/>
        </nbprofile>
    </target>

    <target name="release" depends="jar" description="Create a release package">
            <!-- create a jar file that will contain classpath entries for all required jars -->
            <jar jarfile="${dist}/amqj.jar">
                <manifest>
                    <attribute name="Class-Path" value="lib/jms.jar lib/slf4j-simple.jar lib/log4j-1.2.13.jar lib/mina-core-0.9.5-SNAPSHOT.jar lib/mina-filter-ssl-0.9.5-SNAPSHOT.jar lib/commons-cli-1.0.jar lib/commons-configuration-1.2.jar lib/commons-collections-3.1.jar lib/commons-logging-api.jar lib/commons-logging.jar lib/commons-lang-2.1.jar lib/junit-4.0.jar lib/amqp-tests.jar lib/amqp-common.jar lib/amqp-jms.jar"/>
                </manifest>
            </jar>
            <!-- create a zip for releasing -->
            <zip destfile="${dist}/client.zip">
                <zipfileset dir="bin" includes="*.sh,*.bat" filemode="755"/>
                <zipfileset file="${dist}/amqj.jar" />
                <zipfileset prefix="lib" file="${client.lib}/jms/jms.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/slf4j/slf4j-simple.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/logging-log4j/log4j-1.2.13.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/mina/mina-core-0.9.5-SNAPSHOT.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/mina/mina-filter-ssl-0.9.5-SNAPSHOT.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/commons-cli/commons-cli-1.0.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/commons-configuration/commons-configuration-1.2.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/commons-collections/commons-collections-3.1.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/commons-logging/commons-logging-api.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/commons-logging/commons-logging.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/commons-lang/commons-lang-2.1.jar"/>
                <zipfileset prefix="lib" file="${common.lib}/junit/junit-4.0.jar"/>
                <zipfileset prefix="lib" file="${dist}/amqp-tests.jar"/>
                <zipfileset prefix="lib" file="${dist}/amqp-common.jar"/>
                <zipfileset prefix="lib" file="${dist}/amqp-jms.jar"/>
            </zip>

            <tar destfile="${dist}/client.tar.gz" compression="gzip">
                <tarfileset dir="bin" includes="*.sh,*.bat" mode="755"/>
                <tarfileset file="${dist}/amqj.jar"/>
                <tarfileset prefix="lib" file="${client.lib}/jms/jms.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/slf4j/slf4j-simple.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/logging-log4j/log4j-1.2.13.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/mina/mina-core-0.9.5-SNAPSHOT.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/mina/mina-filter-ssl-0.9.5-SNAPSHOT.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/commons-cli/commons-cli-1.0.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/commons-configuration/commons-configuration-1.2.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/commons-collections/commons-collections-3.1.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/commons-logging/commons-logging-api.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/commons-logging/commons-logging.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/commons-lang/commons-lang-2.1.jar"/>
                <tarfileset prefix="lib" file="${common.lib}/junit/junit-4.0.jar"/>
                <tarfileset prefix="lib" file="${dist}/amqp-tests.jar"/>
                <tarfileset prefix="lib" file="${dist}/amqp-common.jar"/>
                <tarfileset prefix="lib" file="${dist}/amqp-jms.jar"/>
            </tar>
        </target>

</project>
