<!--
 ! 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="hello" basedir="." default="build">

    <description>This Ant scripts provides numerous tasks to build the
        the Hello Example</description>

    <!-- Root of the River source distribution -->
    <property name="root" location="../.." />

    <!-- Override this to build/run hello example against an external River installation -->
    <property name="river.home" location="${root}"/>

    <!-- Import common settings and macros -->
    <import file="${root}/common.xml"/>

    <!-- javadoc setings -->
    <property name="javadoc.doc-title" value="Apache River v${version} Hello Example API Documentation"/>
    <property name="javadoc.win-title" value="${javadoc.doc-title}"/>

    <!-- classpath searched by ClassDep -->
    <path id="classdep.cp">
        <path refid="river.jars"/>
        <pathelement location="${build.classes.dir}"/>
    </path>

    <path id="javadoc.classpath">
        <path refid="river.jars"/>
        <pathelement location="${build.classes.dir}"/>
    </path>
    
	<property name="config.dir" location="config"/>
    <property name="trust.dir" location="prebuiltkeys"/>
      
	<target name="clean" depends=""
		description="Removes all files and dirs created by the build">
        <delete dir="${build.dir}"/>
        <delete dir="${lib.dir}"/>
        <delete dir="${doc.dir}"/>
        <delete dir="${trust.dir}"/>
    </target>

    <target name="compile" depends="prep" description="Build classes">
        <javac-cmd source.dir="${src.dir}" dest.dir="${build.classes.dir}">
            <classpath refid="river.jars"/>
        </javac-cmd>
    </target>
      
	<target name="prep" description="Prepare the build">
        <mkdir dir="${build.dir}" />
        <mkdir dir="${build.classes.dir}" />
        <mkdir dir="${build.deps.dir}" />
        <mkdir dir="${lib.dir}" />
        <mkdir dir="${trust.dir}" />
    </target>

    <target name="doc" depends="compile"
		description="Generate javadoc documentation">
        <delete dir="${doc.api.dir}" quiet="true"/>
        <mkdir  dir="${doc.api.dir}"/>

        <javadoc author="true"
			 breakiterator="yes"
			 destdir="${doc.api.dir}"
			 doctitle="${javadoc.doc-title}"
			 serialwarn="false"
			 source="1.4"
             linkoffline="${jdk.doc.url} ${jdk.packages}"
			 use="true"
			 version="true"
			 windowtitle="${javadoc.win-title}">
            <bottom><![CDATA[${api.copyright}]]></bottom>
            <classpath refid="javadoc.classpath"/>
            <sourcepath>
                <pathelement path="${src.dir}"/>
            </sourcepath>
            <package name="com.sun.jini.example.hello.*"/>
        </javadoc>

        <mkdir dir="${doc.api.dir}/doc-files"/>
        <copy file="${root}/NOTICE" tofile="${doc.api.dir}/doc-files/NOTICE"/>
    </target>
      
	<target name="jars"
		depends="client.jar,
			 mdprefld.jar,
			 server.jar,
			 server-act.jar,
			 server-dl.jar">
      
	</target>
      
	<target name="client.jar" depends="stubs">
        <property name="example-client.deps" location="${build.deps.dir}/example-client.deps"/>
        <classdep output="${example-client.deps}">
            <arg value="-cp"/>
            <arg pathref="classdep.cp"/>
            <arg value="-files"/>
            <arg line="${jskplatform.exclude}"/>
            <arg line="-in net.jini"/>
            <arg line="-in com.sun.jini"/>
            <arg value="com.sun.jini.example.hello.Client"/>
        </classdep>
        <delete file="${lib.dir}/client.jar" quiet="true"/>
        <jar destfile="${lib.dir}/client.jar"
		     index="false"
		     manifest="client.mf">
            <fileset dir="${build.classes.dir}" includesfile="${example-client.deps}"/>
        </jar>
    </target>

    <target name="mdprefld.jar"	depends="compile">
        <delete file="${lib.dir}/mdprefld.jar" quiet="true"/>
        <jar destfile="${lib.dir}/mdprefld.jar"
		     index="false">
            <fileset dir="${build.classes.dir}"
				 includes="com/sun/jini/example/hello/MdClassAnnotationProvider.class"/>
        </jar>
    </target>

    <target name="server.jar" depends="stubs">
        <property name="example-server.deps" location="${build.deps.dir}/example-server.deps"/>
        <classdep output="${example-server.deps}">
            <arg value="-cp"/>
            <arg pathref="classdep.cp"/>
            <arg value="-files"/>
            <arg line="${jskplatform.exclude}"/>
            <arg line="-in net.jini"/>
            <arg line="-in com.sun.jini"/>
            <arg value="com.sun.jini.example.hello.Server"/>
            <arg value="com.sun.jini.example.hello.Server_Stub"/>
            <arg value="com.sun.jini.example.hello.ConfirmingILFactory"/>
            <arg value="com.sun.jini.example.hello.ConfirmingInvocationHandler"/>
            <arg value="com.sun.jini.example.hello.ServerPermission"/>
        </classdep>
        <delete file="${lib.dir}/server.jar" quiet="true"/>
        <jar destfile="${lib.dir}/server.jar"
		     index="false"
		     manifest="server.mf">
            <fileset dir="${build.classes.dir}"  includesfile="${example-server.deps}"/>
        </jar>
    </target>

    <target name="server-act.jar" depends="stubs">
        <property name="example-server-act.deps" location="${build.deps.dir}/example-server-act.deps"/>
        <classdep output="${example-server-act.deps}">
            <arg value="-cp"/>
            <arg pathref="classdep.cp"/>
            <arg value="-files"/>
            <arg line="${jskplatform.exclude}"/>
            <arg line="-in net.jini"/>
            <arg line="-in com.sun.jini"/>
            <arg value="com.sun.jini.example.hello.ActivatableServer"/>
            <arg value="com.sun.jini.example.hello.ConfirmingILFactory"/>
            <arg value="com.sun.jini.example.hello.ConfirmingInvocationHandler"/>
            <arg value="com.sun.jini.example.hello.Server"/>
            <arg value="com.sun.jini.example.hello.Server_Stub"/>
            <arg value="com.sun.jini.example.hello.ServerPermission"/>
        </classdep>
        <delete file="${lib.dir}/server-act.jar" quiet="true"/>
        <jar destfile="${lib.dir}/server-act.jar"
		     index="false"
		     manifest="server-act.mf">
            <fileset dir="${build.classes.dir}" includesfile="${example-server-act.deps}"/>
        </jar>
    </target>

    <target name="server-dl.jar" depends="stubs">
        <property name="example-server-dl.deps" location="${build.deps.dir}/example-server-dl.deps"/>
        <classdep output="${example-server-dl.deps}"> 
            <arg value="-cp"/>
            <arg pathref="classdep.cp"/>
            <arg value="-files"/>
            <arg line="${jskplatform.exclude}"/>
            <arg line="-in net.jini"/>
            <arg line="-in com.sun.jini"/>
            <arg value="com.sun.jini.example.hello.ConfirmingInvocationHandler"/>
            <arg value="com.sun.jini.example.hello.Hello"/>
            <arg value="com.sun.jini.example.hello.Proxy"/>
            <arg value="com.sun.jini.example.hello.Server_Stub"/>
            <arg value="com.sun.jini.example.hello.ServerPermission"/>
        </classdep>
        <delete file="${lib.dir}/server-dl.jar" quiet="true"/>
        <jar destfile="${lib.dir}/server-dl.jar"
		     index="false">
            <fileset dir="${build.classes.dir}"  includesfile="${example-server-dl.deps}"/>
            <metainf dir="${config.dir}/META-INF"/>
        </jar>
    </target>

    <target name="stubs" depends="compile">
        <rmic base="${build.classes.dir}" stubversion="1.2">
            <classpath refid="river.jars"/>
            <include name="com/sun/jini/example/hello/Server.class"/>
        </rmic>
    </target>

    <target name="trust" depends="prep,keystores,password,truststore"
        description="Generate keys, passwords and certificates"/>

    <target name="keystores" depends="client.keystore,
            reggie.keystore,
            phoenix.keystore,
            server.keystore" />

    <target name="client.keystore">
        <delete file="${trust.dir}/client.keystore" quiet="true"/>
        <keystore target="client" dir="${trust.dir}" dname="Client" />
    </target>

    <target name="reggie.keystore">
        <delete file="${trust.dir}/reggie.keystore" quiet="true"/>
        <keystore target="reggie" dir="${trust.dir}" dname="Reggie" />
    </target>

    <target name="phoenix.keystore">
        <delete file="${trust.dir}/phoenix.keystore" quiet="true"/>
        <keystore target="phoenix" dir="${trust.dir}" dname="Phoenix" />
    </target>

    <target name="server.keystore">
        <delete file="${trust.dir}/server.keystore" quiet="true"/>
        <keystore target="server" dir="${trust.dir}" dname="Server" />
    </target>

    <target name="password" depends="client.password,
            reggie.password,
            phoenix.password,
            server.password" />

    <target name="client.password">
        <delete file="${trust.dir}/client.password" quiet="true"/>
        <echo file="${trust.dir}/client.password" message="clientpw" />
    </target>

    <target name="reggie.password">
        <delete file="${trust.dir}/reggie.password" quiet="true"/>
        <echo file="${trust.dir}/reggie.password" message="reggiepw" />
    </target>

    <target name="phoenix.password">
        <delete file="${trust.dir}/phoenix.password" quiet="true"/>
        <echo file="${trust.dir}/phoenix.password" message="phoenixpw" />
    </target>

    <target name="server.password">
        <delete file="${trust.dir}/server.password" quiet="true"/>
        <echo file="${trust.dir}/server.password" message="serverpw" />
    </target>

    <target name="truststore">
        <delete file="${trust.dir}/truststore" quiet="true" />
        <truststore target="client" dir="${trust.dir}" />
        <truststore target="reggie" dir="${trust.dir}" />
        <truststore target="phoenix" dir="${trust.dir}" />
        <truststore target="server" dir="${trust.dir}" />
    </target>

    <target name="build" depends="trust,jars,doc"
            description="Build all"/>

</project>

