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
This commit is contained in:
Trustin Lee 2014-05-21 13:35:28 +09:00
parent e61ad7f80b
commit d4f2488eac
1 changed files with 16 additions and 13 deletions

View File

@ -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"