<!--
  JBoss, Home of Professional Open Source
  Copyright 2008, Red Hat Middleware LLC, and individual contributors
  as indicated by the @author tags.
  See the copyright.txt in the distribution for a
  full listing of individual contributors.
  This copyrighted material is made available to anyone wishing to use,
  modify, copy, or redistribute it subject to the terms and conditions
  of the GNU Lesser General Public License, v. 2.1.
  This program is distributed in the hope that it will be useful, but WITHOUT A
  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,
  v.2.1 along with this distribution; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA  02110-1301, USA.

  (C) 2008,
  @author JBoss Inc.
-->

<project name="embedded-tools" default="build-sar" basedir=".">

    <!-- You should modify the next two lines -->
    <property environment="env"/>
    <property name="jboss.as.home" value="${env.JBOSS_HOME}"/>

    <!-- You should not need to modify anything below this point -->
    <property name="jboss.ts" value="../../.."/>
    <property name="jboss.ts.tools" value="${jboss.ts}/install/bin"/>
    <available property="bin.present" file="${jboss.ts.tools}" type="dir"/>

    <property name="jboss.as.profile" value="default"/>
    <property name="jboss.server" value="${jboss.as.home}/server/${jboss.as.profile}"/>
    <property name="build.dir" value="build"/>
    <property name="jboss.ts.tools.install.dir" value="${build.dir}/mbean"/>
    <property name="src.dir" value="src"/>
    <property name="resources.dir" value="resources"/>

    <!-- Compile with debugging? -->
    <condition property="com.arjuna.mwlabs.debug" value="no">
        <equals arg1="${com.arjuna.mw.debug}" arg2="no"/>
    </condition>
    <property name="com.arjuna.mwlabs.debug" value="yes"/>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

    <target name="init" depends="clean">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dir}/classes"/>
        <mkdir dir="${build.dir}/mbean"/>
        <mkdir dir="${build.dir}/apps"/>
    </target>

    <path id="classpath">
        <fileset dir="${jboss.as.home}/client" includes="jboss-system-jmx-client.jar"/>
        <fileset dir="${jboss.as.home}/lib" includes="jboss-system.jar"/>
        <fileset dir="${jboss.ts.tools}" includes="tsmx-tools.jar"/>
        <fileset dir="${jboss.ts.tools}/tools" includes="tsmx-objectstorebrowser.jar"/>
        <fileset dir="${jboss.ts.tools}/tools/plugins" includes="osbv-defaults.jar"/>
    </path>

    <target name="compile" depends="init" description="compile the source" if="bin.present">
        <mkdir dir="${build.dir}"/>
        <javac destdir="${build.dir}/classes" classpathref="classpath"
            debug="${com.arjuna.mwlabs.debug}">
            <src path="${src.dir}"/>
        </javac>
    </target>

    <target name="build-jar" depends="compile" description="build the jar file" if="bin.present">
        <jar destfile="${build.dir}/apps/embedded-tools.jar">
            <fileset dir="${build.dir}/classes" includes="**/*.class"/>
        </jar>
    </target>

    <target name="build-sar" depends="build-jar" description="build the mbean" if="bin.present">
        <jar destfile="${jboss.ts.tools.install.dir}/jbossts-tools.sar">
            <manifest>
                <attribute name="Class-Path" value="tsmx-tools.jar tools/tsmx-objectstorebrowser.jar"/>
            </manifest>
            <fileset dir="${resources.dir}">
                <include name="META-INF/jboss-beans.xml"/>
            </fileset>
            <fileset dir="${build.dir}/apps" includes="embedded-tools.jar"/>
            <fileset dir="${jboss.ts.tools}/tools">
                <include name="toolsframework.xml"/>
            </fileset>
            <fileset dir="${jboss.ts.tools}">
                <include name="tsmx-tools.jar"/>
                <include name="**/tsmx-objectstorebrowser.jar"/>
                <include name="**/osbv-defaults.jar"/>
            </fileset>
        </jar>
    </target>

</project>
