<project name="compute-grid" default="all" basedir=".">
	<property name="example.name" value="compute-grid"/>
	 <!-- 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="compute-grid"/>
    <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">
		<classdepandjar jarfile="${lib}/grid.jar" files="true" debug="true">
			<classpath refid="project.classpath"/>
			<in name="tutorial.grid"/>
			<topclass name="tutorial.grid.TaskServer"/>
		</classdepandjar>
	</target>

	<target name="download-jar" depends="compile">
		<classdepandjar jarfile="${lib}/grid-dl.jar" files="true" debug="true">
			<classpath refid="project.classpath"/>
			<in name="tutorial.grid"/>
			<topclass name="tutorial.grid.Task"/>
		</classdepandjar>
		<classdepandjar jarfile="${lib}/task1.jar" files="true" debug="true">
			<classpath refid="project.classpath"/>
			<in name="tutorial.grid"/>
			<topclass name="tutorial.grid.task1.Task1Client"/>
		</classdepandjar>
		<classdepandjar jarfile="${lib}/task2.jar" files="true" debug="true">
			<classpath refid="project.classpath"/>
			<in name="tutorial.grid"/>
			<topclass name="tutorial.grid.task2.Task2Client"/>
		</classdepandjar>
	</target>

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

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

	<target name="client-task-1">
		<java classname="tutorial.grid.task1.Task1Client" fork="true">
			<classpath>
				<pathelement location="${lib}/task1.jar"/>
				<path refid="required.jars"/>
			</classpath>
			<jvmarg value="-Djava.security.policy=${basedir}/resources/policy.all"/>
			<jvmarg value="-Djava.rmi.server.codebase=http://YOUR_IP_ADDRESS:9010/compute-grid/lib/task1.jar"/>
		</java>
	</target>

	<target name="client-task-2">
		<java classname="tutorial.grid.task2.Task2Client" fork="true">
			<classpath>
				<pathelement location="${lib}/task2.jar"/>
				<path refid="required.jars"/>
			</classpath>
			<jvmarg value="-Djava.security.policy=${basedir}/resources/policy.all"/>
			<jvmarg value="-Djava.rmi.server.codebase=http://YOUR_IP_ADDRESS:9010//compute-grid/lib/task2.jar"/>
		</java>
	</target>

</project>
