@echo off
REM ###########################################################################
REM Script generated by HP Fortify SCA Scan Wizard (c) HP Fortify 2011
REM Created on 2015/02/07 21:50:51
REM ###########################################################################
REM Generated for the following languages:
REM 	Java
REM 	XML
REM ###########################################################################
REM DEBUG - if set to true, runs SCA in debug mode
REM SOURCEANALYZER - the name of the SCA executable
REM BUILDID - the SCA build id
REM LAUNCHERSWITCHES - the launcher settings that are used to invoke SCA
REM ARGFILE - the name of the argument file that's extracted and passed to SCA
REM MEMORY - the memory settings for SCA
REM OLDFILENUMBER - this defines the file which contains the number of files within the project, it is automatically generated
REM FILENOMAXDIFF - this is the percentage of difference between the number of files which will trigger a warning by the script
REM ###########################################################################

set DEBUG=false
set SOURCEANALYZER=sourceanalyzer
set FPR="..\scanResults\Fortifyauth.fpr"
set BUILDID="auth"
set ARGFILE="Fortifyauth.bat.args"
set MEMORY=-Xmx2048M -Xms2048M -Xss128M 
set LAUNCHERSWITCHES=""
set OLDFILENUMBER=Fortifyauth.bat.fileno
set FILENOMAXDIFF=10

set PROJECTROOT0="..\..\auth"
IF NOT EXIST %PROJECTROOT0% (
   ECHO  ERROR: This script is being run on a different machine than it was
   ECHO         generated on or the targeted project has been moved. This script is 
   ECHO         configured to locate files at
   ECHO            %PROJECTROOT0%
   ECHO         Please modify the %%PROJECTROOT0%% variable found
   ECHO         at the top of this script to point to the corresponding directory
   ECHO         located on this machine.
   GOTO :FINISHED
)

IF %DEBUG%==true set LAUNCHERSWITCHES=-debug %LAUNCHERSWITCHES%
echo Extracting Arguments File


echo. >Fortifyauth.bat.args
SETLOCAL ENABLEDELAYEDEXPANSION
IF EXIST %0 (
   set SCAScriptFile=%0
) ELSE (
  set SCAScriptFile=%0.bat
)

set PROJECTROOT0=%PROJECTROOT0:)=^)%
FOR /f "delims=" %%a IN ('findstr /B /C:"REM ARGS" %SCAScriptFile%' ) DO (
   set argVal=%%a
   set argVal=!argVal:PROJECTROOT0_MARKER=%PROJECTROOT0:~1,-1%!
   echo !argVal:~9! >> %ARGFILE%
)
ENDLOCAL

REM ###########################################################################
echo Cleaning previous scan artifacts
%SOURCEANALYZER% %MEMORY% %LAUNCHERSWITCHES% -b %BUILDID% -clean 
IF %ERRORLEVEL%==1 (
echo Sourceanalyzer failed, exiting
GOTO :FINISHED
)
REM ###########################################################################
echo Translating files
%SOURCEANALYZER% %MEMORY% %LAUNCHERSWITCHES% -b %BUILDID% @%ARGFILE%
IF %ERRORLEVEL%==1 (
echo Sourceanalyzer failed, exiting
GOTO :FINISHED
)
REM ###########################################################################
echo Testing Difference between Translations
SETLOCAL
FOR /F "delims=" %%A in ('%SOURCEANALYZER% -b %BUILDID% -show-files ^| findstr /R /N "^" ^| find /C ":" ') DO SET FILENUMBER=%%A
IF NOT EXIST %OLDFILENUMBER% (
	ECHO It appears to be the first time running this script, setting %OLDFILENUMBER% to %FILENUMBER%
	ECHO %FILENUMBER% > %OLDFILENUMBER%
	GOTO TESTENDED
)

FOR /F "delims=" %%i IN (%OLDFILENUMBER%) DO SET OLDFILENO=%%i
set /a DIFF=%OLDFILENO% * %FILENOMAXDIFF%
set /a DIFF /=  100
set /a MAX=%OLDFILENO% + %DIFF%
set /a MIN=%OLDFILENO% - %DIFF%

IF %FILENUMBER% LSS %MIN% set SHOWWARNING=true
IF %FILENUMBER% GTR %MAX% set SHOWWARNING=true

IF DEFINED SHOWWARNING (
	ECHO WARNING: The number of files has changed by over %FILENOMAXDIFF%%%, it is recommended 
	ECHO          that this script is regenerated with the ScanWizard
)
:TESTENDED
ENDLOCAL

REM ###########################################################################
echo Starting scan
%SOURCEANALYZER% %MEMORY% %LAUNCHERSWITCHES% -b %BUILDID% -scan -f %FPR%
IF %ERRORLEVEL%==1 (
echo Sourceanalyzer failed, exiting
GOTO :FINISHED
)
REM ###########################################################################
echo Finished
:FINISHED
REM ARGS "-cp"
REM ARGS "PROJECTROOT0_MARKER\target\classes\gov\va\med\mpn\auth\controller\AuthorizationController.class;PROJECTROOT0_MARKER\target\classes\gov\va\med\mpn\auth\utils\AuthUtils.class;PROJECTROOT0_MARKER\target\classes\gov\va\med\mpn\auth\web\CustomOAuthClientFilter.class;PROJECTROOT0_MARKER\target\classes\gov\va\med\mpn\auth\web\CustomOAuthSessionListener.class;PROJECTROOT0_MARKER\target\classes\gov\va\med\mpn\auth\web\CustomServletRequestWrapper.class"
REM ARGS "-cp"
REM ARGS "PROJECTROOT0_MARKER\target\mpn-auth-1.19-SNAPSHOT.jar"
REM ARGS "-source"
REM ARGS "1.7"
REM ARGS -exclude "PROJECTROOT0_MARKER\target\classes\authorization.properties"
REM ARGS -exclude "PROJECTROOT0_MARKER\target\maven-archiver\pom.properties"
REM ARGS -exclude "PROJECTROOT0_MARKER\pom.xml"
REM ARGS -exclude "PROJECTROOT0_MARKER\target\classes\log4j.xml"
REM ARGS -exclude "PROJECTROOT0_MARKER\target\classes\spring\mpn-spring-security.xml"
REM ARGS "PROJECTROOT0_MARKER"
