############## # PROPERTIES # ############## MY_PATH=$(dirname $0) SCRIPT_DIR=$(dirname "$(readlink "${BASH_SOURCE[0]}")") START=1 CURL_CONNECTION_REFUSED_CODE=7 ################# # CONFIGURATION # ################# FITNESSE_PORT=8080 FITNESSE_EXECUTABLE_PATH=${SCRIPT_DIR}/fitnesse-standalone.jar FITNESSE_ROOT_CONTENT_FILE=FitnesseRoot/content.txt #################################### # Command Line Argument Processing # #################################### while [ "$1" != "" ]; do case $1 in -p | --port ) shift FITNESSE_PORT=$1 ;; -k | --kill ) shift START=0 ;; esac shift done ############### # Subroutines # ############### function java_check { if ! type java &> /dev/null ; then echo "Java (JRE) not found" echo "Download the latest version of Java?" select yn in "Get Java for Mac" "Not Now"; do case $yn in "Get Java for Mac" ) open "http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"; break;; "Not Now" ) break;; esac done exit 0 fi } function fitnesse_kill { lsof -n -i4TCP:$FITNESSE_PORT | awk ' { print $2 }' | sed -n 2p | xargs kill -9 } function fitnesse_check { if [ ! -f "${FITNESSE_EXECUTABLE_PATH}" ]; then echo "Fitnesse-Standalone.jar missing!" echo "Download the latest fitnesse-standlalone.jar to the current directory from Fitnesse.org" select yn in "Goto http://fitnesse.org" "Not Now"; do case $yn in "Goto http://fitnesse.org" ) open "http://fitnesse.org"; break;; "Not Now" ) break;; esac done popd 2>&1 > /dev/null exit 0 fi } function fitnesse_start { echo "# Fitnesse Info " echo "# Jar=${FITNESSE_EXECUTABLE_PATH}" echo "# Port=${FITNESSE_PORT}" echo "# Root=." java -jar ${FITNESSE_EXECUTABLE_PATH} -e 0 -p ${FITNESSE_PORT} & } function fitnesse_wait { result=$CURL_CONNECTION_REFUSED_CODE while [ $result -eq $CURL_CONNECTION_REFUSED_CODE ] do sleep 0.5 curl -s "http://localhost:${FITNESSE_PORT}" > /dev/null 2>&1 result=$? done echo "" } function fitnesse_open { open "http://localhost:${FITNESSE_PORT}/${ROOT_PAGE}" } function fitnesse_setup { if [ ! -f "${FITNESSE_ROOT_CONTENT_FILE}" ]; then echo "''Auto Generated By !-"OCSlimProject"-! Do Not Modify This Page''" > $FITNESSE_ROOT_CONTENT_FILE echo "!define TEST_SYSTEM {slim}" >> $FITNESSE_ROOT_CONTENT_FILE echo "!define TEST_RUNNER {!-./OCSlimProjectTestRunner.sh-!}" >> $FITNESSE_ROOT_CONTENT_FILE echo "!define SLIM_VERSION {0.0}" >> $FITNESSE_ROOT_CONTENT_FILE echo "!define COMMAND_PATTERN {%m}" >> $FITNESSE_ROOT_CONTENT_FILE cp -r fi } function fitnesse_launch { fitnesse_start fitnesse_wait fitnesse_setup fitnesse_open } function fitnesse_main { pushd $MY_PATH 2>&1 > /dev/null # Check Java Exists java_check # Check Fitnesse Exists fitnesse_check # Enable Job Control set -o monitor # Start Fitnesse in the background, wait for it to respond, then open in a browser. fitnesse_launch # Return Foreground control to Fitnesse fg %1 popd 2>&1 > /dev/null } ######## # Main # ######## function main { case "$START" in 0) echo "Killing Processes on Port $FITNESSE_PORT" fitnesse_kill ;; 1) echo "Launching Fitnesse" fitnesse_main ;; esac } main