@echo off
rem The NOPAUSE env variable should be set to avoid prompt confirmations

rem Define environment variables
set LOG_FILE=%TEMP%/JenkinsDeploy.log
set DEPLOYMENT_DIR=C:\JBoss-7.1\standalone\packages\deploy
set TOKEN_FILE=%DEPLOYMENT_DIR%\deploy.token
cd %DEPLOYMENT_DIR%

rem Check if an EAR file should be deployed
if exist "%TOKEN_FILE%" (
	del "%TOKEN_FILE%"
) else (
    echo No token detected at %TOKEN_FILE%
	pause
	exit
)

rem Reset log file
date /t > %LOG_FILE%

echo =========================
echo Jenkins deployment in VAL
echo =========================

echo  - Undeploy previous EAR
call C:\JBoss-7.1\bin\jboss-cli.bat --connect --command="undeploy snecma-reports.ear"

echo  - Deploy new EAR
call C:\JBoss-7.1\bin\jboss-cli.bat --connect --command="deploy snecma-reports.ear"

echo  - Restart FSC
net stop "Teamcenter FSC Service FSC_pvtc10_tcadmin" >> %LOG_FILE%
net start "Teamcenter FSC Service FSC_pvtc10_tcadmin" >> %LOG_FILE%

echo  - Restart Teamcenter
net stop "TeamcenterServerManager_TC10" >> %LOG_FILE%
net start "TeamcenterServerManager_TC10" >> %LOG_FILE%

del "%DEPLOYMENT_DIR%\snecma-reports.ear"

