#!/bin/sh

OUTPUT_FILE=CodeCoverageProperties.xml

CODE_COVERAGE_BUILDTOOLKIT=`pwd`
TOOLKIT_DIR=buildtoolkit
cd ..

if [ ! -d `pwd`/${TOOLKIT_DIR} ]; then
	cd ..
	TOOLKIT_DIR=jazz/buildsystem/buildtoolkit
	if [ ! -d `pwd`/${TOOLKIT_DIR} ]; then
		echo "Cannot find the 'buildtoolkit' directory! The Rational Application Developer Code Coverage tools for Rational Team Concert Builds must be installed within the IBM Rational Team Concert Build System Toolkit."
		echo
		cd $CODE_COVERAGE_BUILDTOOLKIT
		exit 1;
		echo 
	fi
fi


BUILDTOOLKIT=`pwd`/${TOOLKIT_DIR}
cd $CODE_COVERAGE_BUILDTOOLKIT

ENGINE_JAR=$(find ${CODE_COVERAGE_BUILDTOOLKIT} -name "com.ibm.rational.llc.engine_*.jar" | sort | tail -1);

JVMTI_RUNTIME_DIR=$(find ${CODE_COVERAGE_BUILDTOOLKIT} -name "org.eclipse.tptp.platform.jvmti.runtime_*" | sort | tail -1);

echo \<project\> > ${OUTPUT_FILE}

echo \<property name=\"jazz-build-toolkit\" value=\"${BUILDTOOLKIT}\"/\> >> ${OUTPUT_FILE}
echo \<property name=\"code-coverage-ext-dir\" value=\"${CODE_COVERAGE_BUILDTOOLKIT}\"/\> >> ${OUTPUT_FILE}
echo \<property name=\"code-coverage-report-dir\" value=\"${CODE_COVERAGE_BUILDTOOLKIT}/CodeCoverageReports\"/\> >> ${OUTPUT_FILE}
echo \<property name=\"llc-jvmti-library\" value=\"${JVMTI_RUNTIME_DIR}/agent_files/linux_ia32/libJPIBootLoader.so\"/\> >> ${OUTPUT_FILE}
echo \<property name=\"llc-engine-plugin\" value=\"${ENGINE_JAR}\"/\> >> ${OUTPUT_FILE}

echo \<property name=\"llc-jvm-arg-jvmti\" value=\"-agentpath:\${llc-jvmti-library}=JPIAgent:server=standalone,file=\;ProbekitAgent:ext-pk-BCILibraryName=BCIEngProbe,ext-pk-probescript=\"/\> >> ${OUTPUT_FILE}
echo \<property name=\"llc-jvm-arg-engine\" value=\"-Xbootclasspath/a:\${llc-engine-plugin}\"/\> >> ${OUTPUT_FILE}
echo \<property name=\"llc-jvm-arg-output\" value=\"-Dcoverage.out.file=\"/\> >> ${OUTPUT_FILE}

echo \<import file=\"\${code-coverage-ext-dir}/CoverageToolkitTaskDefs.xml\"/\> >> ${OUTPUT_FILE}
echo \<import file=\"\${jazz-build-toolkit}/BuildToolkitTaskDefs.xml\"/\> >> ${OUTPUT_FILE}

echo \</project\> >> ${OUTPUT_FILE}
echo Code Coverage properties file successfully generated!
echo 
