<?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.
-->

<project name="Inbound Connection Demo" default="build" basedir=".">
    <property environment="env"/>

    <property environment="env"/>
    <condition property="cxf.home" value="${env.CXF_HOME}">
        <isset property="env.CXF_HOME"/>
    </condition>

    <fail message="this sample need to use CXF_HOME enviroment, please setup CXF_HOME in your environment" unless="cxf.home"/>

    <property name="j2ee.resources.dir" location="${basedir}/../common/resources"/>
    <property name="build.archives" value="${basedir}/j2ee-archives"/>
    <property name="ejb.xml" location="./etc/ejb.xml"/>
    <property name="j2ee.archives" value="j2ee-archives"/>
    <property name="demos.current.dir" value="."/>
    <property name="build.classes.dir" value="${basedir}/build"/>

    <import file="../../../common_build.xml"/>


    <path id="other.classpath">
        <fileset dir="${cxf.home}/modules/integration" >
            <include name="cxf-integration-jca-*.jar"/>
        </fileset>
        <pathelement location="${basedir}/../common/lib/geronimo-ejb_3.0_spec-1.0.1.jar"/>
    </path>

    <target name="init">
        <mkdir dir="${build.classes.dir}/cxf-rar/META-INF"/>
        <mkdir dir="${build.classes.dir}/lib"/>
        <mkdir dir="${j2ee.archives}"/>
    </target>

    <target name="generate.code">
        <echo level="info" message="Generating code using wsdl2java..."/>
        <wsdl2java file="hello_world.wsdl"/>
    </target>

    <target name="generate.rar" depends="init">
        <copy file="${basedir}/etc/ra.xml" todir="${build.classes.dir}/cxf-rar/META-INF"/>
        <copy todir="${build.classes.dir}/cxf-rar">
            <fileset dir="${cxf.home}/lib">
                <include name="*.jar"/>
                <exclude name="cxf*.jar"/>
            </fileset>
            <fileset dir="${cxf.home}/modules">
                <include name="*.jar"/>
                <exclude name="*manifest*.jar"/>
            </fileset>
            <fileset dir="${cxf.home}/modules/integration">
                <include name="*.jar"/>
                <exclude name="*-jbi-*.jar"/>
            </fileset>
        </copy>
        <jar destfile="${build.classes.dir}/lib/cxf.rar"
         basedir="${build.classes.dir}/cxf-rar"/>
    </target>

    <target name="build" description="compile the code" depends="build.ejb.jar"/>

    <target name="j2ee.compile" depends="init,maybe.generate.code">
        <javac destdir="${build.classes.dir}" debug="true" fork="yes">
            <src path="${basedir}/src"/>
            <src path="${build.dir}/src"/>
            <classpath>
                <pathelement location="${cxf.home}/modules/cxf-manifest.jar"/>
                <pathelement location="${build.classes.dir}"/>
                <path refid="cxf.classpath"/>
                <path refid="other.classpath"/>
            </classpath>
        </javac>
    </target>

    <target name="clean">
        <delete dir="${build.dir}"/>
        <delete dir="${basedir}/j2ee-archives"/>
    </target>

    <target name="build.ejb.jar" depends="j2ee.compile">
        <jar destfile="${j2ee.archives}/greeterwithwsdlejb.jar">
            <metainf dir="${basedir}/etc">
                <include name="ejb-jar.xml"/>
            </metainf>
            <fileset dir="${build.classes.dir}/" includes="org/**/*.class"/>
            <fileset dir="${build.classes.dir}/" includes="demo/ejb/**/Greeter*.class"/>
            <fileset dir="${basedir}" includes="wsdl/**/*.wsdl"/>
            <fileset dir="${basedir}" includes="etc/cxf.xml"/>
        </jar>
    </target>

    <target name="client" description="run demo client" depends="build">
        <property name="param" value=""/>
        <cxfrun classname="demo.client.Client"
            param1="${basedir}/wsdl/hello_world.wsdl" 
            param2="${op}" 
            param3="${param}"/>
    </target> 

</project>
