<!-- Main build configutaion for Shibboleth java components - Walter Hoehn 06/04/2002 -->

<project name="Shibboleth" default="dist-origin" basedir=".">

    <!-- Set global properties for this build -->
    <property name="distname" value="shibboleth" />
    <property name="root" value="." />
    <property name="src" value="${root}/src/" />
    <property name="tests" value="${root}/tests/" />
    <property name="approot" value="${root}/webApplication/" />
    <property name="appconfig" value="${src}/conf/" />
    <property name="configroot" value="${root}/webAppConfig/" />
    <property name="build" value="${approot}/WEB-INF/classes/" />
    <property name="libdir" value="${approot}/WEB-INF/lib/" />
    <property name="buildlibs" value="${root}/lib/" />
    <property name="distlibs" value="${root}/lib/" />
    <property name="dist" value="${root}/dist/" />
    <property name="docs" value="${root}/docs/" />
    <property name="javadocs" value="${docs}/api/" />

    <property name="year" value="2002"/>
    <property name="copyright" value="Copyright &#169; ${year} UCAID. All Rights Reserved."/>


    <!-- Construct the CLASSPATH -->
    <path id="build.path">
        <pathelement path="${classpath}" />
        <pathelement location="${build}" />
        <fileset dir="${libdir}">
            <include name="**/*.jar" />
        </fileset>
        <fileset dir="${buildlibs}">
            <include name="**/*.jar" />
        </fileset>
    </path>


    <!-- Prepare directory structure for project build-->
    <target name="init">
    <mkdir dir="${build}" />
    <mkdir dir="${dist}" />
    </target>


    <!-- This target should be run before checking code into the repository -->
    <target name="pre-checkin" depends="compile, test-all, clean-all" />


    <!-- Compile classes and move them to ${build} -->
    <target name="compile" depends="init">
        <javac srcdir="${src}" destdir="${build}" includes="**/*.java" debug="on">
            <classpath refid="build.path" />
        </javac>
        <copy todir="${build}/schemas">
            <fileset dir="${src}/schemas"/>
        </copy>
        <copy todir="${build}/conf">
            <fileset dir="${src}/conf"/>
        </copy>
    </target>
    
    <target name="compile-tests" depends="compile">
        <javac srcdir="${tests}" destdir="${build}" includes="**/*.java" debug="on">
            <classpath refid="build.path" />
        </javac>
    </target>


	<!-- Generate API docs -->
	<target name="javadocs">
		<mkdir dir="${docs}" />
		<mkdir dir="${javadocs}" />
		<javadoc packagenames='edu.internet2.middleware.*'
			sourcepath='${src}' destdir='${javadocs}'
			author='true' version='true'
			windowtitle='Shibboleth Java API' doctitle='Shibboleth Java API'
			bottom='${copyright}'>
                <classpath refid="build.path" />
        </javadoc>
	</target>

    <!-- Create various product distributions and move them to ${dist} -->

    <target name="dist-all" depends="compile, test-all, package-all, clean-build" />
    <target name="package-all">
        <war warfile="${dist}/${distname}.war" webxml="${configroot}/all.xml" basedir="${approot}" update="no" />
    </target>

    <target name="dist-origin" depends="compile, test-origin, package-origin, clean-build" />
    <target name="package-origin">
        <war warfile="${dist}/${distname}.war" webxml="${configroot}/origin.xml" basedir="${approot}" update="no" />
    </target>
    
    <target name="dist-wayf" depends="compile, package-wayf, clean-build" />
    <target name="package-wayf">
        <war warfile="${dist}/${distname}-wayf.war" webxml="${configroot}/wayf.xml" basedir="${approot}" update="no" />
    </target>

    <!-- Build utilities -->
    <target name="build-util" depends="compile">
        <jar jarfile="${distlibs}/shib-util.jar" basedir="${build}" />
    </target>

    
    <!-- Cleanup after the build, test, and distribution processes -->
    <target name="clean" depends="clean-all" />
    <target name="clean-all" depends="clean-build, clean-dist, clean-test, clean-javadocs, clean-util" />
    <target name="clean-build">
        <delete dir="${build}" />
    </target>
    <target name="clean-test">
        <delete>
            <fileset dir="${root}">
                <include name="**/TEST*.txt" />
            </fileset>
        </delete>
    </target>
    <target name="clean-dist">
        <delete dir="${dist}" />
    </target>
	<target name="clean-javadocs">
		<delete dir="${javadocs}" />
	</target>
    <target name="clean-util">
        <delete>
            <fileset dir="${buildlibs}">
                <include name="shib-util.jar" />
            </fileset>
        </delete>
    </target>

    <!-- Run automated tests on compiled code -->
    <target name="test-all" depends="test-origin" />
    <target name="test-origin" depends="compile-tests">
        <junit printsummary="no" fork="yes" haltonfailure="yes" haltonerror="yes" dir="${root}">
            <classpath refid="build.path" />
            <formatter type="plain" />
            <test name="edu.internet2.middleware.shibboleth.aa.arp.ArpTests" />
			<test name="edu.internet2.middleware.shibboleth.aa.attrresolv.ResolverTests" />
        </junit>
    </target>
    
	<target name="genSecret" depends="compile">
    	<taskdef name="genSecret" classname="edu.internet2.middleware.shibboleth.utils.HandleRepositorySecretGenerator" classpathref="build.path"/>
		<genSecret keyStorePath="${appconfig}/handle.jks" keyStorePassword="shibhs" keyStoreKeyAlias="handleKey" keyStoreKeyPassword="shibhs" />
	</target>

</project>
