<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<!--
 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 name="rio-example" default="all" basedir=".">
    <!-- import the common elements -->
    <property name="rio.home" location="${basedir}/../../.."/>
    <import file="${rio.home}/build/import/dir-settings.xml"/>
    <import file="${rio.home}/build/import/build-tasks.xml"/>
    <import file="${rio.home}/build/import/deploy-tasks.xml"/>

    <property name="name" value="rio-example"/>
    <property name="lib" value="${basedir}/lib"/>
    <property name="build" value="${basedir}/build"/>
    <property name="classes" value="${build}/classes"/>
    <property name="src" value="${basedir}/src"/>

    <path id="project.classpath">
        <pathelement location="${classes}"/>
        <path refid="required.jars"/>
    </path>

    <target name="prepare"
            description="Creates required directories">
        <mkdir dir="${classes}"/>
        <mkdir dir="${lib}"/>
        <mkdir dir="${deploy.dir}/${name}/lib"/>
    </target>

    <target name="clean"
            description="Removes files and directories created
                         during the build and install process">
        <delete verbose="true" failonerror="false" dir="${lib}"/>
        <delete verbose="true" failonerror="false" dir="${build}"/>
        <delete verbose="true" failonerror="false"
                dir="${deploy.dir}/${name}"/>
    </target>

    <target name="compile" depends="prepare">
        <javac srcdir="${src}" destdir="${classes}"
               deprecation="yes" debug="on">
            <classpath refid="project.classpath"/>
            <patternset refid="java.source"/>
        </javac>
    </target>

    <fileset dir="${src}">
        <patternset id="java.source">
            <include name="**/*.java"/>
        </patternset>
    </fileset>

    <target name="all" depends="prepare, jars"/>

    <target name="jars" depends="impl-jar, download-jar"/>

    <target name="impl-jar" depends="compile">
        <jar destfile="${lib}/rio-example.jar"
             basedir="${classes}"
             includes="tutorial/**"/>
    </target>

    <target name="download-jar" depends="compile">
        <jar destfile="${lib}/rio-example-dl.jar"
             basedir="${classes}"
             includes="tutorial/Echo.class tutorial/EchoProxy.class tutorial/RemoteEcho.class"/>
    </target>

    <target name="deploy" depends="jars">
        <copy todir="${rio.home}/deploy/${name}/lib" overwrite="true">
            <fileset dir="${lib}" includes="*.jar"/>
        </copy>
        <deploy file="${basedir}/resources/rio-example.xml"/>
    </target>

    <target name="undeploy" depends="jars">
        <undeploy file="${basedir}/resources/rio-example.xml"/>
    </target>

    <target name="client">
        <java classname="tutorial.EchoClient" fork="true">
            <classpath>
                <pathelement location="${lib}/rio-example.jar"/>
                <path refid="required.jars"/>
            </classpath>
            <jvmarg
                value="-Djava.security.policy=${basedir}/resources/policy.all"/>
        </java>
    </target>

</project>