<?xml version="1.0"?>

<project name="Apache Sandesha" default="usage" basedir=".">
    <description>
   Build File Interop Interops for Apache Sandesha

   This file is intended for ANT, a Java based build tool.
   ANT is available from http://jakarta.apache.org/ant/index.html

Prerequisites:
   J2SDK 1.4          from http://java.sun.com/
   jakarta-ant        from http://jakarta.apache.org/ant/
   commons-logging    from http://jakarta.apache.org/commons/logging.html
   log4j              from http://jakarta.apache.org/log4j

Optional components:
   junit              from http://www.junit.org/

Build Instructions:
   To build, run

     ant "target"   on the directory where this file is located with the target you want.
    </description>

    <target name="init">
        <property name="product.Name" value="Apache-Sandesha-J"/>
        <property name="year" value="2004"/>
        <property name="copyright" value="Copyright &#169; ${year} Apache Sandesha Project. All Rights Reserved."/>

        <property name="dir.dist" value="../target/dist"/>
        <property name="dir.libs" value="../lib"/>
        <property name="dir.src" value="../src"/>
        <property name="dir.test" value="../test"/>
        <property name="dir.interop" value="../interop"/>
        <property name="dir.webapp" location="../webapps/axis"/>
        <property name="build.dir" value="../target"/>
        
        
        <!-- Following two were added on 01-03-2005-->
        <property name="dir.config" value="../config"/>
        <property name="build.interop" value="${build.dir}/interop-classes"/>


        <property name="build.classes" value="${build.dir}/classes"/>
        <property name="build.work" value="${build.dir}/work"/>
        <property name="build.webapp" location="${build.dir}/webapps/axis"/>
        <property environment="env1"/>


        <path id="classpath.libraries" description="3rd party libs">
            <fileset dir="${dir.libs}">
                <include name="**/*.jar"/>
            </fileset>
        </path>

        <path id="classpath.sandesha" description="sandesha classes; first try pure class files, then jars">
            <pathelement path="${build.classes}"/>
        </path>

        <path id="classpath.library">
            <path refid="classpath.sandesha"/>
            <path refid="classpath.libraries"/>
        </path>

        <path id="classpath.interop">
            <path refid="classpath.sandesha"/>
            <path refid="classpath.libraries"/>
            <pathelement path="${build.interop}"/>
        </path>


        <echo message="-------------------------------------------------------------------"/>
        <echo message="----------------------- Sandesha Interop Build---------------------"/>
        <echo message="-------------------------------------------------------------------"/>
        <echo message="Building with ${ant.version}"/>
        <echo message="using build file ${ant.file}"/>
        <echo message="Java ${java.version} located at ${java.home} "/>
        <echo message="-------------------------------------------------------------------"/>
        <echo message=""/>

    </target>

    <target name="usage" depends="init">
        <echo message="                                                                            "/>
        <echo message=" Build instructions                                                         "/>
        <echo message="----------------------------------------------------------------------------"/>
        <echo message="                                                                            "/>
        <echo message=" available targets are:                                                     "/>
        <echo message="   clean    --> cleans up all generated files and                           "/>
        <echo message="   jar      --> creates the JAR file                                        "/>
        <echo message="   war      --> creates the interop war file in ./target/dist/war directory "/>
        <echo message="   war.copy --> creates the war and copy it to                              "/>
        <echo message="                 CATALINA_HOME/webapps                                      "/>
        <echo message="   usage    --> provides help on using the build tool                       "/>
        <echo message="                       (default)                                            "/>
        <echo message=" See comments inside the build.xml file for more details.                   "/>
        <echo message="----------------------------------------------------------------------------"/>
        <echo message="                                                                            "/>
    </target>

    <target name="clean" depends="init" description="Clean up all temporary build files">
        <delete dir="${build.dir}"/>
        <delete dir="${dir.dist}"/>
        <delete>
            <fileset dir="." includes="before*.xml"/>
            <fileset dir="." includes="after*.xml"/>
            <fileset dir="." includes="signed*.xml"/>
        </delete>
    </target>

    <target name="prepare" depends="init" description="This target generates a first build directory and checks for some libraries">
        <tstamp/>
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dir}/test-reports"/>

    </target>


    <target name="prepare-src" depends="prepare" description="This target copies the Java sources and brands the version information">
        <!-- create directories -->
        <mkdir dir="${build.classes}"/>
    </target>

    <target name="compile" depends="compile.library" description="compile everything"/>

    <target name="compile.library" depends="prepare-src">
        <javac srcdir="${dir.src}" destdir="${build.classes}" debug="on">
            <classpath refid="classpath.library"/>
        </javac>

        <javac srcdir="${dir.interop}" destdir="${build.classes}" debug="on">
            <classpath refid="classpath.library"/>
        </javac>

        <copy todir="${build.classes}">

            <fileset dir="${dir.interop}">
                <include name="sandesha-interop.properties"/>
                <include name="server-config.wsdd"/>
            </fileset>
            <fileset dir="${dir.config}">
                <include name="client-config.wsdd"/>
                <include name="sandesha.properties"/>
                <include name="log4j.properties"/>
                <include name="WSRMPolicy.xml"/>
                <include name="commons-logging.properties"/>
                <include name="sandesha.log"/>
            </fileset>
        </copy>
    </target>


    <target name="compile.interop" depends="compile.library">
        <javac srcdir="${dir.interop}" destdir="${build.interop}" debug="on">
            <classpath refid="classpath.library"/>
        </javac>

        <copy todir="${build.interop}">
            <fileset dir="${dir.interop}" includes="client-config.wsdd"/>
            <fileset dir="${dir.config}" includes="sandesha.properties"/>
            <fileset dir="${dir.interop}" includes="sandesha-interop.properties"/>
        </copy>

    </target>


    <target name="prepare-dist">
        <mkdir dir="${dir.dist}"/>
    </target>

    <target name="prepare-jar" depends="compile.library,prepare-dist" description="prepares for creating jar">

        <property name="sandesha.jar.name" value="SandeshaInterop.jar"/>
        <property name="dir.dist.jar" value="${dir.dist}/jar"/>
        <property name="sandesha.jar" value="${dir.dist.jar}/${sandesha.jar.name}"/>
        <property name="axishome" value="${env1.CATALINA_HOME}/webapps/axis/WEB-INF/lib"/>
        <mkdir dir="${dir.dist.jar}"/>

        <copy todir="${build.classes}">
            <fileset dir="${dir.config}">
                <include name="client-config.wsdd"/>
                <include name="sandesha.properties"/>
                <include name="log4j.properties"/>
                <include name="WSRMPolicy.xml"/>
                <include name="commons-logging.properties"/>
                <include name="sandesha.log"/>
            </fileset>
        </copy>
        <copy todir="${build.classes}">
            <fileset dir="${dir.interop}">
                <include name="sandesha-interop.properties"/>
                <include name="server-config.wsdd"/>
            </fileset>
        </copy>
    </target>

    <target name="jar" depends="prepare-jar" description="creates the sandesha jar">
        <jar basedir="${build.classes}" destfile="${sandesha.jar}"/>

    </target>

    <target name="prepare-war" depends="jar" description="prepares for creating war">
        <property name="interop.prop.file.name" value="sandesha-interop.properties"/>
        <property name="sandesha.war.name" value="sandesha-interop.war"/>
        <property name="sandehsa.war.base.name" value="sandesha-interop"/>
        <property name="webxml" value="${dir.interop}/webapp/web.xml"/>
        <property name="dir.dist.war" value="${dir.dist}/war"/>
        <property name="sandesha.war" value="${dir.dist.war}/${sandesha.war.name}"/>
        <property name="webapps" value="${env1.CATALINA_HOME}/webapps"/>
        <mkdir dir="${dir.dist.war}"/>
    </target>

    <target name="create.war" depends="prepare-war" description="creates the sandesha war">
        <war destfile="${sandesha.war}" webxml="${webxml}">
            <fileset dir="${dir.interop}/webapp/jsp"/>
            <lib dir="${dir.libs}"/>
            <lib file="${sandesha.jar}"/>
        </war>
    </target>

    <target name="war.copy.clean" depends="war.copy" description="cleans the temporary files">
        <delete dir="${dir.dist}"/>
        <delete dir="${build.interop}"/>
    </target>

    <target name="war.copy" depends="war">
        <delete file="${webapps}/${sandesha.war}"/>
        <delete dir="${webapps}/${sandehsa.war.base.name}"/>
        <copy file="${sandesha.war}" todir="${webapps}"/>
    </target>

    <target name="jar.copy" depends="jar">
        <delete file="${axishome}/${sandesha.jar.name}"/>
        <copy file="${sandesha.jar}" todir="${axishome}"/>
    </target>

    <target name="war" depends="clean,create.war" description="creates the war file"/>

</project>
