@echo off

set OUTPUT_FILE=CodeCoverageProperties.xml
set CODE_COVERAGE_BUILDTOOLKIT=%cd%

REM Check for the 'buildtoolkit' directory 
cd ..
set TOOLKIT_DIR=buildtoolkit
IF EXIST %TOOLKIT_DIR% GOTO DIR_EXISTS

REM The directory structure of the build toolkit offering changed in the 3.x version. 
REM Check for the 3.x directory structure if we haven't found the buildtoolkit directory yet
cd ..
set TOOLKIT_DIR=jazz\buildsystem\buildtoolkit
IF EXIST %TOOLKIT_DIR% GOTO DIR_EXISTS
cd %CODE_COVERAGE_BUILDTOOLKIT%
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.
goto END

:DIR_EXISTS
cd %TOOLKIT_DIR%
set BUILDTOOLKIT=%cd%
cd %CODE_COVERAGE_BUILDTOOLKIT%

for /f "delims= tokens=1" %%c in ('dir /B /S /OD "org.eclipse.tptp.platform.jvmti.runtime_*"') do set JVMTI_RUNTIME=%%c
for /f "delims= tokens=1" %%c in ('dir /B /S /OD "com.ibm.rational.llc.engine_*"') do set ENGINE_JAR=%%c

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-ext-dir}\CodeCoverageReports"/^> >> %OUTPUT_FILE%
echo ^<property name="llc-jvmti-library" value="%JVMTI_RUNTIME%\agent_files\win_ia32\JPIBootLoader"/^> >> %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.

:END