<!--
  ~ Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
  ~
  ~ 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.
  -->
<project default="build-all">

    <property name="wso2appserver.home" value="../../../"/>
    <property name="repo.location" value="${wso2appserver.home}/repository/deployment/server"/>
    <property name="warName" value="jaxrs_basic.war"/>
    <property name="build.dir" value="build"/>
    <property name="classes" value="${build.dir}/classes"/>
    <property name="lib" value="${build.dir}/lib"/>
    <property name="webapps" value="${build.dir}/webapps"/>
    <property name="src" value="."/>

    <path id="compile.classpath">
        <fileset dir="${lib}">
            <include name="*.jar"/>
        </fileset>
    </path>

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

        <copy toDir="${lib}">
	    <fileset dir="${wso2appserver.home}/repository/components/plugins/">
                <include name="commons-httpclient_3.1.0.wso2v2.jar"/>
                <include name="commons-codec_1.4.0.wso2v1.jar"/>
            </fileset>
	    <fileset dir="${wso2appserver.home}/lib/runtimes/cxf/">
                <include name="*.jar"/>
            </fileset>
        </copy>
    </target>

    <target name="compile" depends="init" >
        <javac destdir="${classes}" debug="true" srcdir="src">
            <classpath refid="compile.classpath"/>
        </javac>
    </target>

    <target name="war" depends="compile">
        <echo message="Creating webapp ${warName}."/>
        <copy file="src/main/java/demo/jaxrs/client/add_customer.xml" todir="${classes}/demo/jaxrs/client"/>
        <copy file="src/main/java/demo/jaxrs/client/update_customer.xml" todir="${classes}/demo/jaxrs/client"/>
        <war destfile="${webapps}/${warName}" webxml="./src/main/webapp/WEB-INF/web.xml">
            <classes dir="${classes}"/>
            <fileset dir="src/main/webapp/"/>
        </war>
    </target>

    <target name="build-all" depends ="war">
        <echo message="Copying the created war file in to the deployment directory"/>
        <copy file="${webapps}/${warName}" todir="${repo.location}/webapps"/>
    </target>

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

</project>