<!-- TODO
Add some echo messages

Get dates into reports?

-->
<property name = "cc.label"             value = "${component.version}"/>
<!-- baseline information -->
<property name = "baseline.version" 	value = ""/>
<property name = "baseline.doc.dir" 	value = "W:\Java\common_components"/>

<property name = "lib.vob.root"			value = "\vob_common_lib"/>
<property name = "src.vob.root"			value = "\vob_common_src"/>
<property name = "lib.root.dir"			value = "${lib.vob.root}\${component.name}"/>
<property name = "src.root.dir"			value = "${src.vob.root}\${component.name}"/>
<property name = "cc.workspace.project"         value = "${component.name}"/>
<!-- physical locations -->
<property name = "classes.dir" 		 	value = "${src.root.dir}\bin"/>
<property name = "source.dir" 		 	value = "${src.root.dir}\src"/>
<property name = "test.source.dir" 	 	value = "${src.root.dir}\test"/>
<property name = "jar.name" 		 	value = "${component.name}.jar"/>
<property name = "jar.name.src"		 	value = "${component.name}-src.jar"/>
<property name = "jar.lib.dir" 			value = "${lib.vob.root}\${component.name}"/>
<property name = "jar.src.dir" 			value = "${src.vob.root}\Debug_sources"/> 

<!-- locations for reports at development time -->
<property name = "dev.publish.dir"	 	value = "${src.vob.root}\output\${component.name}"/>

<!-- locations for reports at release time -->
<property name = "release.publish.dir" 	value = "${baseline.doc.dir}\${component.name}"/>

<!-- ant related -->
<property name = "script.root.dir"	 	value = "Z:\vob_devtools\ant\scripts"/>
<property name = "common.build"		 	value = "${script.root.dir}\common-build.xml"/>

<!-- Set up the task to get the classpath from this environment -->
<taskdef name="getclasspath" classname="com.deaded.ant.ClasspathTask"
    classpath="Z:\vob_devtools\ant\lib\commonAntTasks.jar"/>

<!-- Set up the task to get the J2EE classpath from this environment -->
<taskdef name="getJ2EEclasspath" classname="com.deaded.ant.J2EEClasspathTask"
    classpath="Z:\vob_devtools\ant\lib\commonAntTasks.jar"/>

<!-- Set up the task to get the classpath from this environment -->
<taskdef name="jtcg-junit" classname="net.sourceforge.jtcg.junit.JUnitTask"
    classpath="Z:\vob_devtools\ant\lib\jtcg.jar"/>

<!-- Set up the task to fix the correct drive letter to paths used by a UCM view -->
<taskdef name="applyDriveLetter" classname="com.deaded.ant.CurrentDriveLetterTask" 
    classpath="Z:\vob_devtools\ant\lib\commonAntTasks.jar"/>

<!-- Creates the binary JAR and debug source JAR -->
<target name="Create.JARs" depends="Compile, checkout.jars.reserved, checkout.jars.unreserved">
    <applyDriveLetter propertyName="src.root.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="source.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="test.source.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="classes.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="jar.src.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="jar.lib.dir" projectName="${cc.workspace.project}"/>

    <ant antfile="${common.build}" target="update.manifest">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
        <property name="package.name" value="${component.name}"/>
	<property name="manifest.version" value="${component.version}"/>
    </ant>

    <jar jarfile="${jar.lib.dir}/${jar.name}" basedir="${classes.dir}"
        excludes="**/*Test.class, **/*Tests.class"
        manifest="${root.dir}/Manifest.mf"/>
    <jar jarfile="${jar.src.dir}/${jar.name.src}" basedir="${source.dir}"
        excludes="${test.source.dir}"
        manifest="${root.dir}/Manifest.mf"/>

    <!-- will be performed during a deploy -->
    <antcall target="checkin.jars.reserved"/>

    <!-- we can generate this next time - no need for clearcase involvement -->
    <delete file="${src.root.dir}/Manifest.mf"/>
</target>

<!-- basic create JAR should be unreserved ... FULL REALEASE and BASELINE should be reserved -->
<!-- checkout the binary and debug source jars as unreserved -->
<target name="checkout.jars.unreserved" unless="deploy.on">
    <applyDriveLetter propertyName="jar.lib.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="jar.src.dir" projectName="${cc.workspace.project}"/>

    <cccheckout viewpath="${jar.lib.dir}/${jar.name}" reserved="false" nowarn="false"/>
    <cccheckout viewpath="${jar.src.dir}/${jar.name.src}" reserved="false" nowarn="false"/>
</target>

<!-- checkout the binary and debug source jars as reserved -->
<target name="checkout.jars.reserved" if="deploy.on">
    <applyDriveLetter propertyName="jar.lib.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="jar.src.dir" projectName="${cc.workspace.project}"/>

    <cccheckout viewpath="${jar.lib.dir}/${jar.name}" reserved="true" nowarn="false"/>
    <cccheckout viewpath="${jar.src.dir}/${jar.name.src}" reserved="true" nowarn="false"/>  
</target>

<!-- checkin the binary and debug source jars -->
<target name="checkin.jars.reserved" if="deploy.on">
    <applyDriveLetter propertyName="jar.lib.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="jar.src.dir" projectName="${cc.workspace.project}"/>

    <cccheckin viewpath="${jar.lib.dir}/${jar.name}" nowarn="false" identical="true"/>
    <cccheckin viewpath="${jar.src.dir}/${jar.name.src}" nowarn="false" identical="true"/>
</target>

<!-- undo the checkout of the binary and debug source jars ... if Create.JARs is run during 
  development time, the libraries will remain checked out in unreserved state ... this will undo that -->
<target name="Undo.Checkout.Jars">
    <applyDriveLetter propertyName="jar.lib.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="jar.src.dir" projectName="${cc.workspace.project}"/>

    <ccuncheckout viewpath="${jar.lib.dir}/${jar.name}" keepcopy="false"/>
    <ccuncheckout viewpath="${jar.src.dir}/${jar.name.src}" keepcopy="false"/>
</target>

<!-- clean all class files -->
<target name="clean">
    <applyDriveLetter propertyName="classes.dir" projectName="${cc.workspace.project}"/>

    <delete dir="${classes.dir}"/>
</target>

<target name="do.compile" depends="clean">
    <projectBuild ProjectName="${component.name}" failonerror="true"
	DebugCompilation="true" BuildType="full"/>
        
    <getJavacErrorCount ProjectName="${component.name}"  
        PropertyName="compile.error.count" />
    <condition property="build.ok">
        <equals arg1="${compile.error.count}" arg2="0"/>
    </condition>
</target>

<target name="fail.build.check" unless="build.ok">
  <fail>Failed while compiling ${component.name}</fail>
</target>

<target name="Compile" depends="do.compile, fail.build.check">
</target>	

<!-- Build the JavaDoc API docs -->
<target name="JavaDoc" depends="set.dev.publish.dir">
    <ant antfile="${common.build}" target="javadoc">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
    </ant>
</target>

<!-- Build the dependency report -->
<target name="Dependency.Report" depends="set.dev.publish.dir">
    <ant antfile="${common.build}" target="jdepend-for-graphviz">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
    </ant>
</target>

<!-- Build the code style report -->
<target name="Code.Style.Check.Report" depends="set.dev.publish.dir">
    <ant antfile="${common.build}" target="checkstyle">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
    </ant>
</target>
	
<!-- Build the PMD report (style + unused variables) -->
<target name="Project.Mess.Detector.Report" depends="set.dev.publish.dir">
    <ant antfile="${common.build}" target="pmd">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
    </ant>
</target>

<!-- Build the source code metrics report -->
<target name="Source.Code.Metrics.Report" depends="set.dev.publish.dir">
    <ant antfile="${common.build}" target="javancss">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
    </ant>
</target>

<!-- Run the JUnit tests and build the test run report -->
<target name="JUnit.Test.Runs.and.Report" depends="set.dev.publish.dir, Get.Classpath">
    <ant antfile="${common.build}" target="junit">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
    </ant>
</target>

<!-- Run the FindBugs and build report -->
<target name="FindBugs" depends="set.dev.publish.dir, Get.Classpath">
    <ant antfile="${common.build}" target="FindBugs">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
    </ant>
</target>

<!-- Make the real deployment -->
<target name=".FULL.RELEASE." depends="set.deploy.publish.dir, 
	Compile, JUnit.Test.Runs.and.Report, Create.JARs, JavaDoc,
	Dependency.Report, FindBugs, Code.Style.Check.Report, Project.Mess.Detector.Report,
    Source.Code.Metrics.Report, Code.Coverage.Report">

	<!-- update the intranet docs -->
	<antcall target="update.component.intra.docs"/>

	<!-- update the change history with this release info -->
	<antcall target="update.changehistory">
		<param name="history.version" value="${component.version}"/>
	</antcall>

     <ant antfile="${common.build}" target="cc.make.baseline">
        <property name="vob.root" value="${lib.vob.root}"/>
        <property name="root.dir" value="${lib.root.dir}"/>
        <property name="component.to.baseline" value="${component.name}"/>
     </ant>

    <ant antfile="${common.build}" target="cc.make.baseline">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
        <property name="component.to.baseline" value="${component.name}_src"/>
    </ant>

     <property name="coco.url" value="http://localhost/common_components/java/"/>

     <antcall target="make.basecc.release"/>
     
     <antcall target="NNTP"/>
</target>

<target name="make.basecc.release" description="makes the changes to the Base CC side">
    <property name="baseCC.vob.root" value="Z:\vob_common"/>

    <!-- checkout lib jar -->
    <cccheckout viewpath="${baseCC.vob.root}/lib/${component.name}.jar" reserved="true" nowarn="false"/>
    <!-- checkout debug src jar -->
    <cccheckout viewpath="${baseCC.vob.root}/src/Debug_sources/${component.name}-src.jar" reserved="true" nowarn="false"/>

    <!-- create the label for the vob -->
    <ant antfile="${common.build}" target="cc.create.label.no.apply">
        <property name="vob.root" value="${baseCC.vob.root}"/>
        <property name="root.dir" value="${baseCC.vob.root}"/>
    </ant>

    <!-- apply label to the binary JAR -->
    <ant antfile="${common.build}" target="cc.apply.label.to.file.no.apply">
        <property name="vob.root" value="${baseCC.vob.root}"/>
        <property name="root.dir" value="${baseCC.vob.root}"/>
  	<property name="vob.dir" value="${baseCC.vob.root}/lib"/>
        <property name="cc.file.to.label" value="${component.name}.jar"/>
    </ant>

    <!-- apply label to the source JAR -->
    <ant antfile="${common.build}" target="cc.apply.label.to.file.no.apply">
        <property name="vob.root" value="${baseCC.vob.root}"/>
        <property name="root.dir" value="${baseCC.vob.root}"/>
  	<property name="vob.dir" value="${baseCC.vob.root}/src/Debug_sources"/>
        <property name="cc.file.to.label" value="${component.name}-src.jar"/>
    </ant>

    <cccheckin viewpath="${baseCC.vob.root}/lib/${component.name}.jar" nowarn="false" identical="true"/>
    <cccheckin viewpath="${baseCC.vob.root}/src/Debug_sources/${component.name}-src.jar" nowarn="false" identical="true"/>

    <echo message=" "/>
    <echo message=" "/>
    <echo message="Now update the CoCo main page component version table"/>
    <echo message=" "/>
    <echo message=" "/>
</target>

<target name="apply.labels">
    <!-- apply label to the binary JAR -->
   	<ant antfile="${common.build}" target="cc.apply.label.to.file">
             <property name="vob.root" value="${lib.vob.root}"/>
             <property name="root.dir" value="${lib.root.dir}"/>
   	     <property name="vob.dir" value="${jar.lib.dir}"/>
             <property name="cc.file.to.label" value="${jar.name}"/>
   	</ant>

    <!-- apply label to the source JAR -->
   	<ant antfile="${common.build}" target="cc.apply.label.to.file">
            <property name="vob.root" value="${src.vob.root}"/>
            <property name="root.dir" value="${src.root.dir}"/>
  	    <property name="vob.dir" value="${jar.src.dir}"/>
            <property name="cc.file.to.label" value="${jar.name.src}"/>
   	</ant>

    <!-- apply label to the source tree -->
   	<ant antfile="${common.build}" target="cc.apply.label.to.dir">
             <property name="vob.root" value="${src.vob.root}"/>
             <property name="root.dir" value="${src.root.dir}"/>
  	     <property name="vob.dir" value="${src.root.dir}\.."/>
             <property name="cc.dir.to.label" value="${component.name}"/>
   	</ant>
</target>

<target name="move.labels">
    <!-- apply label to the binary JAR -->
   	<ant antfile="${common.build}" target="cc.move.label.to.file">
  	    <property name="vob.dir" value="${jar.lib.dir}"/>
            <property name="cc.file.to.label" value="${jar.name}"/>
   	</ant>

    <!-- apply label to the source JAR -->
   	<ant antfile="${common.build}" target="cc.move.label.to.file">
  	    <property name="vob.dir" value="${jar.src.dir}"/>
            <property name="cc.file.to.label" value="${jar.name.src}"/>
   	</ant>

    <!-- apply label to the source tree -->
   	<ant antfile="${common.build}" target="cc.move.label.to.dir">
  	    <property name="vob.dir" value="${src.root.dir}"/>
            <property name="cc.dir.to.label" value="${component.name}"/>
   	</ant>
</target>

<target name="set.dev.publish.dir" unless="deploy.on">
    <property name="report.dir" value="${dev.publish.dir}\reports"/>
    <property name="javadoc.dir" value="${dev.publish.dir}\${component.version}-api"/>

    <applyDriveLetter propertyName="report.dir" projectName="${cc.workspace.project}"/>
    <applyDriveLetter propertyName="javadoc.dir" projectName="${cc.workspace.project}"/>
</target>

<target name="set.deploy.publish.dir">
    <property name="deploy.on" value="true"/>

    <property name="report.dir" value="${release.publish.dir}\reports"/>
    <property name="javadoc.dir" value="${release.publish.dir}\${component.version}-api"/>
</target>

<target name="update.component.intra.docs">
    <!-- update the current component version on the component page -->
    <property name="search1" value="Current Component Version: ${previous.version}"/>
	<property name="replace1" value="Current Component Version: ${component.version}"/>
	<replace file="${baseline.doc.dir}\${component.name}\index.html" token="${search1}" value="${replace1}"/>
		
    <!-- add a link to the new JavaDocs ... keeping the link to the previous version JavaDocs -->
    <property name="search2" value='&lt;a href="${previous.version}-api\index.html"&gt;${previous.version} API&lt;/a&gt;&lt;br/&gt;'/>
    <property name="replace2" value='&lt;a href="${component.version}-api\index.html"&gt;${component.version} API&lt;/a&gt;&lt;br/&gt;${line.separator}${search2}'/>
	<replace file="${baseline.doc.dir}\${component.name}\index.html" token="${search2}" value="${replace2}"/>

    <!-- update the cuurent component version on the common component main page -->
	<property name="search3" value='&lt;!-- ANT.${component.name}.current.version --&gt;&lt;a href="${component.name}\${previous.version}-api\index.html"&gt;${previous.version}&lt;/a&gt;'/>
	<property name="replace3" value='&lt;!-- ANT.${component.name}.current.version --&gt;&lt;a href="${component.name}\${component.version}-api\index.html"&gt;${component.version}&lt;/a&gt;'/>
	<replace file="${baseline.doc.dir}\index.html" token="${search3}" value="${replace3}"/>
</target>

<!-- Update a file named ChangeHistory.txt in the src.root.dir of a project -->
<target name="update.changehistory">
	<tstamp>
		<format property="TSTAMP" pattern="dd.MM.yyyy HH:mm"/>
	</tstamp>

    <cccheckout viewpath="${src.root.dir}/ChangeHistory.txt" reserved="true" nowarn="false"/>

    <!-- Add the lines in reverse order as we are prepending -->
    <!-- last line is a blank line -->        
    <ant antfile="${common.build}" target="prepend.text.to.file">
   	    <property name="text.to.prepend" value='" "'/>
        <property name="file.to.prepend" value="${src.root.dir}/ChangeHistory.txt"/>
    </ant>

    <!-- 2nd line is the version info -->
    <ant antfile="${common.build}" target="prepend.text.to.file">
   	    <property name="text.to.prepend" value='"- ${baseline.version} ${component.version}"'/>
        <property name="file.to.prepend" value="${src.root.dir}/ChangeHistory.txt"/>
    </ant>

    <!-- 1st line is the timestamp -->
    <ant antfile="${common.build}" target="prepend.text.to.file">
  	    <property name="text.to.prepend" value='"${TSTAMP}"'/>
        <property name="file.to.prepend" value="${src.root.dir}/ChangeHistory.txt"/>
    </ant>

    <cccheckin viewpath="${src.root.dir}/ChangeHistory.txt" nowarn="false" identical="true"/>

	<!-- Copy the ChangeHistory.txt file to the intranet location -->
	<copy file="${src.root.dir}/ChangeHistory.txt" tofile="${baseline.doc.dir}\${component.name}\ChangeHistory.txt"/>
</target>

<!-- Get the classpath from this project into a form that can be passed
  outside of the WSAD environment -->
<target name="Get.Classpath">
	<getclasspath ProjectName="${component.name}" 
		ProjectClasspathProperty="project.classpath"/>
</target>

<!-- Build the code coverage report -->
<target name="Code.Coverage.Report" depends="clean, set.dev.publish.dir, Get.Classpath">
    <ant antfile="${common.build}" target="clover">
        <property name="vob.root" value="${src.vob.root}"/>
        <property name="root.dir" value="${src.root.dir}"/>
    </ant>

    <antcall target="Compile"/>
</target>

<target name="NNTP">
  <property name="coco.url" value="http://localhost/common_components/java/"/>
  <property name="line1" value="Component: ${component.name}"/>
  <property name="line2" value="Label: ${component.version}"/>
  <property name="line3" value=""/>
  <property name="line4" value="Change History: ${coco.url}${component.name}/ChangeHistory.txt"/>
  <property name="line5" value="Component Pages: ${coco.url}${component.name}/index.html"/>
  <property name="line6" value=""/>
  <property name="line7" value="CoCo Page: ${coco.url}"/>

  <ant antfile="${common.build}" target="NNTP">
    <property name="nntp.server" value="news.someserver.com"/>
    <property name="nntp.group" value="alt.java"/>
    <property name="nntp.email" value="some.person@somecompany,com"/>
    <property name="nntp.author" value="Java Common Components"/>
    <property name="nntp.subject" value="[Components] ${component.version}"/>
    <property name="nntp.text" value="${line1}\n${line2}\n${line3}\n${line4}\n${line5}\n${line6}\n${line7}"/>
  </ant>
</target>
