<?xml version="1.0"?>
<!--
 -
 - Copyright (c) 2006 The Apache Software Foundation
 -
 - Licensed 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 Management Core Java build file -->

<project name="management-core" default="jar" basedir=".">
    <property name="lib" value="${basedir}/lib"/>
    <property name="src" value="${basedir}/src"/>
    <property name="generated.src" value="${basedir}/generated/src"/>
    <property name="tests" value="${basedir}/test"/>
    <property name="etc" value="${basedir}/etc"/>
    <property name="classes" value="${basedir}/classes"/>
    <property name="testclasses" value="${basedir}/testclasses"/>
    <property name="dist" value="${basedir}/dist"/>
    <property name="apache.root" value="${basedir}/../../clients_java"/>
    <property name="apache.dist" value="${apache.root}/dist"/>
    <property name="apache.lib" value="${apache.root}/lib"/>

    <taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" classpathref="core.classpath"/>

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

        <mkdir dir="${generated.src}"/>
        <mkdir dir="${classes}"/>
        <mkdir dir="${testclasses}"/>
        <mkdir dir="${dist}"/>
    </target>

    <path id="core.classpath">
        <fileset dir="${lib}">
            <include name="**/*.jar"/>
        </fileset>
        <pathelement path="${classes}"/>
        <pathelement path="${testclasses}/"/>
        <fileset dir="${apache.dist}">
            <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${apache.lib}">
            <include name="**/*.jar"/>
        </fileset>
    </path>

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

    <!-- Generate code from the XML schema -->
    <target name="xmlbeans" depends="init">
        <xmlbean classgendir="${classes}" classpathref="core.classpath"
                 failonerror="true" srcgendir="${generated.src}"
                 javasource="1.5" source="1.5">
            <fileset dir="${etc}" includes="**/*.xsd"/>
        </xmlbean>
    </target>

    <!-- Compile Java -->
    <target name="compile" depends="xmlbeans">
        <javac destdir="${classes}" target="1.5" source="1.5" debug="on">
            <classpath refid="core.classpath"/>
            <src path="${src}"/>
            <src path="${generated.src}"/>
        </javac>

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


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

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

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


    <target name="javadoc" depends="compile, compiletests">
        <mkdir dir="${dist}/docs/api"/>
        <javadoc sourcepath="${src}" destdir="${dist}/docs/api"
                 packagenames="org.apache.qpid.*" classpathref="apache.classpath" author="true"
                 version="true" windowTitle="AMQP Client API" doctitle="AMQP Client API"
                 footer="See &lt;a href=&quot;http://www.apache.org&quot;&gt;www.apache.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="apache.classpath"/>
              <jvmarg value="-server"/>
              <jvmarg value="-Damqj.logging.level=INFO"/>
              <arg value="localhost"/>
              <arg value="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="apache.classpath"/>
              <jvmarg value="-server"/>
              <jvmarg value="-Damqj.logging.level=INFO"/>
              <arg value="localhost"/>
              <arg value="5672"/>
              <arg value="guest"/>
              <arg value="guest"/>
              <arg value="/vpath"/>
              <arg value="serviceQ1"/>
              <arg value="5000"/>
        </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="apache.classpath"/>
        </nbprofiledirect>
        <java fork="true" classname="org.apache.qpid.requestreply1.ServiceRequestingClient"
              dir="${profiler.session.working.dir}"
              jvm="${profiler.info.jvm}">
          <jvmarg value="${profiler.info.jvmargs.agent}"/>
          <jvmarg line="${profiler.info.jvmargs}"/>
          <env key="Path" path="${profiler.info.agentpath}:${env.Path}"/>
          <classpath refid="apache.classpath"/>
          <jvmarg value="-server"/>
          <jvmarg value="-Damqj.logging.level=INFO"/>
          <arg value="localhost"/>
          <arg value="5672"/>
          <arg value="guest"/>
          <arg value="guest"/>
          <arg value="/vpath"/>
          <arg value="serviceQ1"/>
          <arg value="5000"/>
        </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="apache.classpath"/>
        </nbprofile>
    </target>
</project>
