From d4f2488eacce2680c4d9ebaa66527cfe5ceb4762 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 21 May 2014 13:35:28 +0900 Subject: [PATCH] Bash 3 compatibility Motivation: Mac OS X ships Bash 3, and it does not have an associative array (declare -A). Modifications: Do not use an associative array. Result: Can run examples on Mac OS X using run-example.sh --- run-example.sh | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/run-example.sh b/run-example.sh index b36f911f15..c409aaf098 100755 --- a/run-example.sh +++ b/run-example.sh @@ -1,26 +1,29 @@ #!/bin/bash -e -declare -A EXAMPLE_MAP=( - ['spdy-server']='io.netty.example.spdy.server.SpdyServer' - ['spdy-client']='io.netty.example.spdy.client.SpdyClient' +EXAMPLE_MAP=( + 'spdy-server:io.netty.example.spdy.server.SpdyServer' + 'spdy-client:io.netty.example.spdy.client.SpdyClient' ) EXAMPLE='' EXAMPLE_CLASS='' -EXAMPLE_ARGS='' +EXAMPLE_ARGS='-D_' I=0 while [[ $# -gt 0 ]]; do ARG="$1" shift if [[ "$ARG" =~ (^-.+) ]]; then - if [[ -z "$EXAMPLE_ARGS" ]]; then - EXAMPLE_ARGS="$ARG" - else - EXAMPLE_ARGS="$EXAMPLE_ARGS $ARG" - fi + EXAMPLE_ARGS="$EXAMPLE_ARGS $ARG" else EXAMPLE="$ARG" - EXAMPLE_CLASS="${EXAMPLE_MAP["$EXAMPLE"]}" + for E in "${EXAMPLE_MAP[@]}"; do + KEY="${E%%:*}" + VAL="${E##*:}" + if [[ "$EXAMPLE" == "$KEY" ]]; then + EXAMPLE_CLASS="$VAL" + break + fi + done break fi done @@ -32,8 +35,8 @@ if [[ -z "$EXAMPLE" ]] || [[ -z "$EXAMPLE_CLASS" ]] || [[ $# -ne 0 ]]; then echo >&2 echo "Available examples:" >&2 echo >&2 - for E in "${!EXAMPLE_MAP[@]}"; do - echo " $E" + for E in "${EXAMPLE_MAP[@]}"; do + echo " ${E%%:*}" done | sort >&2 echo >&2 exit 1 @@ -41,5 +44,5 @@ fi cd "`dirname "$0"`"/example echo "[INFO] Running: $EXAMPLE ($EXAMPLE_CLASS $EXAMPLE_ARGS)" -exec mvn -nsu compile exec:exec -DargLine.example="$EXAMPLE_ARGS" -DexampleClass="$EXAMPLE_CLASS" +exec mvn -X -nsu compile exec:exec -DargLine.example="$EXAMPLE_ARGS" -DexampleClass="$EXAMPLE_CLASS"