diff --git a/example/pom.xml b/example/pom.xml index 833ebbe7de..d09c478776 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -105,34 +105,6 @@ - - - spdy-server - - io.netty.example.spdy.server.SpdyServer - - - - spdy-client - - io.netty.example.spdy.client.SpdyClient - - - - - http2-server - - io.netty.example.http2.server.Http2Server - - - - http2-client - - io.netty.example.http2.client.Http2Client - - - - @@ -146,6 +118,7 @@ ${argLine.leak} ${argLine.coverage} -classpath %classpath + ${argLine.example} ${exampleClass} runtime diff --git a/run-example.sh b/run-example.sh index 9bf40f64cb..35fb34da7a 100755 --- a/run-example.sh +++ b/run-example.sh @@ -1,15 +1,44 @@ #!/bin/bash -e -cd "`dirname "$0"`"/example -if [[ $# -ne 1 ]]; then - echo "Usage: $0 " >&2 +declare -A EXAMPLE_MAP=( + ['spdy-server']='io.netty.example.spdy.server.SpdyServer' + ['spdy-client']='io.netty.example.spdy.client.SpdyClient' + ['http2-server']='io.netty.example.http2.server.Http2Server' + ['http2-client']='io.netty.example.http2.client.Http2Client' +) + +EXAMPLE='' +EXAMPLE_CLASS='' +EXAMPLE_ARGS='' +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 + else + EXAMPLE="$ARG" + EXAMPLE_CLASS="${EXAMPLE_MAP["$EXAMPLE"]}" + break + fi +done + +if [[ -z "$EXAMPLE" ]] || [[ -z "$EXAMPLE_CLASS" ]] || [[ $# -ne 0 ]]; then + echo " Usage: $0 [-D[=] ...] " >&2 + echo "Example: $0 -Dport=8443 -Dssl http-server" >&2 echo >&2 echo "Available examples:" >&2 - grep -E '^ [-a-z0-9]*' pom.xml | sed -e 's#\(^.*\|.*$\)##g' | sed -e 's#^# #' >&2 + for E in "${!EXAMPLE_MAP[@]}"; do + echo " $E" + done | sort >&2 exit 1 fi -EXAMPLE_NAME="$1" - -echo "[INFO] Running: $EXAMPLE_NAME" -mvn -X -P "$EXAMPLE_NAME" compile exec:exec +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"