From 899d086b64ec0f33affa3eb13a7cfba3f0393857 Mon Sep 17 00:00:00 2001 From: Laurent Jouanneau Date: Wed, 31 Jul 2013 23:38:38 +0200 Subject: [PATCH] Fixes issues with Cygwin Path of the profile and of the application.ini were not in the good format. there was also an issue with the --envs parameter. Closes #4 --- docs/installation.rst | 13 +- src/README.md | 3 +- src/components/commandline.js | 6 +- src/slimerjs | 15 +- src/slimerjs.bat | 382 +++++++++++++++++----------------- 5 files changed, 222 insertions(+), 197 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index ae3bc4c..76e2ed5 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -5,8 +5,17 @@ Installation ============ -SlimerJS runs on any platform on which Firefox or XulRunner is available. XulRunner -is the core of Firefox without its user interface. +Requirements +------------ + +SlimerJS runs on any platform on which Firefox or XulRunner is available: Linux (32bits and 64bits), +Windows, MacOs X. XulRunner is the core of Firefox without its user interface. + +On windows, you should open a terminal. You can use the classical cmd.exe, or the recent PowerShell.exe. +You can also install `Cygwin `_ and use its terminal. + +You cannot use the MingW32 environment on Windows because there are some issues with +(no output in the console, and it lacks on some commands like mktemp). Installation of SlimerJS ------------------------ diff --git a/src/README.md b/src/README.md index 6e03d44..d2a8066 100644 --- a/src/README.md +++ b/src/README.md @@ -14,8 +14,7 @@ Go to [http://slimerjs.org] to know more and to access to the documentation - [Download the latest package](http://download.slimerjs.org/slimerjs-0.5RC1.zip) or [the source code of SlimerJS](https://github.com/laurentj/slimerjs/archive/master.zip) if you didn't it yet - On windows, a .bat is provided, but you can also launch slimer from a "true" console. In this case, you should install - [Cygwin](http://www.cygwin.com/) or any other unix environment to launch slimerjs. Note - that some issues are known with Cygwin. + [Cygwin](http://www.cygwin.com/) or any other unix environment to launch slimerjs. - SlimerJS needs to know where Firefox or XulRunner is stored. It tries to discover itself the path but can fail. You must then set the environment variable SLIMERJSLAUNCHER, which should contain the full path to the firefox binary: diff --git a/src/components/commandline.js b/src/components/commandline.js index 6c0ab15..671b15f 100644 --- a/src/components/commandline.js +++ b/src/components/commandline.js @@ -39,7 +39,10 @@ slCommandLine.prototype = { dump("error cache service:"+ ex+"\n"); } - slConfiguration.setEnvNames(cmdLine.handleFlagWithParam("envs", false).split(/,/)); + if (envService.exists('__SLIMER_ENV')) { + let envs = envService.get('__SLIMER_ENV'); + slConfiguration.setEnvNames(envs.split(/,/)); + } slConfiguration.workingDirectory = cmdLine.workingDirectory; @@ -114,6 +117,7 @@ slCommandLine.prototype = { } } else { + slConfiguration.scriptFile = cmdLine.resolveFile(slConfiguration.args[0]); } if (!slConfiguration.scriptFile.exists()) diff --git a/src/slimerjs b/src/slimerjs index 7baab1d..c371a56 100755 --- a/src/slimerjs +++ b/src/slimerjs @@ -11,6 +11,15 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli done SLIMERDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +SYSTEM=`uname -o` +if [ "$SYSTEM" == "Cygwin" ] +then + IN_CYGWIN=1 + SLIMERDIR=`cygpath -w $SLIMERDIR` +else + IN_CYGWIN= +fi + # retrieve the path of a gecko launcher if [ "$SLIMERJSLAUNCHER" == "" ] then @@ -136,6 +145,9 @@ then echo "Error: cannot generate temp profile" exit 1 fi + if [ "$IN_CYGWIN" == 1 ]; then + PROFILE_DIR=`cygpath -w $PROFILE_DIR` + fi PROFILE="--profile $PROFILE_DIR" else PROFILE="-purgecaches" @@ -144,9 +156,10 @@ fi # put all arguments in a variable, to have original arguments before their transformation # by Mozilla export __SLIMER_ARGS="$@" +export __SLIMER_ENV="$LISTVAR" # launch slimerjs with firefox/xulrunner -"$SLIMERJSLAUNCHER" -app $SLIMERDIR/application.ini $PROFILE -no-remote --envs "$LISTVAR" "$@" +"$SLIMERJSLAUNCHER" -app $SLIMERDIR/application.ini $PROFILE -no-remote "$@" EXITCODE=$? diff --git a/src/slimerjs.bat b/src/slimerjs.bat index 974fd8e..2c74ce6 100644 --- a/src/slimerjs.bat +++ b/src/slimerjs.bat @@ -1,191 +1,191 @@ -@echo off - -SET SLIMERJSLAUNCHER="%SLIMERJSLAUNCHER%" -REM % ~ d[rive] p[ath] 0[script name] is the absolute path to this bat file, without quotes, always. -REM ~ strips quotes from the argument -SET SLIMERDIR=%~dp0 -REM %* is every argument passed to this script. -SET __SLIMER_ARGS=%* -SET LISTVAR= - -SET CREATETEMP=Y - -REM check arguments -FOR %%A IN (%*) DO ( - - if ["%%A"]==["/?"] ( - call :helpMessage - pause - exit 0 - ) - if /I ["%%A"]==["--help"] ( - call :helpMessage - pause - exit 0 - ) - if /I ["%%A"]==["-h"] ( - call :helpMessage - pause - exit 0 - ) - if /I ["%%A"]==["-reset-profile"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["-profile"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["-p"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["-createprofile"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["-profilemanager"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["--reset-profile"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["--profile"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["--p"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["--createprofile"] ( - SET CREATETEMP= - ) - if /I ["%%A"]==["--profilemanager"] ( - SET CREATETEMP= - ) -) - -if not exist "%SLIMERJSLAUNCHER%" ( - if exist "%SLIMERDIR%\xulrunner\xulrunner.exe" ( - SET SLIMERJSLAUNCHER="%SLIMERDIR%\xulrunner\xulrunner.exe" - ) -) -if not exist "%SLIMERJSLAUNCHER%" ( - call :findFirefox -) -if not exist "%SLIMERJSLAUNCHER%" ( - echo SLIMERJSLAUNCHER environment variable is missing or the path is invalid. - echo Set it with the path to Firefox or xulrunner. - echo The current value of SLIMERJSLAUNCHER is: %SLIMERJSLAUNCHER% - REM %% escapes the percent sign so it displays literally - echo SET SLIMERJSLAUNCHER="%%programfiles%%\Mozilla Firefox\firefox.exe" - echo SET SLIMERJSLAUNCHER="%%programfiles%%\XULRunner\xulrunner.exe" - pause - exit 1 -) - - -SETLOCAL EnableDelayedExpansion - -REM store environment variable into LISTVAR for SlimerJS -FOR /F "usebackq delims==" %%i IN (`set`) DO set LISTVAR=!LISTVAR!,%%i - -REM let's create a temporary dir for the profile, if needed -if ["%CREATETEMP%"]==[""] ( - SET PROFILEDIR= - SET PROFILE=-purgecaches - goto callexec -) -:createdirname -SET PROFILEDIR=%Temp%\slimerjs-!Random!!Random!!Random! -IF EXIST "%PROFILEDIR%" ( - GOTO createdirname -) -mkdir %PROFILEDIR% - -SET PROFILE=-profile %PROFILEDIR% - -:callexec -REM Firefox console output is done to NUL or something like that. -REM So we have to redirect output to a file and then output this file -REM FIXME: This solution is not optimal, since we cannot see messages at realtime -REM FIXME: an other solution to redirect directly to the console ? -set TMPFILE=%TMP%\slimer-output-%RANDOM%.tmp - -%SLIMERJSLAUNCHER% -app "%SLIMERDIR%application.ini" %PROFILE% -no-remote -envs "%LISTVAR%" %__SLIMER_ARGS% >%TMPFILE% 2>&1 - -if ["%CREATETEMP%"]==["Y"] ( - rmdir /S /Q %PROFILEDIR% -) -TYPE %TMPFILE% -DEL %TMPFILE% -ENDLOCAL - -goto :eof - - -:helpMessage -REM in echo statements the escape character is ^ -REM escape < > | and & -REM the character % is escaped by doubling it to %% -REM if delayed variable expansion is turned on then the character ! needs to be escaped as ^^! - echo Available options are: - echo. -REM echo --config=^ Load the given configuration file -REM echo (JSON formated) -REM echo --debug=[yes^|no] Prints additional warning and debug message -REM echo (default is no) -REM echo --disk-cache=[yes^|no] Enables disk cache (default is no). - echo --help or -h Show this help -REM echo --ignore-ssl-errors=[yes^|no] Ignores SSL errors (default is no). - echo --load-images=[yes^|no] Loads all inlined images (default is yes) - echo --local-storage-quota=^ Sets the maximum size of the offline - echo local storage (in KB) -REM echo --local-to-remote-url-access=[yes^|no] Allows local content to access remote -REM echo URL (default is no) -REM echo --max-disk-cache-size=^ Limits the size of the disk cache (in KB) -REM echo --output-encoding=^ Sets the encoding for the terminal output -REM echo (default is 'utf8') -REM echo --remote-debugger-port=^ Starts the script in a debug harness and -REM echo listens on the specified port -REM echo --remote-debugger-autorun=[yes^|no] Runs the script in the debugger immediately -REM echo (default is no) -REM echo --proxy=^ Sets the proxy server -REM echo --proxy-auth=^ Provides authentication information for the -REM echo proxy -REM echo --proxy-type=[http^|socks5^|none] Specifies the proxy type (default is http) -REM echo --script-encoding=^ Sets the encoding used for the starting -REM echo script (default is utf8) -REM echo --web-security=[yes^|no] Enables web security (default is yes) -REM echo --ssl-protocol=[SSLv3^|SSLv2^|TLSv1^|any] Sets the SSL protocol - echo --version or v Prints out SlimerJS version -REM echo --webdriver or --wd or -w Starts in 'Remote WebDriver mode' (embedded -REM echo GhostDriver) '127.0.0.1:8910' -REM echo --webdriver=[^:]^ Starts in 'Remote WebDriver mode' in the -REM echo specified network interface -REM echo --webdriver-logfile=^ File where to write the WebDriver's Log -REM echo (default 'none') (NOTE: needs '--webdriver') -REM echo --webdriver-loglevel=[ERROR^|WARN^|INFO^|DEBUG^|] WebDriver Logging Level -REM echo (default is 'INFO') (NOTE: needs '--webdriver') -REM echo --webdriver-selenium-grid-hub=^ URL to the Selenium Grid HUB (default is -REM echo 'none') (NOTE: needs '--webdriver') - echo --error-log-file= Log all javascript errors in a file - echo -jsconsole Open a window to view all javascript errors - echo during the execution - echo. - echo *** About profiles: see details of these Mozilla options at - echo https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile - echo. - echo --createprofile name Create a new profile and exit - echo -P name Use the specified profile to execute the script - echo -profile path Use the profile stored in the specified - echo directory, to execute the script - echo By default, SlimerJS use a temporary profile - echo. -goto :eof - - -:findFirefox -if exist "%programfiles%\Mozilla Firefox\firefox.exe" ( - SET SLIMERJSLAUNCHER="%programfiles%\Mozilla Firefox\firefox.exe" -) -if exist "%programfiles% (x86)\Mozilla Firefox\firefox.exe" ( - SET SLIMERJSLAUNCHER="%programfiles% (x86)\Mozilla Firefox\firefox.exe" -) -echo SLIMERJSLAUNCHER is set to %SLIMERJSLAUNCHER% -goto :eof +@echo off + +SET SLIMERJSLAUNCHER="%SLIMERJSLAUNCHER%" +REM % ~ d[rive] p[ath] 0[script name] is the absolute path to this bat file, without quotes, always. +REM ~ strips quotes from the argument +SET SLIMERDIR=%~dp0 +REM %* is every argument passed to this script. +SET __SLIMER_ARGS=%* +SET __SLIMER_ENV= + +SET CREATETEMP=Y + +REM check arguments +FOR %%A IN (%*) DO ( + + if ["%%A"]==["/?"] ( + call :helpMessage + pause + exit 0 + ) + if /I ["%%A"]==["--help"] ( + call :helpMessage + pause + exit 0 + ) + if /I ["%%A"]==["-h"] ( + call :helpMessage + pause + exit 0 + ) + if /I ["%%A"]==["-reset-profile"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["-profile"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["-p"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["-createprofile"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["-profilemanager"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["--reset-profile"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["--profile"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["--p"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["--createprofile"] ( + SET CREATETEMP= + ) + if /I ["%%A"]==["--profilemanager"] ( + SET CREATETEMP= + ) +) + +if not exist "%SLIMERJSLAUNCHER%" ( + if exist "%SLIMERDIR%\xulrunner\xulrunner.exe" ( + SET SLIMERJSLAUNCHER="%SLIMERDIR%\xulrunner\xulrunner.exe" + ) +) +if not exist "%SLIMERJSLAUNCHER%" ( + call :findFirefox +) +if not exist "%SLIMERJSLAUNCHER%" ( + echo SLIMERJSLAUNCHER environment variable is missing or the path is invalid. + echo Set it with the path to Firefox or xulrunner. + echo The current value of SLIMERJSLAUNCHER is: %SLIMERJSLAUNCHER% + REM %% escapes the percent sign so it displays literally + echo SET SLIMERJSLAUNCHER="%%programfiles%%\Mozilla Firefox\firefox.exe" + echo SET SLIMERJSLAUNCHER="%%programfiles%%\XULRunner\xulrunner.exe" + pause + exit 1 +) + + +SETLOCAL EnableDelayedExpansion + +REM store environment variable into __SLIMER_ENV for SlimerJS +FOR /F "usebackq delims==" %%i IN (`set`) DO set __SLIMER_ENV=!__SLIMER_ENV!,%%i + +REM let's create a temporary dir for the profile, if needed +if ["%CREATETEMP%"]==[""] ( + SET PROFILEDIR= + SET PROFILE=-purgecaches + goto callexec +) +:createdirname +SET PROFILEDIR=%Temp%\slimerjs-!Random!!Random!!Random! +IF EXIST "%PROFILEDIR%" ( + GOTO createdirname +) +mkdir %PROFILEDIR% + +SET PROFILE=-profile %PROFILEDIR% + +:callexec +REM Firefox console output is done to NUL or something like that. +REM So we have to redirect output to a file and then output this file +REM FIXME: This solution is not optimal, since we cannot see messages at realtime +REM FIXME: an other solution to redirect directly to the console ? +set TMPFILE=%TMP%\slimer-output-%RANDOM%.tmp + +%SLIMERJSLAUNCHER% -app "%SLIMERDIR%application.ini" %PROFILE% -no-remote %__SLIMER_ARGS% >%TMPFILE% 2>&1 + +if ["%CREATETEMP%"]==["Y"] ( + rmdir /S /Q %PROFILEDIR% +) +TYPE %TMPFILE% +DEL %TMPFILE% +ENDLOCAL + +goto :eof + + +:helpMessage +REM in echo statements the escape character is ^ +REM escape < > | and & +REM the character % is escaped by doubling it to %% +REM if delayed variable expansion is turned on then the character ! needs to be escaped as ^^! + echo Available options are: + echo. +REM echo --config=^ Load the given configuration file +REM echo (JSON formated) +REM echo --debug=[yes^|no] Prints additional warning and debug message +REM echo (default is no) +REM echo --disk-cache=[yes^|no] Enables disk cache (default is no). + echo --help or -h Show this help +REM echo --ignore-ssl-errors=[yes^|no] Ignores SSL errors (default is no). + echo --load-images=[yes^|no] Loads all inlined images (default is yes) + echo --local-storage-quota=^ Sets the maximum size of the offline + echo local storage (in KB) +REM echo --local-to-remote-url-access=[yes^|no] Allows local content to access remote +REM echo URL (default is no) +REM echo --max-disk-cache-size=^ Limits the size of the disk cache (in KB) +REM echo --output-encoding=^ Sets the encoding for the terminal output +REM echo (default is 'utf8') +REM echo --remote-debugger-port=^ Starts the script in a debug harness and +REM echo listens on the specified port +REM echo --remote-debugger-autorun=[yes^|no] Runs the script in the debugger immediately +REM echo (default is no) +REM echo --proxy=^ Sets the proxy server +REM echo --proxy-auth=^ Provides authentication information for the +REM echo proxy +REM echo --proxy-type=[http^|socks5^|none] Specifies the proxy type (default is http) +REM echo --script-encoding=^ Sets the encoding used for the starting +REM echo script (default is utf8) +REM echo --web-security=[yes^|no] Enables web security (default is yes) +REM echo --ssl-protocol=[SSLv3^|SSLv2^|TLSv1^|any] Sets the SSL protocol + echo --version or v Prints out SlimerJS version +REM echo --webdriver or --wd or -w Starts in 'Remote WebDriver mode' (embedded +REM echo GhostDriver) '127.0.0.1:8910' +REM echo --webdriver=[^:]^ Starts in 'Remote WebDriver mode' in the +REM echo specified network interface +REM echo --webdriver-logfile=^ File where to write the WebDriver's Log +REM echo (default 'none') (NOTE: needs '--webdriver') +REM echo --webdriver-loglevel=[ERROR^|WARN^|INFO^|DEBUG^|] WebDriver Logging Level +REM echo (default is 'INFO') (NOTE: needs '--webdriver') +REM echo --webdriver-selenium-grid-hub=^ URL to the Selenium Grid HUB (default is +REM echo 'none') (NOTE: needs '--webdriver') + echo --error-log-file= Log all javascript errors in a file + echo -jsconsole Open a window to view all javascript errors + echo during the execution + echo. + echo *** About profiles: see details of these Mozilla options at + echo https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#User_Profile + echo. + echo --createprofile name Create a new profile and exit + echo -P name Use the specified profile to execute the script + echo -profile path Use the profile stored in the specified + echo directory, to execute the script + echo By default, SlimerJS use a temporary profile + echo. +goto :eof + + +:findFirefox +if exist "%programfiles%\Mozilla Firefox\firefox.exe" ( + SET SLIMERJSLAUNCHER="%programfiles%\Mozilla Firefox\firefox.exe" +) +if exist "%programfiles% (x86)\Mozilla Firefox\firefox.exe" ( + SET SLIMERJSLAUNCHER="%programfiles% (x86)\Mozilla Firefox\firefox.exe" +) +echo SLIMERJSLAUNCHER is set to %SLIMERJSLAUNCHER% +goto :eof