Hooking up sub-processes with different JRE and Squish package

Last edited on

Prepare separate Squish Package and Squish Settings

Steps for Windows for every separate JRE (do once only per JRE):

(Replace SQUISH2 as required.)

Start Sub-Process indirectly through Helper Tool (No AUT modification needed)

:: ################################################################
:: TO BE CONFIGURED (1 of 2) -->

:: Squish package configured for JRE of the sub-process:
set SQUISH2_PREFIX=C:\Users\myuser\squish-5.0-java-win64-20140125-0214

:: JRE that executes the sub-process:
set JRE2_PREFIX=C:\Program Files\Java\jre7

:: <-- TO BE CONFIGURED (1 of 2)
:: ################################################################



:: ################################################################
:: Start Java sub-process with different Squish package and JRE
:: ################################################################

[...]

:: ################################################################
:: TO BE CONFIGURED (2 of 2) -->

:: Finally, start the sub-process:
"%JRE2_PREFIX%\bin\java" -cp "%SQUISH_PREFIX%\examples\java\calculator" Calculator

:: <-- TO BE CONFIGURED (2 of 2)
:: ################################################################

:: Exit with the current error level, in case the parent process
:: relies on this:
exit %errorlevel%

[...]
mysubprocess.exe.bat

Start Sub-Process indirectly through Batch File (AUT modification needed)

:: ################################################################
:: TO BE CONFIGURED (1 of 2) -->

:: Squish package configured for JRE of the sub-process:
set SQUISH2_PREFIX=C:\Users\myuser\squish-5.0-java-win64-20140125-0214

:: JRE that executes the sub-process:
set JRE2_PREFIX=C:\Program Files\Java\jre7

:: <-- TO BE CONFIGURED (1 of 2)
:: ################################################################



:: ################################################################
:: Start Java sub-process with different Squish package and JRE
:: ################################################################

:: Point to other Squish package:
set SQUISH_PREFIX=%SQUISH2_PREFIX%

:: Restore original PATH by removing the first 4 paths that Squish
:: added to PATH (to avoid overflowing and thus truncating the PATH
:: contents):
call :split_once "%PATH%" ";" "dummy" "PATH"
call :split_once "%PATH%" ";" "dummy" "PATH"
call :split_once "%PATH%" ";" "dummy" "PATH"
call :split_once "%PATH%" ";" "dummy" "PATH"

:: Add to PATH #1: Path to Squish's bin folder:
set PATH=%SQUISH_PREFIX%\bin;%PATH%

:: Add to PATH #2: Path to JRE's bin folder:
set PATH=%JRE2_PREFIX%\bin;%PATH%

if not exist "%JRE2_PREFIX%\bin\server\jvm.dll" set set PATH=%JRE2_PREFIX%\bin\server;%PATH%
if exist "%JRE2_PREFIX%\bin\server\jvm.dll" set set PATH=%JRE2_PREFIX%\bin\client;%PATH%

:: Add to PATH #3: Path to the other Squish package's lib folder:
set PATH=%SQUISH_PREFIX%\lib;%PATH%

:: Add to PATH #4: Path to the other Squish package's lib\jvm folder:
set PATH=%SQUISH_PREFIX%\lib\jvm;%PATH%

:: Point to other Squish (JRE) configuration in the Squish folder
:: itself:
set SQUISH_USER_SETTINGS_DIR=%SQUISH_PREFIX%\settings_jre2

:: Point to Squish proxy jvm.dll from other Squish package:
set JDK_ALTERNATE_VM=%SQUISH_PREFIX%\lib\jvm

:: Point to other JRE that will execute the sub-process:
set SQUISH_LIBJVM=%JRE2_PREFIX%\bin\client\jvm.dll
if exist "%JRE2_PREFIX%\bin\server\jvm.dll" set SQUISH_LIBJVM=%JRE2_PREFIX%\bin\server\jvm.dll

:: Adjust Squish proxy jvm.dll parameters:
set SQUISH_JAVA_DEF_1=-Xbootclasspath/p:%SQUISH_PREFIX%\lib\squishrt.jar
set SQUISH_JAVA_DEF_2=-Dsquish.wrapper=%SQUISH_PREFIX%\bin\squishjavawrapper.dll
set SQUISH_JAVA_DEF_3=-javaagent:%SQUISH_PREFIX%\lib\squishagent.jar=%SQUISH_PREFIX%\lib



:: ################################################################
:: TO BE CONFIGURED (2 of 2) -->

:: Finally, start the sub-process:
"%JRE2_PREFIX%\bin\java" -cp "%SQUISH_PREFIX%\examples\java\calculator" Calculator

:: <-- TO BE CONFIGURED (2 of 2)
:: ################################################################



:: Exit with the current error level, in case the parent process
:: relies on this:
exit %errorlevel%



:: No automatic execution past this point
goto eof



:: FUNCTIONS

:: USAGE:
::   call :split_once "string to split once" "delimiter_char" "left_var" "right_var"
:split_once
    setlocal
    set right=%~1
    set delimiter_char=%~2
    set left=

    if "%right%" equ "" goto split_once_done

    :split_once_loop
        if "%right:~0,1%" equ "%delimiter_char%" set right=%right:~1%&& goto split_once_done
        if "%right:~0,1%" neq "%delimiter_char%" set left=%left%%right:~0,1%
        if "%right:~0,1%" neq "%delimiter_char%" set right=%right:~1%
        if "%right%" equ "" goto split_once_done
    goto split_once_loop

    :split_once_done
    endlocal & set %~3=%left%& set %~4=%right%
goto:eof
mysubprocess.bat

Related Information