<?xml version="1.0"?>

<project name="Project.Export" default="export.EAR">
    <description>
        Export build file - called from the main build with parameters set for the target
        system to create the EAR for.
    </description>

    <target name="export.EAR">
        <!-- checkout the files we need to modify -->
        <cccheckout viewpath="${web.xml}" reserved="false" nowarn="false" />
        <cccheckout viewpath="${ejb.ejb-jar.xml}" reserved="false" nowarn="false" />
        <cccheckout viewpath="${head.jsp}" reserved="false" nowarn="false" />		
        <cccheckout viewpath="${manifest.ear.file}" reserved="false" nowarn="false" />
        <cccheckout viewpath="${manifest.web.file}" reserved="false" nowarn="false" />
        <!-- need the EAR project dir checked out to remove the clover.jar link for EAR deployment -->
        <cccheckout viewpath="${root.dir}${ear.project}" reserved="false" nowarn="false" />

        <!-- replace the db name to be used -->
        <replace file="${web.xml}" token="${dev.db}" value="${deploy.db}" />
        <replace file="${ejb.ejb-jar.xml}" token="${dev.db}" value="${deploy.db}" />
        <replace file="${head.jsp}" token="${versionToken}" value="${versionNumber} (${deploy.name})" />
        <!-- remove the clover.jar entry from the manifest.mf file -->
        <replace file="${manifest.web.file}" token="clover.jar" value="" />

        <!-- remove the clover.jar link from this checkout of the EAR dir as this is not wanted in 
                the deployed application -->
        <exec dir="${root.dir}${ear.project}" executable="cmd">
            <arg line="/c cleartool rmname clover.jar"/>
        </exec>
        <!-- refresh to reflect the removal of clover.jar -->
        <eclipse.refreshLocal resource="${ear.project}" depth="infinite" />	

        <manifest file="${manifest.ear.file}" mode="update">
            <section name="version">
                <attribute name="DBSchema" value="${deploy.db}"/>
                <attribute name="Version" value="${versionNumber}"/>
                <attribute name="Project" value="${head.title}"/>
                <attribute name="Company" value="DeadEd.com"/>
            </section>
        </manifest>

        <eclipse.refreshLocal resource="${ejb.project}" depth="infinite" />	
        <eclipse.refreshLocal resource="${web.project}" depth="infinite" />	

        <!-- export the EAR to the wanted location -->
        <earExport EARProjectName="${ear.project}" EARExportFile="${deploy.ear.file}" Overwrite="true"/>

        <!-- undo the checkouts, also means that the changes are lost (== good) -->
        <ccuncheckout viewpath="${web.xml}" keepcopy="false" />
        <ccuncheckout viewpath="${ejb.ejb-jar.xml}" keepcopy="false" />
        <ccuncheckout viewpath="${head.jsp}" keepcopy="false" />	
        <ccuncheckout viewpath="${manifest.ear.file}" keepcopy="false" />
        <ccuncheckout viewpath="${manifest.web.file}" keepcopy="false" />
        <!-- undo checkout of EAR dir will put the clover.jar link back -->
        <ccuncheckout viewpath="${root.dir}${ear.project}" keepcopy="false" />

        <!-- earExport internally sets debug to false, so we turn it back on here -->
        <setDebugInfo DebugInfo="true"/>

        <eclipse.refreshLocal resource="${ejb.project}" depth="infinite" />	
        <eclipse.refreshLocal resource="${web.project}" depth="infinite" />	
        <projectBuild ProjectName="${ejb.project}" failonerror="false" DebugCompilation="${debug.compilation}" />
        <projectBuild ProjectName="${web.project}" failonerror="false" DebugCompilation="${debug.compilation}" />

        <!-- a final refresh of the EAR project to bring the clover.jar link back -->
        <eclipse.refreshLocal resource="${ear.project}" depth="infinite" />	
	</target>
</project>